Move (find_compare)_device functions to guest.py as it will be used there in an upcoming patch. Signed-off-by: Marc Hartmayer <mhartmay@xxxxxxxxxxxxx> Reviewed-by: Boris Fiuczynski <fiuczy@xxxxxxxxxxxxx> --- virtManager/domain.py | 63 +++---------------------------------------- virtinst/__init__.py | 2 +- virtinst/guest.py | 55 +++++++++++++++++++++++++++++++++++++ 3 files changed, 60 insertions(+), 60 deletions(-) diff --git a/virtManager/domain.py b/virtManager/domain.py index ad1c76d4d655..0b17e548e68e 100644 --- a/virtManager/domain.py +++ b/virtManager/domain.py @@ -13,7 +13,7 @@ import libvirt from virtinst import DomainCapabilities from virtinst import DomainSnapshot -from virtinst import Guest +from virtinst import Guest, find_device from virtinst import util from virtinst import DeviceController from virtinst import DeviceDisk @@ -26,61 +26,6 @@ class _SENTINEL(object): pass -def compare_device(origdev, newdev, idx): - devprops = { - "disk": ["target", "bus"], - "interface": ["macaddr", "xmlindex"], - "input": ["bus", "type", "xmlindex"], - "sound": ["model", "xmlindex"], - "video": ["model", "xmlindex"], - "watchdog": ["xmlindex"], - "hostdev": ["type", "managed", "xmlindex", - "product", "vendor", - "function", "domain", "slot"], - "serial": ["type", "target_port"], - "parallel": ["type", "target_port"], - "console": ["type", "target_type", "target_port"], - "graphics": ["type", "xmlindex"], - "controller": ["type", "index"], - "channel": ["type", "target_name"], - "filesystem": ["target", "xmlindex"], - "smartcard": ["mode", "xmlindex"], - "redirdev": ["bus", "type", "xmlindex"], - "tpm": ["type", "xmlindex"], - "rng": ["type", "xmlindex"], - "panic": ["type", "xmlindex"], - "vsock": ["xmlindex"], - } - - if id(origdev) == id(newdev): - return True - - if not isinstance(origdev, type(newdev)): - return False - - for devprop in devprops[origdev.DEVICE_TYPE]: - if devprop == "xmlindex": - origval = origdev.get_xml_idx() - newval = idx - else: - origval = getattr(origdev, devprop) - newval = getattr(newdev, devprop) - - if origval != newval: - return False - - return True - - -def _find_device(guest, origdev): - devlist = getattr(guest.devices, origdev.DEVICE_TYPE) - for idx, dev in enumerate(devlist): - if compare_device(origdev, dev, idx): - return dev - - return None - - def start_job_progress_thread(vm, meter, progtext): current_thread = threading.currentThread() @@ -395,14 +340,14 @@ class vmmDomain(vmmLibvirtObject): if for_hotplug: return origdev - dev = _find_device(xmlobj, origdev) + dev = find_device(xmlobj, origdev) if dev: return dev # If we are removing multiple dev from an active VM, a double # attempt may result in a lookup failure. If device is present # in the active XML, assume all is good. - if _find_device(self.get_xmlobj(), origdev): + if find_device(self.get_xmlobj(), origdev): logging.debug("Device in active config but not inactive config.") return @@ -488,7 +433,7 @@ class vmmDomain(vmmLibvirtObject): return if con: - rmcon = _find_device(xmlobj, con) + rmcon = find_device(xmlobj, con) if rmcon: xmlobj.remove_device(rmcon) xmlobj.remove_device(editdev) diff --git a/virtinst/__init__.py b/virtinst/__init__.py index 5a3c269d0dad..3aff0c846c2e 100644 --- a/virtinst/__init__.py +++ b/virtinst/__init__.py @@ -40,7 +40,7 @@ from virtinst.devices import * # pylint: disable=wildcard-import from virtinst.installer import Installer -from virtinst.guest import Guest +from virtinst.guest import Guest, find_device from virtinst.cloner import Cloner from virtinst.snapshot import DomainSnapshot diff --git a/virtinst/guest.py b/virtinst/guest.py index c0471cd8a882..c0043cbc94c0 100644 --- a/virtinst/guest.py +++ b/virtinst/guest.py @@ -22,6 +22,61 @@ from .xmlbuilder import XMLBuilder, XMLProperty, XMLChildProperty _ignore = Device +def compare_device(origdev, newdev, idx): + devprops = { + "disk": ["target", "bus"], + "interface": ["macaddr", "xmlindex"], + "input": ["bus", "type", "xmlindex"], + "sound": ["model", "xmlindex"], + "video": ["model", "xmlindex"], + "watchdog": ["xmlindex"], + "hostdev": ["type", "managed", "xmlindex", + "product", "vendor", + "function", "domain", "slot"], + "serial": ["type", "target_port"], + "parallel": ["type", "target_port"], + "console": ["type", "target_type", "target_port"], + "graphics": ["type", "xmlindex"], + "controller": ["type", "index"], + "channel": ["type", "target_name"], + "filesystem": ["target", "xmlindex"], + "smartcard": ["mode", "xmlindex"], + "redirdev": ["bus", "type", "xmlindex"], + "tpm": ["type", "xmlindex"], + "rng": ["type", "xmlindex"], + "panic": ["type", "xmlindex"], + "vsock": ["xmlindex"], + } + + if id(origdev) == id(newdev): + return True + + if not isinstance(origdev, type(newdev)): + return False + + for devprop in devprops[origdev.DEVICE_TYPE]: + if devprop == "xmlindex": + origval = origdev.get_xml_idx() + newval = idx + else: + origval = getattr(origdev, devprop) + newval = getattr(newdev, devprop) + + if origval != newval: + return False + + return True + + +def find_device(guest, origdev): + devlist = getattr(guest.devices, origdev.DEVICE_TYPE) + for idx, dev in enumerate(devlist): + if compare_device(origdev, dev, idx): + return dev + + return None + + class _DomainDevices(XMLBuilder): XML_NAME = "devices" _XML_PROP_ORDER = ['disk', 'controller', 'filesystem', 'interface', -- 2.17.0 _______________________________________________ virt-tools-list mailing list virt-tools-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/virt-tools-list