File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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 ])
Original file line number Diff line number Diff 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 ]))
Original file line number Diff line number Diff line change @@ -1602,13 +1602,13 @@ def raise_bad_load(e):
16021602
16031603 self ._exists = False
16041604 vdi_sm_config = self .sr .srcmd .params .get ('vdi_sm_config' )
1605- if vdi_sm_config is not None :
1606- type = vdi_sm_config .get ('type' )
1607-
1608- try :
1609- self ._set_type (CREATE_PARAM_TYPES [type ])
1610- except :
1611- raise xs_errors .XenError ('VDICreate' , opterr = 'bad type ' )
1605+ if vdi_sm_config :
1606+ image_format = vdi_sm_config . get ( 'image-format' ) or vdi_sm_config .get ('type' )
1607+ if image_format :
1608+ try :
1609+ self ._set_type (CREATE_PARAM_TYPES [image_format ])
1610+ except :
1611+ raise xs_errors .XenError ('VDICreate' , opterr = 'bad image format ' )
16121612
16131613 if not self .vdi_type :
16141614 self ._set_type (getVdiTypeFromImageFormat (self .sr .preferred_image_formats [0 ]))
You can’t perform that action at this time.
0 commit comments