Skip to content

Commit b81a658

Browse files
committed
Support image-format param during VDI creation
Signed-off-by: Ronan Abhamon <ronan.abhamon@vates.tech>
1 parent 2fa5206 commit b81a658

3 files changed

Lines changed: 26 additions & 23 deletions

File tree

drivers/FileSR.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -489,16 +489,18 @@ def load(self, vdi_uuid) -> None:
489489

490490
if self.sr.srcmd.cmd == "vdi_create":
491491
self.key_hash = None
492-
if "vdi_sm_config" in self.sr.srcmd.params:
493-
if "key_hash" in self.sr.srcmd.params["vdi_sm_config"]:
494-
self.key_hash = self.sr.srcmd.params["vdi_sm_config"]["key_hash"]
495492

496-
if "type" in self.sr.srcmd.params["vdi_sm_config"]:
497-
vdi_type = self.sr.srcmd.params["vdi_sm_config"]["type"]
498-
if not self.VDI_TYPE.get(vdi_type):
493+
vdi_sm_config = self.sr.srcmd.params.get("vdi_sm_config")
494+
if vdi_sm_config:
495+
self.key_hash = vdi_sm_config.get("key_hash")
496+
497+
image_format = vdi_sm_config.get("image-format") or vdi_sm_config.get("type")
498+
if image_format:
499+
vdi_type = self.VDI_TYPE.get(image_format)
500+
if not vdi_type:
499501
raise xs_errors.XenError('VDIType',
500502
opterr='Invalid VDI type %s' % vdi_type)
501-
self.vdi_type = self.VDI_TYPE[vdi_type]
503+
self.vdi_type = vdi_type
502504

503505
if not self.vdi_type:
504506
self.vdi_type = getVdiTypeFromImageFormat(self.sr.preferred_image_formats[0])

drivers/LVMSR.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1370,16 +1370,17 @@ def load(self, vdi_uuid) -> None:
13701370

13711371
# the VDI must be in the process of being created
13721372
self.exists = False
1373-
if "vdi_sm_config" in self.sr.srcmd.params and \
1374-
"type" in self.sr.srcmd.params["vdi_sm_config"]:
1375-
type = self.sr.srcmd.params["vdi_sm_config"]["type"]
13761373

1377-
try:
1378-
self._setType(CREATE_PARAM_TYPES[type])
1379-
except:
1380-
raise xs_errors.XenError('VDICreate', opterr='bad type')
1381-
if self.sr.legacyMode and self.sr.cmd == 'vdi_create' and VdiType.isCowImage(self.vdi_type):
1382-
raise xs_errors.XenError('VDICreate', opterr='Cannot create COW type disk in legacy mode')
1374+
vdi_sm_config = self.sr.srcmd.params.get("vdi_sm_config")
1375+
if vdi_sm_config:
1376+
image_format = vdi_sm_config.get("image-format") or vdi_sm_config.get("type")
1377+
if image_format:
1378+
try:
1379+
self._setType(CREATE_PARAM_TYPES[image_format])
1380+
except:
1381+
raise xs_errors.XenError('VDICreate', opterr='bad image format')
1382+
if self.sr.legacyMode and self.sr.cmd == 'vdi_create' and VdiType.isCowImage(self.vdi_type):
1383+
raise xs_errors.XenError('VDICreate', opterr='Cannot create COW type disk in legacy mode')
13831384

13841385
if not self.vdi_type:
13851386
self._setType(getVdiTypeFromImageFormat(self.sr.preferred_image_formats[0]))

drivers/LinstorSR.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1609,13 +1609,13 @@ def raise_bad_load(e):
16091609

16101610
self._exists = False
16111611
vdi_sm_config = self.sr.srcmd.params.get('vdi_sm_config')
1612-
if vdi_sm_config is not None:
1613-
type = vdi_sm_config.get('type')
1614-
1615-
try:
1616-
self._set_type(CREATE_PARAM_TYPES[type])
1617-
except:
1618-
raise xs_errors.XenError('VDICreate', opterr='bad type')
1612+
if vdi_sm_config:
1613+
image_format = vdi_sm_config.get('image-format') or vdi_sm_config.get('type')
1614+
if image_format:
1615+
try:
1616+
self._set_type(CREATE_PARAM_TYPES[image_format])
1617+
except:
1618+
raise xs_errors.XenError('VDICreate', opterr='bad image format')
16191619

16201620
if not self.vdi_type:
16211621
self._set_type(getVdiTypeFromImageFormat(self.sr.preferred_image_formats[0]))

0 commit comments

Comments
 (0)