mirror of
https://github.com/virt-manager/virt-manager.git
synced 2025-02-10 23:45:49 -06:00
virtinst: Move fetch_all_guests to connection object
And fetch_all_pools. And have it use pollhelpers
This commit is contained in:
parent
ee7d0b620d
commit
d5dc06148d
@ -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
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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 #
|
||||
|
@ -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
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user