Skip to content

Commit c37c64a

Browse files
committed
feat(image_format): support image_format
vdi.py: add getting the image_format if available sr.py: add choosing a image_format on vdi creation sr.py add get_type to get the type of the SR Signed-off-by: Damien Thenot <[email protected]>
1 parent 3501307 commit c37c64a

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

lib/sr.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import logging
22
import time
3+
from typing import Optional
34

45
import lib.commands as commands
56

@@ -12,6 +13,7 @@ def __init__(self, uuid, pool):
1213
self.pool = pool
1314
self._is_shared = None # cached value for is_shared()
1415
self._main_host = None # cached value for main_host()
16+
self._type = None # cache value for get_type()
1517

1618
def pbd_uuids(self):
1719
return safe_split(self.pool.master.xe('pbd-list', {'sr-uuid': self.uuid}, minimal=True))
@@ -153,13 +155,21 @@ def is_shared(self):
153155
{'uuid': self.uuid, 'param-name': 'shared'}))
154156
return self._is_shared
155157

156-
def create_vdi(self, name_label, virtual_size=64):
158+
def get_type(self) -> str:
159+
if self._type is None:
160+
self._type = self.pool.master.xe("sr-param-get", {"uuid": self.uuid, "param-name": "type"})
161+
return self._type
162+
163+
def create_vdi(self, name_label: str, virtual_size: int = 64, image_format: Optional[str] = None) -> VDI:
157164
logging.info("Create VDI %r on SR %s", name_label, self.uuid)
158-
vdi_uuid = self.pool.master.xe('vdi-create', {
165+
args = {
159166
'name-label': prefix_object_name(name_label),
160167
'virtual-size': str(virtual_size),
161-
'sr-uuid': self.uuid
162-
})
168+
'sr-uuid': self.uuid,
169+
}
170+
if image_format:
171+
args["sm-config:image-format"] = image_format
172+
vdi_uuid = self.pool.master.xe('vdi-create', args)
163173
return VDI(vdi_uuid, sr=self)
164174

165175
def run_quicktest(self):

lib/vdi.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ def __str__(self):
4848
def get_parent(self) -> Optional[str]:
4949
return self.param_get("sm-config", key="vhd-parent", accept_unknown_key=True)
5050

51+
def get_image_format(self) -> Optional[str]:
52+
return self.param_get("sm-config", key="image-format", accept_unknown_key=True)
53+
5154
@overload
5255
def param_get(self, param_name: str, key: Optional[str] = ...,
5356
accept_unknown_key: Literal[False] = ...) -> str:

0 commit comments

Comments
 (0)