Skip to content

Commit 0d957e7

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 feec8ba commit 0d957e7

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-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
from lib.common import prefix_object_name, safe_split, strtobool, wait_for, wait_for_not
@@ -11,6 +12,7 @@ def __init__(self, uuid, pool):
1112
self.pool = pool
1213
self._is_shared = None # cached value for is_shared()
1314
self._main_host = None # cached value for main_host()
15+
self._type = None # cache value for get_type()
1416

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

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

164174
def run_quicktest(self):

lib/vdi.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ def readonly(self) -> bool:
5050
def __str__(self):
5151
return f"VDI {self.uuid} on SR {self.sr.uuid}"
5252

53+
def get_parent(self) -> Optional[str]:
54+
return self.param_get("sm-config", key="vhd-parent", accept_unknown_key=True)
55+
56+
def get_image_format(self) -> Optional[str]:
57+
return self.param_get("sm-config", key="image-format", accept_unknown_key=True)
58+
5359
@overload
5460
def param_get(self, param_name: str, key: Optional[str] = ...,
5561
accept_unknown_key: Literal[False] = ...) -> str:

0 commit comments

Comments
 (0)