diff --git a/virtinst/VirtualDisk.py b/virtinst/VirtualDisk.py index 603e65e1e..32cb79eaf 100644 --- a/virtinst/VirtualDisk.py +++ b/virtinst/VirtualDisk.py @@ -466,8 +466,7 @@ class VirtualDisk(VirtualDevice): if not path: return - active, inactive = util.fetch_all_guests(conn) - vms = active + inactive + vms = conn.fetch_all_guests() def count_cb(ctx): c = 0 diff --git a/virtinst/VirtualNetworkInterface.py b/virtinst/VirtualNetworkInterface.py index f3488d9dc..74b4a6563 100644 --- a/virtinst/VirtualNetworkInterface.py +++ b/virtinst/VirtualNetworkInterface.py @@ -336,10 +336,9 @@ class VirtualNetworkInterface(VirtualDevice): if mac is None: return (False, None) - vms, inactive_vm = util.fetch_all_guests(conn) + vms = self.conn.fetch_all_guests() - if (_countMACaddr(vms, mac) > 0 or - _countMACaddr(inactive_vm, mac) > 0): + if _countMACaddr(vms, mac) > 0: return (True, _("The MAC address '%s' is in use " "by another virtual machine.") % mac) diff --git a/virtinst/connection.py b/virtinst/connection.py index 9f851589a..449b1945a 100644 --- a/virtinst/connection.py +++ b/virtinst/connection.py @@ -22,6 +22,7 @@ import re import libvirt +from virtinst import pollhelpers from virtinst import support from virtinst import util from virtinst import CapabilitiesParser @@ -118,6 +119,16 @@ class VirtualConnection(object): self._fixup_virtinst_test_uri(conn) self._libvirtconn = conn + def fetch_all_guests(self): + ignore, ignore, ret = pollhelpers.fetch_vms(self, {}, + lambda obj, ignore: obj) + return ret.values() + + def fetch_all_pools(self): + ignore, ignore, ret = pollhelpers.fetch_pools(self, {}, + lambda obj, ignore: obj) + return ret.values() + ######################### # Public version checks # diff --git a/virtinst/util.py b/virtinst/util.py index 8c65e7f7b..c443ecd01 100644 --- a/virtinst/util.py +++ b/virtinst/util.py @@ -167,36 +167,6 @@ def xml_append(orig, new): return orig + new -def fetch_all_guests(conn): - """ - Return 2 lists: ([all_running_vms], [all_nonrunning_vms]) - """ - active = [] - inactive = [] - - # Get all active VMs - ids = conn.listDomainsID() - for i in ids: - try: - vm = conn.lookupByID(i) - active.append(vm) - except libvirt.libvirtError: - # guest probably in process of dieing - logging.warn("Failed to lookup active domain id %d", i) - - # Get all inactive VMs - names = conn.listDefinedDomains() - for name in names: - try: - vm = conn.lookupByName(name) - inactive.append(vm) - except: - # guest probably in process of dieing - logging.warn("Failed to lookup inactive domain %d", name) - - return (active, inactive) - - def set_xml_path(xml, path, newval): """ Set the passed xml xpath to the new value @@ -494,19 +464,15 @@ def lookup_pool_by_path(conn, path): if not conn.check_conn_support(conn.SUPPORT_CONN_STORAGE): return None - def check_pool(poolname, path): - pool = conn.storagePoolLookupByName(poolname) + def check_pool(pool, path): xml_path = get_xml_path(pool.XMLDesc(0), "/pool/target/path") if xml_path is not None and os.path.abspath(xml_path) == path: return pool - running_list = conn.listStoragePools() - inactive_list = conn.listDefinedStoragePools() - for plist in [running_list, inactive_list]: - for name in plist: - p = check_pool(name, path) - if p: - return p + for pool in conn.fetch_all_pools(): + p = check_pool(pool, path) + if p: + return p return None