@@ -448,25 +448,24 @@ def _change_disk_type(self, org_type, cln_type, idxs, ctx):
448448 for dev_idx in idxs :
449449 disk_type = ctx .xpathEval ("/domain/devices/disk[%d]/@type" %
450450 dev_idx )
451- driv_name = ctx .xpathEval ("/domain/devices/disk[%d]/driver/@name" %
452- dev_idx )
451+ driv_name = ctx .xpathEval ("/domain/devices/disk[%d]/driver/@name" % dev_idx )
453452 src = ctx .xpathEval ("/domain/devices/disk[%d]/source" % dev_idx )
454453 src_chid_txt = src [0 ].get_properties ().getContent ()
455454
456455 # different type
457456 if org_type [type_idx ] != cln_type [type_idx ]:
458- # changing from file to disk
459457 if org_type [type_idx ] == True :
460- disk_type [0 ].setContent ("block" )
461- driv_name [0 ].setContent ("phy" )
462- src [0 ].get_properties ().unlinkNode ()
463- src [0 ].newProp ("dev" , src_chid_txt )
464- # changing from disk to file
458+ # changing from file to disk
459+ typ , driv , newprop = ("block" , "phy" , "dev" )
465460 else :
466- disk_type [0 ].setContent ("file" )
467- driv_name [0 ].setContent ("file" )
468- src [0 ].get_properties ().unlinkNode ()
469- src [0 ].newProp ("file" , src_chid_txt )
461+ # changing from disk to file
462+ typ , driv , newprop = ("file" , "file" , "file" )
463+
464+ disk_type [0 ].setContent (typ )
465+ if driv_name :
466+ driv_name [0 ].setContent (driv )
467+ src [0 ].get_properties ().unlinkNode ()
468+ src [0 ].newProp (newprop , src_chid_txt )
470469
471470 type_idx += 1
472471
0 commit comments