summaryrefslogtreecommitdiff
path: root/virtinst
diff options
context:
space:
mode:
authorCole Robinson <crobinso@redhat.com>2013-07-07 14:54:48 -0400
committerCole Robinson <crobinso@redhat.com>2013-07-07 15:14:59 -0400
commitd5dc06148d3dfb2e09304473b3e742b432719f9f (patch)
tree8353d6600aa477966ac94f99afba9b046975a89b /virtinst
parentee7d0b620d93a41a701da4a235d736a14f1d8297 (diff)
downloadvirt-manager-d5dc06148d3dfb2e09304473b3e742b432719f9f.tar.gz
virtinst: Move fetch_all_guests to connection object
And fetch_all_pools. And have it use pollhelpers
Diffstat (limited to 'virtinst')
-rw-r--r--virtinst/VirtualDisk.py3
-rw-r--r--virtinst/VirtualNetworkInterface.py5
-rw-r--r--virtinst/connection.py11
-rw-r--r--virtinst/util.py44
4 files changed, 19 insertions, 44 deletions
diff --git a/virtinst/VirtualDisk.py b/virtinst/VirtualDisk.py
index 603e65e1..32cb79ea 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 f3488d9d..74b4a656 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 9f851589..449b1945 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 8c65e7f7..c443ecd0 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