@@ -636,31 +636,43 @@ def _get_input_device(self):
636636 raise NotImplementedError
637637
638638 def _get_device_xml (self , install = True ):
639- change_disks = []
640- for d in self ._get_install_devs (VirtualDevice .VIRTUAL_DEV_DISK ):
641- if (d .device == VirtualDisk .DEVICE_CDROM
642- and d .transient
643- and not install ):
644- # Keep cdrom around, but with no media attached,
645- # But only if we are a distro that doesn't have a multi
646- # stage install (aka not Windows)
647- if not self .get_continue_inst ():
648- change_disks .append ((d , d .path ))
649- d .path = None
639+ # If install hasn't been prepared yet, make sure we use
640+ # the regular device list
641+ inst_devs = self ._get_all_install_devs ()
642+ reg_devs = self .get_all_devices ()
643+ if len (inst_devs ) >= len (reg_devs ):
644+ devs = inst_devs [:]
645+ else :
646+ devs = reg_devs [:]
647+
648+ def do_remove_media (d ):
649+ # Keep cdrom around, but with no media attached,
650+ # But only if we are a distro that doesn't have a multi
651+ # stage install (aka not Windows)
652+ return (d .virtual_device_type == VirtualDevice .VIRTUAL_DEV_DISK and
653+ d .device == VirtualDisk .DEVICE_CDROM
654+ and d .transient
655+ and not install and
656+ not self .get_continue_inst ())
657+
658+ # Wrapper for building disk XML, handling transient CDROMs
659+ def get_dev_xml (dev ):
660+ origpath = None
661+ try :
662+ if do_remove_media (dev ):
663+ origpath = dev .path
664+ dev .path = None
665+
666+ return dev .get_xml_config ()
667+ finally :
668+ if origpath :
669+ dev .path = origpath
650670
651671 xml = ""
652672 try :
653- # If install hasn't been prepared yet, make sure we use
654- # the regular device list
655- inst_devs = self ._get_all_install_devs ()
656- reg_devs = self .get_all_devices ()
657- if len (inst_devs ) >= len (reg_devs ):
658- devs = inst_devs
659- else :
660- devs = reg_devs
661-
673+ # Build XML
662674 for dev in devs :
663- xml = _util .xml_append (xml , dev . get_xml_config ( ))
675+ xml = _util .xml_append (xml , get_dev_xml ( dev ))
664676 finally :
665677 try :
666678 for disk , path in change_disks :
0 commit comments