mirror of
https://github.com/virt-manager/virt-manager.git
synced 2026-08-13 06:24:59 -05:00
VirtualConnection: proxy virtinst.support API
Simplifies the lives of callers, and will allow us to do caching later
This commit is contained in:
+32
-25
@@ -96,7 +96,7 @@ def poolCompare(pool_inst):
|
||||
return pool_inst.install(build=True, meter=None, create=True)
|
||||
|
||||
|
||||
def createVol(poolobj, volname=None, input_vol=None, clone_vol=None):
|
||||
def createVol(conn, poolobj, volname=None, input_vol=None, clone_vol=None):
|
||||
volclass = StorageVolume.get_volume_for_pool(pool_object=poolobj)
|
||||
|
||||
if volname is None:
|
||||
@@ -104,7 +104,8 @@ def createVol(poolobj, volname=None, input_vol=None, clone_vol=None):
|
||||
|
||||
alloc = 5 * 1024 * 1024 * 1024
|
||||
cap = 10 * 1024 * 1024 * 1024
|
||||
vol_inst = volclass(name=volname, capacity=cap, allocation=alloc,
|
||||
vol_inst = volclass(conn,
|
||||
name=volname, capacity=cap, allocation=alloc,
|
||||
pool=poolobj)
|
||||
|
||||
perms = {}
|
||||
@@ -113,14 +114,10 @@ def createVol(poolobj, volname=None, input_vol=None, clone_vol=None):
|
||||
perms["group"] = 10736
|
||||
|
||||
vol_inst.perms = perms
|
||||
if input_vol or clone_vol:
|
||||
if not virtinst.Storage.is_create_vol_from_supported(poolobj._conn):
|
||||
return
|
||||
|
||||
if input_vol:
|
||||
vol_inst.input_vol = input_vol
|
||||
elif clone_vol:
|
||||
vol_inst = virtinst.Storage.CloneVolume(volname, clone_vol)
|
||||
vol_inst = virtinst.Storage.CloneVolume(conn, volname, clone_vol)
|
||||
|
||||
filename = os.path.join(basepath, vol_inst.name + ".xml")
|
||||
|
||||
@@ -137,28 +134,36 @@ class TestStorage(unittest.TestCase):
|
||||
|
||||
def testDirPool(self):
|
||||
poolobj = createPool(self.conn, StoragePool.TYPE_DIR, "pool-dir")
|
||||
invol = createVol(poolobj)
|
||||
createVol(poolobj, volname=invol.name() + "input", input_vol=invol)
|
||||
createVol(poolobj, volname=invol.name() + "clone", clone_vol=invol)
|
||||
invol = createVol(self.conn, poolobj)
|
||||
createVol(self.conn, poolobj,
|
||||
volname=invol.name() + "input", input_vol=invol)
|
||||
createVol(self.conn, poolobj,
|
||||
volname=invol.name() + "clone", clone_vol=invol)
|
||||
|
||||
def testFSPool(self):
|
||||
poolobj = createPool(self.conn, StoragePool.TYPE_FS, "pool-fs")
|
||||
invol = createVol(poolobj)
|
||||
createVol(poolobj, volname=invol.name() + "input", input_vol=invol)
|
||||
createVol(poolobj, volname=invol.name() + "clone", clone_vol=invol)
|
||||
invol = createVol(self.conn, poolobj)
|
||||
createVol(self.conn, poolobj,
|
||||
volname=invol.name() + "input", input_vol=invol)
|
||||
createVol(self.conn, poolobj,
|
||||
volname=invol.name() + "clone", clone_vol=invol)
|
||||
|
||||
def testNetFSPool(self):
|
||||
poolobj = createPool(self.conn, StoragePool.TYPE_NETFS, "pool-netfs")
|
||||
invol = createVol(poolobj)
|
||||
createVol(poolobj, volname=invol.name() + "input", input_vol=invol)
|
||||
createVol(poolobj, volname=invol.name() + "clone", clone_vol=invol)
|
||||
invol = createVol(self.conn, poolobj)
|
||||
createVol(self.conn, poolobj,
|
||||
volname=invol.name() + "input", input_vol=invol)
|
||||
createVol(self.conn, poolobj,
|
||||
volname=invol.name() + "clone", clone_vol=invol)
|
||||
|
||||
def testLVPool(self):
|
||||
poolobj = createPool(self.conn, StoragePool.TYPE_LOGICAL,
|
||||
"pool-logical")
|
||||
invol = createVol(poolobj)
|
||||
createVol(poolobj, volname=invol.name() + "input", input_vol=invol)
|
||||
createVol(poolobj, volname=invol.name() + "clone", clone_vol=invol)
|
||||
invol = createVol(self.conn, poolobj)
|
||||
createVol(self.conn, poolobj,
|
||||
volname=invol.name() + "input", input_vol=invol)
|
||||
createVol(self.conn,
|
||||
poolobj, volname=invol.name() + "clone", clone_vol=invol)
|
||||
|
||||
# Test parsing source name for target path
|
||||
createPool(self.conn, StoragePool.TYPE_LOGICAL,
|
||||
@@ -177,15 +182,17 @@ class TestStorage(unittest.TestCase):
|
||||
def testDiskPool(self):
|
||||
poolobj = createPool(self.conn, StoragePool.TYPE_DISK,
|
||||
"pool-disk", fmt="dos")
|
||||
invol = createVol(poolobj)
|
||||
createVol(poolobj, volname=invol.name() + "input", input_vol=invol)
|
||||
createVol(poolobj, volname=invol.name() + "clone", clone_vol=invol)
|
||||
invol = createVol(self.conn, poolobj)
|
||||
createVol(self.conn, poolobj,
|
||||
volname=invol.name() + "input", input_vol=invol)
|
||||
createVol(self.conn, poolobj,
|
||||
volname=invol.name() + "clone", clone_vol=invol)
|
||||
|
||||
def testISCSIPool(self):
|
||||
poolobj = createPool(self.conn, StoragePool.TYPE_ISCSI, "pool-iscsi")
|
||||
# Not supported
|
||||
#volobj = createVol(poolobj)
|
||||
self.assertRaises(RuntimeError, createVol, poolobj)
|
||||
self.assertRaises(RuntimeError, createVol, self.conn, poolobj)
|
||||
|
||||
createPool(self.conn, StoragePool.TYPE_ISCSI, "pool-iscsi-iqn",
|
||||
iqn="foo.bar.baz.iqn")
|
||||
@@ -194,13 +201,13 @@ class TestStorage(unittest.TestCase):
|
||||
poolobj = createPool(self.conn, StoragePool.TYPE_SCSI, "pool-scsi")
|
||||
# Not supported
|
||||
#volobj = createVol(poolobj)
|
||||
self.assertRaises(RuntimeError, createVol, poolobj)
|
||||
self.assertRaises(RuntimeError, createVol, self.conn, poolobj)
|
||||
|
||||
def testMpathPool(self):
|
||||
poolobj = createPool(self.conn, StoragePool.TYPE_MPATH, "pool-mpath")
|
||||
# Not supported
|
||||
#volobj = createVol(poolobj)
|
||||
self.assertRaises(RuntimeError, createVol, poolobj)
|
||||
self.assertRaises(RuntimeError, createVol, self.conn, poolobj)
|
||||
|
||||
def _enumerateCompare(self, pool_list):
|
||||
for pool in pool_list:
|
||||
|
||||
@@ -407,17 +407,15 @@ class vmmAddHardware(vmmGObjectUI):
|
||||
_("Connection does not support host device enumeration"),
|
||||
"pci")
|
||||
add_hw_option("Video", "video-display", PAGE_VIDEO,
|
||||
virtinst.support.check_conn_support(
|
||||
self.conn.get_backend(),
|
||||
virtinst.support.SUPPORT_CONN_DOMAIN_VIDEO),
|
||||
self.conn.check_conn_support(
|
||||
self.conn.SUPPORT_CONN_DOMAIN_VIDEO),
|
||||
_("Libvirt version does not support video devices."))
|
||||
add_hw_option("Watchdog", "device_pci", PAGE_WATCHDOG,
|
||||
self.vm.is_hvm(),
|
||||
_("Not supported for this guest type."))
|
||||
add_hw_option("Filesystem", Gtk.STOCK_DIRECTORY, PAGE_FILESYSTEM,
|
||||
virtinst.support.check_conn_hv_support(
|
||||
self.conn.get_backend(),
|
||||
virtinst.support.SUPPORT_CONN_HV_FILESYSTEM,
|
||||
self.conn.check_conn_hv_support(
|
||||
self.conn.SUPPORT_CONN_HV_FILESYSTEM,
|
||||
self.vm.get_hv_type()),
|
||||
_("Not supported for this hypervisor/libvirt "
|
||||
"combination."))
|
||||
|
||||
@@ -72,8 +72,8 @@ def can_we_clone(conn, vol, path):
|
||||
|
||||
elif vol:
|
||||
# Managed storage
|
||||
if not virtinst.Storage.is_create_vol_from_supported(
|
||||
conn.get_backend()):
|
||||
if not conn.check_pool_support(conn,
|
||||
conn.SUPPORT_STORAGE_CREATEVOLFROM):
|
||||
if conn.is_remote() or not os.access(path, os.R_OK):
|
||||
msg = _("Connection does not support managed storage cloning.")
|
||||
else:
|
||||
|
||||
+40
-20
@@ -257,8 +257,7 @@ class vmmConnection(vmmGObject):
|
||||
##########################
|
||||
|
||||
def get_qualified_hostname(self):
|
||||
if virtinst.support.check_conn_support(self._backend,
|
||||
virtinst.support.SUPPORT_CONN_GETHOSTNAME):
|
||||
if self.check_conn_support(self._backend.SUPPORT_CONN_GETHOSTNAME):
|
||||
return self._backend.getHostname()
|
||||
|
||||
uri_hostname = self.get_uri_hostname()
|
||||
@@ -414,9 +413,30 @@ class vmmConnection(vmmGObject):
|
||||
# API support helpers #
|
||||
#######################
|
||||
|
||||
for _supportname in [_supportname for _supportname in
|
||||
dir(virtinst.VirtualConnection) if
|
||||
_supportname.startswith("SUPPORT_")]:
|
||||
locals()[_supportname] = getattr(virtinst.VirtualConnection,
|
||||
_supportname)
|
||||
def check_conn_support(self, *args):
|
||||
return self._backend.check_conn_support(*args)
|
||||
def check_conn_hv_support(self, *args):
|
||||
return self._backend.check_conn_hv_support(*args)
|
||||
def check_domain_support(self, *args):
|
||||
return self._backend.check_domain_support(*args)
|
||||
def check_pool_support(self, *args):
|
||||
return self._backend.check_pool_support(*args)
|
||||
def check_nodedev_support(self, *args):
|
||||
return self._backend.check_nodedev_support(*args)
|
||||
def check_interface_support(self, *args):
|
||||
return self._backend.check_interface_support(*args)
|
||||
def check_stream_support(self, *args):
|
||||
return self._backend.check_stream_support(*args)
|
||||
|
||||
def is_storage_capable(self):
|
||||
if self._storage_capable is None:
|
||||
self._storage_capable = virtinst.util.is_storage_capable(self._backend)
|
||||
self._storage_capable = self.check_conn_support(
|
||||
self._backend.SUPPORT_CONN_STORAGE)
|
||||
if self._storage_capable is False:
|
||||
logging.debug("Connection doesn't seem to support storage "
|
||||
"APIs. Skipping all storage polling.")
|
||||
@@ -431,9 +451,8 @@ class vmmConnection(vmmGObject):
|
||||
|
||||
def is_network_capable(self):
|
||||
if self.network_capable is None:
|
||||
self.network_capable = virtinst.support.check_conn_support(
|
||||
self._backend,
|
||||
virtinst.support.SUPPORT_CONN_NETWORK)
|
||||
self.network_capable = self.check_conn_support(
|
||||
self._backend.SUPPORT_CONN_NETWORK)
|
||||
if self.network_capable is False:
|
||||
logging.debug("Connection doesn't seem to support network "
|
||||
"APIs. Skipping all network polling.")
|
||||
@@ -442,9 +461,8 @@ class vmmConnection(vmmGObject):
|
||||
|
||||
def is_interface_capable(self):
|
||||
if self.interface_capable is None:
|
||||
self.interface_capable = virtinst.support.check_conn_support(
|
||||
self._backend,
|
||||
virtinst.support.SUPPORT_CONN_INTERFACE)
|
||||
self.interface_capable = self.check_conn_support(
|
||||
self._backend.SUPPORT_CONN_INTERFACE)
|
||||
if self.interface_capable is False:
|
||||
logging.debug("Connection doesn't seem to support interface "
|
||||
"APIs. Skipping all interface polling.")
|
||||
@@ -453,7 +471,8 @@ class vmmConnection(vmmGObject):
|
||||
|
||||
def is_nodedev_capable(self):
|
||||
if self._nodedev_capable is None:
|
||||
self._nodedev_capable = virtinst.NodeDeviceParser.is_nodedev_capable(self._backend)
|
||||
self._nodedev_capable = self.check_conn_support(
|
||||
self._backend.SUPPORT_CONN_NODEDEV)
|
||||
return self._nodedev_capable
|
||||
|
||||
def _get_flags_helper(self, obj, key, check_func):
|
||||
@@ -481,21 +500,21 @@ class vmmConnection(vmmGObject):
|
||||
act = 0
|
||||
inact = 0
|
||||
|
||||
if virtinst.support.check_domain_support(vm,
|
||||
virtinst.support.SUPPORT_DOMAIN_XML_INACTIVE):
|
||||
if self.check_domain_support(vm,
|
||||
self._backend.SUPPORT_DOMAIN_XML_INACTIVE):
|
||||
inact = libvirt.VIR_DOMAIN_XML_INACTIVE
|
||||
else:
|
||||
logging.debug("Domain XML inactive flag not supported.")
|
||||
|
||||
if virtinst.support.check_domain_support(vm,
|
||||
virtinst.support.SUPPORT_DOMAIN_XML_SECURE):
|
||||
if self.check_domain_support(vm,
|
||||
self._backend.SUPPORT_DOMAIN_XML_SECURE):
|
||||
inact |= libvirt.VIR_DOMAIN_XML_SECURE
|
||||
act = libvirt.VIR_DOMAIN_XML_SECURE
|
||||
else:
|
||||
logging.debug("Domain XML secure flag not supported.")
|
||||
|
||||
if virtinst.support.check_domain_support(vm,
|
||||
virtinst.support.SUPPORT_DOMAIN_CPU_HOST_MODEL):
|
||||
if self.check_domain_support(vm,
|
||||
self._backend.SUPPORT_DOMAIN_CPU_HOST_MODEL):
|
||||
inact |= libvirt.VIR_DOMAIN_XML_UPDATE_CPU
|
||||
act |= libvirt.VIR_DOMAIN_XML_UPDATE_CPU
|
||||
else:
|
||||
@@ -506,9 +525,9 @@ class vmmConnection(vmmGObject):
|
||||
return self._get_flags_helper(vm, key, check_func)
|
||||
|
||||
def get_dom_managedsave_supported(self, vm):
|
||||
key = virtinst.support.SUPPORT_DOMAIN_MANAGED_SAVE
|
||||
key = self._backend.SUPPORT_DOMAIN_MANAGED_SAVE
|
||||
if key not in self._support_dict:
|
||||
val = virtinst.support.check_domain_support(vm, key)
|
||||
val = self.check_domain_support(vm, key)
|
||||
logging.debug("Connection managed save support: %s", val)
|
||||
self._support_dict[key] = val
|
||||
|
||||
@@ -521,8 +540,8 @@ class vmmConnection(vmmGObject):
|
||||
act = 0
|
||||
inact = 0
|
||||
|
||||
if virtinst.support.check_interface_support(iface,
|
||||
virtinst.support.SUPPORT_INTERFACE_XML_INACTIVE):
|
||||
if self.check_interface_support(iface,
|
||||
self._backend.SUPPORT_INTERFACE_XML_INACTIVE):
|
||||
inact = libvirt.VIR_INTERFACE_XML_INACTIVE
|
||||
else:
|
||||
logging.debug("Interface XML inactive flag not supported.")
|
||||
@@ -531,6 +550,7 @@ class vmmConnection(vmmGObject):
|
||||
|
||||
return self._get_flags_helper(iface, key, check_func)
|
||||
|
||||
|
||||
###################################
|
||||
# Connection state getter/setters #
|
||||
###################################
|
||||
|
||||
@@ -462,9 +462,8 @@ class vmmCreate(vmmGObjectUI):
|
||||
can_storage = (is_local or is_storage_capable)
|
||||
is_pv = (self.capsguest.os_type == "xen")
|
||||
is_container = self.conn.is_container()
|
||||
can_remote_url = virtinst.support.check_stream_support(
|
||||
self.conn.get_backend(),
|
||||
virtinst.support.SUPPORT_STREAM_UPLOAD)
|
||||
can_remote_url = self.conn.check_stream_support(
|
||||
self.conn.SUPPORT_STREAM_UPLOAD)
|
||||
|
||||
# Install Options
|
||||
method_tree = self.widget("method-tree")
|
||||
@@ -1414,8 +1413,8 @@ class vmmCreate(vmmGObjectUI):
|
||||
if guest.installer.is_container():
|
||||
return
|
||||
|
||||
support_spice = virtinst.support.check_conn_support(guest.conn,
|
||||
virtinst.support.SUPPORT_CONN_HV_GRAPHICS_SPICE)
|
||||
support_spice = guest.conn.check_conn_support(
|
||||
guest.conn.SUPPORT_CONN_HV_GRAPHICS_SPICE)
|
||||
if not self._rhel6_defaults():
|
||||
support_spice = True
|
||||
|
||||
|
||||
@@ -269,7 +269,8 @@ class vmmCreateVolume(vmmGObjectUI):
|
||||
cap = self.widget("vol-capacity").get_value()
|
||||
|
||||
try:
|
||||
self.vol = self.vol_class(name=volname,
|
||||
self.vol = self.vol_class(self.conn,
|
||||
name=volname,
|
||||
allocation=(alloc * 1024 * 1024),
|
||||
capacity=(cap * 1024 * 1024),
|
||||
pool=self.parent_pool.pool)
|
||||
|
||||
+14
-14
@@ -29,7 +29,6 @@ import threading
|
||||
import libvirt
|
||||
import virtinst
|
||||
from virtinst.VirtualCharDevice import VirtualCharSpicevmcDevice
|
||||
import virtinst.support as support
|
||||
|
||||
from virtManager import util
|
||||
from virtManager.libvirtobject import vmmLibvirtObject
|
||||
@@ -209,16 +208,16 @@ class vmmDomain(vmmLibvirtObject):
|
||||
try:
|
||||
self._backend.vcpus()
|
||||
except libvirt.libvirtError, err:
|
||||
if support.is_error_nosupport(err):
|
||||
if virtinst.util.is_error_nosupport(err):
|
||||
self._getvcpus_supported = False
|
||||
return self._getvcpus_supported
|
||||
getvcpus_supported = property(_get_getvcpus_supported)
|
||||
|
||||
def _get_getjobinfo_supported(self):
|
||||
if self._getjobinfo_supported is None:
|
||||
self._getjobinfo_supported = support.check_domain_support(
|
||||
self._getjobinfo_supported = self.conn.check_domain_support(
|
||||
self._backend,
|
||||
support.SUPPORT_DOMAIN_JOB_INFO)
|
||||
self.conn.SUPPORT_DOMAIN_JOB_INFO)
|
||||
return self._getjobinfo_supported
|
||||
getjobinfo_supported = property(_get_getjobinfo_supported)
|
||||
|
||||
@@ -228,11 +227,12 @@ class vmmDomain(vmmLibvirtObject):
|
||||
"""
|
||||
self._reparse_xml()
|
||||
|
||||
self.managedsave_supported = self.conn.get_dom_managedsave_supported(self._backend)
|
||||
self.managedsave_supported = self.conn.get_dom_managedsave_supported(
|
||||
self._backend)
|
||||
|
||||
self.remote_console_supported = support.check_domain_support(
|
||||
self._backend,
|
||||
support.SUPPORT_DOMAIN_CONSOLE_STREAM)
|
||||
self.remote_console_supported = self.conn.check_domain_support(
|
||||
self._backend,
|
||||
self.conn.SUPPORT_DOMAIN_CONSOLE_STREAM)
|
||||
|
||||
# Determine available XML flags (older libvirt versions will error
|
||||
# out if passed SECURE_XML, INACTIVE_XML, etc)
|
||||
@@ -916,8 +916,8 @@ class vmmDomain(vmmLibvirtObject):
|
||||
# libvirt since 0.9.10 provides a SetMetadata API that provides
|
||||
# actual <description> 'hotplug', and using that means checkig
|
||||
# for support, version, etc.
|
||||
if not virtinst.support.check_domain_support(self._backend,
|
||||
virtinst.support.SUPPORT_DOMAIN_SET_METADATA):
|
||||
if not self.conn.check_domain_support(self._backend,
|
||||
self.conn.SUPPORT_DOMAIN_SET_METADATA):
|
||||
return
|
||||
|
||||
flags = (libvirt.VIR_DOMAIN_AFFECT_LIVE |
|
||||
@@ -1269,8 +1269,8 @@ class vmmDomain(vmmLibvirtObject):
|
||||
|
||||
|
||||
def support_downtime(self):
|
||||
return support.check_domain_support(self._backend,
|
||||
support.SUPPORT_DOMAIN_MIGRATE_DOWNTIME)
|
||||
return self.conn.check_domain_support(self._backend,
|
||||
self.conn.SUPPORT_DOMAIN_MIGRATE_DOWNTIME)
|
||||
|
||||
def migrate_set_max_downtime(self, max_downtime, flag=0):
|
||||
self._backend.migrateSetMaxDowntime(max_downtime, flag)
|
||||
@@ -1668,7 +1668,7 @@ class vmmDomain(vmmLibvirtObject):
|
||||
rx += io[0]
|
||||
tx += io[4]
|
||||
except libvirt.libvirtError, err:
|
||||
if support.is_error_nosupport(err):
|
||||
if virtinst.util.is_error_nosupport(err):
|
||||
logging.debug("Net stats not supported: %s", err)
|
||||
self._stats_net_supported = False
|
||||
else:
|
||||
@@ -1705,7 +1705,7 @@ class vmmDomain(vmmLibvirtObject):
|
||||
rd += io[1]
|
||||
wr += io[3]
|
||||
except libvirt.libvirtError, err:
|
||||
if support.is_error_nosupport(err):
|
||||
if virtinst.util.is_error_nosupport(err):
|
||||
logging.debug("Disk stats not supported: %s", err)
|
||||
self._stats_disk_supported = False
|
||||
else:
|
||||
|
||||
@@ -953,7 +953,7 @@ class vmmEngine(vmmGObject):
|
||||
try:
|
||||
vm.reboot()
|
||||
except Exception, reboot_err:
|
||||
no_support = virtinst.support.is_error_nosupport(reboot_err)
|
||||
no_support = virtinst.util.is_error_nosupport(reboot_err)
|
||||
if not no_support:
|
||||
raise RuntimeError(_("Error rebooting domain: %s" %
|
||||
str(reboot_err)))
|
||||
|
||||
+24
-23
@@ -27,8 +27,6 @@ from gi.repository import Gtk
|
||||
# pylint: enable=E0611
|
||||
|
||||
import virtinst
|
||||
from virtinst import VirtualNetworkInterface
|
||||
from virtinst import VirtualDisk
|
||||
|
||||
from virtManager import util
|
||||
from virtManager.error import vmmErrorDialog
|
||||
@@ -40,6 +38,7 @@ OPTICAL_DEV_KEY = 3
|
||||
OPTICAL_MEDIA_KEY = 4
|
||||
OPTICAL_IS_VALID = 5
|
||||
|
||||
|
||||
##############################################################
|
||||
# Initialize an error object to use for validation functions #
|
||||
##############################################################
|
||||
@@ -471,13 +470,13 @@ def build_storage_format_combo(vm, combo):
|
||||
|
||||
|
||||
def pretty_network_desc(nettype, source=None, netobj=None):
|
||||
if nettype == VirtualNetworkInterface.TYPE_USER:
|
||||
if nettype == virtinst.VirtualNetworkInterface.TYPE_USER:
|
||||
return _("Usermode networking")
|
||||
|
||||
extra = None
|
||||
if nettype == VirtualNetworkInterface.TYPE_BRIDGE:
|
||||
if nettype == virtinst.VirtualNetworkInterface.TYPE_BRIDGE:
|
||||
ret = _("Bridge")
|
||||
elif nettype == VirtualNetworkInterface.TYPE_VIRTUAL:
|
||||
elif nettype == virtinst.VirtualNetworkInterface.TYPE_VIRTUAL:
|
||||
ret = _("Virtual network")
|
||||
if netobj:
|
||||
extra = ": %s" % netobj.pretty_forward_mode()
|
||||
@@ -521,7 +520,8 @@ def net_list_changed(net_list, bridge_box,
|
||||
row = net_list.get_model()[active]
|
||||
|
||||
if source_mode_box is not None:
|
||||
show_source_mode = (row[0] == VirtualNetworkInterface.TYPE_DIRECT)
|
||||
show_source_mode = (row[0] ==
|
||||
virtinst.VirtualNetworkInterface.TYPE_DIRECT)
|
||||
source_mode_box.set_property("visible", show_source_mode)
|
||||
source_mode_label.set_property("visible", show_source_mode)
|
||||
vport_expander.set_property("visible", show_source_mode)
|
||||
@@ -542,7 +542,7 @@ def get_network_selection(net_list, bridge_entry):
|
||||
net_check_bridge = row[5]
|
||||
|
||||
if net_check_bridge and bridge_entry:
|
||||
net_type = VirtualNetworkInterface.TYPE_BRIDGE
|
||||
net_type = virtinst.VirtualNetworkInterface.TYPE_BRIDGE
|
||||
net_src = bridge_entry.get_text()
|
||||
|
||||
return net_type, net_src
|
||||
@@ -575,7 +575,7 @@ def populate_network_list(net_list, conn, show_direct_interfaces=True):
|
||||
|
||||
# For qemu:///session
|
||||
if conn.is_qemu_session():
|
||||
nettype = VirtualNetworkInterface.TYPE_USER
|
||||
nettype = virtinst.VirtualNetworkInterface.TYPE_USER
|
||||
r = build_row(nettype, None, pretty_network_desc(nettype), True, True)
|
||||
model.append(r)
|
||||
set_active(0)
|
||||
@@ -586,7 +586,7 @@ def populate_network_list(net_list, conn, show_direct_interfaces=True):
|
||||
# Virtual Networks
|
||||
for uuid in conn.list_net_uuids():
|
||||
net = conn.get_net(uuid)
|
||||
nettype = VirtualNetworkInterface.TYPE_VIRTUAL
|
||||
nettype = virtinst.VirtualNetworkInterface.TYPE_VIRTUAL
|
||||
|
||||
label = pretty_network_desc(nettype, net.get_name(), net)
|
||||
if not net.is_active():
|
||||
@@ -623,7 +623,7 @@ def populate_network_list(net_list, conn, show_direct_interfaces=True):
|
||||
for name in conn.list_net_device_paths():
|
||||
br = conn.get_net_device(name)
|
||||
bridge_name = br.get_bridge()
|
||||
nettype = VirtualNetworkInterface.TYPE_BRIDGE
|
||||
nettype = virtinst.VirtualNetworkInterface.TYPE_BRIDGE
|
||||
|
||||
if ((bridge_name in vnet_bridges) or
|
||||
(br.get_name() in vnet_bridges) or
|
||||
@@ -642,10 +642,10 @@ def populate_network_list(net_list, conn, show_direct_interfaces=True):
|
||||
brlabel = _("(Empty bridge)")
|
||||
else:
|
||||
if (show_direct_interfaces and
|
||||
virtinst.support.check_conn_support(conn.get_backend(),
|
||||
virtinst.support.SUPPORT_CONN_HV_DIRECT_INTERFACE)):
|
||||
conn.check_conn_support(
|
||||
conn.SUPPORT_CONN_HV_DIRECT_INTERFACE)):
|
||||
sensitive = True
|
||||
nettype = VirtualNetworkInterface.TYPE_DIRECT
|
||||
nettype = virtinst.VirtualNetworkInterface.TYPE_DIRECT
|
||||
bridge_name = name
|
||||
brlabel = ": %s" % _("macvtap")
|
||||
else:
|
||||
@@ -713,7 +713,7 @@ def validate_network(parent, conn, nettype, devname, macaddr, model=None):
|
||||
return None
|
||||
|
||||
# Make sure VirtualNetwork is running
|
||||
if (nettype == VirtualNetworkInterface.TYPE_VIRTUAL and
|
||||
if (nettype == virtinst.VirtualNetworkInterface.TYPE_VIRTUAL and
|
||||
devname not in conn.get_backend().listNetworks()):
|
||||
|
||||
res = err_dial.yes_no(_("Virtual Network is not active."),
|
||||
@@ -736,16 +736,16 @@ def validate_network(parent, conn, nettype, devname, macaddr, model=None):
|
||||
try:
|
||||
bridge = None
|
||||
netname = None
|
||||
if nettype == VirtualNetworkInterface.TYPE_VIRTUAL:
|
||||
if nettype == virtinst.VirtualNetworkInterface.TYPE_VIRTUAL:
|
||||
netname = devname
|
||||
elif nettype == VirtualNetworkInterface.TYPE_BRIDGE:
|
||||
elif nettype == virtinst.VirtualNetworkInterface.TYPE_BRIDGE:
|
||||
bridge = devname
|
||||
elif nettype == VirtualNetworkInterface.TYPE_DIRECT:
|
||||
elif nettype == virtinst.VirtualNetworkInterface.TYPE_DIRECT:
|
||||
bridge = devname
|
||||
elif nettype == VirtualNetworkInterface.TYPE_USER:
|
||||
elif nettype == virtinst.VirtualNetworkInterface.TYPE_USER:
|
||||
pass
|
||||
|
||||
net = VirtualNetworkInterface(conn.get_backend(),
|
||||
net = virtinst.VirtualNetworkInterface(conn.get_backend(),
|
||||
type=nettype,
|
||||
bridge=bridge,
|
||||
network=netname,
|
||||
@@ -776,7 +776,7 @@ def validate_network(parent, conn, nettype, devname, macaddr, model=None):
|
||||
def generate_macaddr(conn):
|
||||
newmac = ""
|
||||
try:
|
||||
net = VirtualNetworkInterface(conn.get_backend())
|
||||
net = virtinst.VirtualNetworkInterface(conn.get_backend())
|
||||
net.setup()
|
||||
newmac = net.macaddr
|
||||
except:
|
||||
@@ -984,7 +984,8 @@ def check_path_search_for_qemu(parent, conn, path):
|
||||
user = util.running_config.default_qemu_user
|
||||
|
||||
skip_paths = util.running_config.get_perms_fix_ignore()
|
||||
broken_paths = VirtualDisk.check_path_search_for_user(conn.get_backend(),
|
||||
broken_paths = virtinst.VirtualDisk.check_path_search_for_user(
|
||||
conn.get_backend(),
|
||||
path, user)
|
||||
for p in broken_paths:
|
||||
if p in skip_paths:
|
||||
@@ -1007,8 +1008,8 @@ def check_path_search_for_qemu(parent, conn, path):
|
||||
return
|
||||
|
||||
logging.debug("Attempting to correct permission issues.")
|
||||
errors = VirtualDisk.fix_path_search_for_user(conn.get_backend(),
|
||||
path, user)
|
||||
errors = virtinst.VirtualDisk.fix_path_search_for_user(conn.get_backend(),
|
||||
path, user)
|
||||
if not errors:
|
||||
return
|
||||
|
||||
|
||||
@@ -324,7 +324,8 @@ class Cloner(object):
|
||||
if (clone_disk.vol_install.pool.name() ==
|
||||
orig_disk.vol_object.storagePoolLookupByVolume().name()):
|
||||
newname = clone_disk.vol_install.name
|
||||
clone_disk.vol_install = Storage.CloneVolume(newname,
|
||||
clone_disk.vol_install = Storage.CloneVolume(self.conn,
|
||||
newname,
|
||||
orig_disk.vol_object)
|
||||
|
||||
else:
|
||||
|
||||
@@ -26,7 +26,6 @@ import tempfile
|
||||
import urlgrabber
|
||||
|
||||
from virtinst import Storage
|
||||
from virtinst import support
|
||||
from virtinst import util
|
||||
from virtinst import Installer
|
||||
from virtinst.VirtualDisk import VirtualDisk
|
||||
@@ -220,7 +219,8 @@ class DistroInstaller(Installer.Installer):
|
||||
validated = False
|
||||
|
||||
if (self._location_is_path or
|
||||
(not validated and util.is_storage_capable(self.conn))):
|
||||
(not validated and
|
||||
self.conn.check_conn_support(self.conn.SUPPORT_CONN_STORAGE))):
|
||||
# If user passed a storage tuple, OR
|
||||
# We couldn't determine the location type and a storage capable
|
||||
# connection was passed:
|
||||
@@ -319,8 +319,7 @@ class DistroInstaller(Installer.Installer):
|
||||
def support_remote_url_install(self):
|
||||
if hasattr(self.conn, "_virtinst__fake_conn"):
|
||||
return False
|
||||
return support.check_stream_support(self.conn,
|
||||
support.SUPPORT_STREAM_UPLOAD)
|
||||
return self.conn.check_stream_support(self.conn.SUPPORT_STREAM_UPLOAD)
|
||||
|
||||
def _upload_media(self, guest, meter, kernel, initrd):
|
||||
conn = guest.conn
|
||||
|
||||
+5
-6
@@ -827,9 +827,8 @@ class Guest(XMLBuilderDomain.XMLBuilderDomain):
|
||||
return xml
|
||||
|
||||
def _get_vcpu_xml(self):
|
||||
curvcpus_supported = virtinst.support.check_conn_support(
|
||||
self.conn,
|
||||
virtinst.support.SUPPORT_CONN_MAXVCPUS_XML)
|
||||
curvcpus_supported = self.conn.check_conn_support(
|
||||
self.conn.SUPPORT_CONN_MAXVCPUS_XML)
|
||||
cpuset = ""
|
||||
if self.cpuset is not None:
|
||||
cpuset = " cpuset='%s'" % self.cpuset
|
||||
@@ -1259,7 +1258,7 @@ class Guest(XMLBuilderDomain.XMLBuilderDomain):
|
||||
try:
|
||||
self.domain.setAutostart(True)
|
||||
except libvirt.libvirtError, e:
|
||||
if support.is_error_nosupport(e):
|
||||
if util.is_error_nosupport(e):
|
||||
logging.warn("Could not set autostart flag: libvirt "
|
||||
"connection does not support autostart.")
|
||||
else:
|
||||
@@ -1418,8 +1417,8 @@ class Guest(XMLBuilderDomain.XMLBuilderDomain):
|
||||
|
||||
if (has_spice() and
|
||||
not has_spice_agent() and
|
||||
support.check_conn_support(self.conn,
|
||||
support.SUPPORT_CONN_HV_CHAR_SPICEVMC)):
|
||||
self.conn.check_conn_support(
|
||||
self.conn.SUPPORT_CONN_HV_CHAR_SPICEVMC)):
|
||||
agentdev = VirtualCharDevice.get_dev_instance(self.conn,
|
||||
VirtualCharDevice.DEV_CHANNEL,
|
||||
VirtualCharDevice.CHAR_SPICEVMC)
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
# MA 02110-1301 USA.
|
||||
|
||||
from virtinst import support
|
||||
from virtinst import util
|
||||
import libvirt
|
||||
import logging
|
||||
@@ -396,29 +395,6 @@ class SCSIBus(NodeDevice):
|
||||
child = child.next
|
||||
|
||||
|
||||
def is_nodedev_capable(conn):
|
||||
"""
|
||||
Check if the passed libvirt connection supports host device routines
|
||||
|
||||
@param conn: Connection to check
|
||||
|
||||
@rtype: C{bool}
|
||||
"""
|
||||
return support.check_conn_support(conn, support.SUPPORT_CONN_NODEDEV)
|
||||
|
||||
|
||||
def is_pci_detach_capable(conn):
|
||||
"""
|
||||
Check if the passed libvirt connection support pci device Detach/Reset
|
||||
|
||||
@param conn: Connection to check
|
||||
|
||||
@rtype: C{bool}
|
||||
"""
|
||||
return support.check_conn_support(conn,
|
||||
support.SUPPORT_NODEDEV_PCI_DETACH)
|
||||
|
||||
|
||||
def _lookupNodeName(conn, name):
|
||||
nodedev = conn.nodeDeviceLookupByName(name)
|
||||
xml = nodedev.XMLDesc(0)
|
||||
@@ -438,7 +414,7 @@ def lookupNodeName(conn, name):
|
||||
|
||||
@rtype: L{NodeDevice} instance
|
||||
"""
|
||||
if not is_nodedev_capable(conn):
|
||||
if not conn.check_conn_support(conn.SUPPORT_CONN_NODEDEV):
|
||||
raise ValueError(_("Connection does not support host device "
|
||||
"enumeration."))
|
||||
|
||||
@@ -524,7 +500,7 @@ def devAddressToNodedev(conn, addrstr):
|
||||
- (domain:)bus:slot.func (ex. 00:10.0 for a pci device)
|
||||
@param addrstr: C{str}
|
||||
"""
|
||||
if not is_nodedev_capable(conn):
|
||||
if not conn.check_conn_support(conn.SUPPORT_CONN_NODEDEV):
|
||||
raise ValueError(_("Connection does not support host device "
|
||||
"enumeration."))
|
||||
|
||||
|
||||
+27
-33
@@ -55,7 +55,6 @@ import urlgrabber
|
||||
|
||||
from virtinst.util import xml_escape as escape
|
||||
from virtinst import util
|
||||
from virtinst import support
|
||||
|
||||
|
||||
DEFAULT_DEV_TARGET = "/dev"
|
||||
@@ -69,11 +68,6 @@ VIR_STORAGE_VOL_FILE = 0
|
||||
VIR_STORAGE_VOL_BLOCK = 1
|
||||
|
||||
|
||||
def is_create_vol_from_supported(conn):
|
||||
return support.check_pool_support(conn,
|
||||
support.SUPPORT_STORAGE_CREATEVOLFROM)
|
||||
|
||||
|
||||
def _parse_pool_source_list(source_xml):
|
||||
def source_parser(node):
|
||||
ret_list = []
|
||||
@@ -305,8 +299,7 @@ class StoragePool(StorageObject):
|
||||
@param pool_type: Pool type string from I{Types}
|
||||
@param host: Option host string to poll for sources
|
||||
"""
|
||||
if not support.check_conn_support(conn,
|
||||
support.SUPPORT_CONN_FINDPOOLSOURCES):
|
||||
if not conn.check_conn_support(conn.SUPPORT_CONN_FINDPOOLSOURCES):
|
||||
return []
|
||||
|
||||
pool_class = StoragePool.get_pool_class(pool_type)
|
||||
@@ -320,7 +313,7 @@ class StoragePool(StorageObject):
|
||||
try:
|
||||
xml = conn.findStoragePoolSources(pool_type, source_xml, 0)
|
||||
except libvirt.libvirtError, e:
|
||||
if support.is_error_nosupport(e):
|
||||
if util.is_error_nosupport(e):
|
||||
return []
|
||||
raise
|
||||
|
||||
@@ -971,7 +964,7 @@ class StorageVolume(StorageObject):
|
||||
# File vs. Block for the Volume class
|
||||
_file_type = None
|
||||
|
||||
def __init__(self, name, capacity, conn=None, pool_name=None, pool=None,
|
||||
def __init__(self, conn, name, capacity, pool_name=None, pool=None,
|
||||
allocation=0):
|
||||
"""
|
||||
@param name: Name for the new storage volume
|
||||
@@ -985,16 +978,14 @@ class StorageVolume(StorageObject):
|
||||
if pool_name is None:
|
||||
raise ValueError(_("One of pool or pool_name must be "
|
||||
"specified."))
|
||||
if conn is None:
|
||||
raise ValueError(_("'conn' must be specified with 'pool_name'"))
|
||||
pool = StorageVolume.lookup_pool_by_name(pool_name=pool_name,
|
||||
conn=conn)
|
||||
self._pool = None
|
||||
self.pool = pool
|
||||
poolconn = self.pool._conn # pylint: disable=W0212
|
||||
|
||||
StorageObject.__init__(self, object_type=StorageObject.TYPE_VOLUME,
|
||||
name=name, conn=poolconn)
|
||||
StorageObject.__init__(self, conn,
|
||||
object_type=StorageObject.TYPE_VOLUME,
|
||||
name=name)
|
||||
self._allocation = None
|
||||
self._capacity = None
|
||||
self._format = None
|
||||
@@ -1061,7 +1052,7 @@ class StorageVolume(StorageObject):
|
||||
if pool_name is not None and pool_object is None:
|
||||
if conn is None:
|
||||
raise ValueError(_("'conn' must be specified with 'pool_name'"))
|
||||
if not util.is_storage_capable(conn):
|
||||
if not conn.check_conn_support(conn.SUPPORT_CONN_STORAGE):
|
||||
raise ValueError(_("Connection does not support storage "
|
||||
"management."))
|
||||
try:
|
||||
@@ -1142,8 +1133,8 @@ class StorageVolume(StorageObject):
|
||||
if not isinstance(vol, libvirt.virStorageVol):
|
||||
raise ValueError(_("input_vol must be a virStorageVol"))
|
||||
|
||||
poolconn = self.pool._conn # pylint: disable=W0212
|
||||
if not is_create_vol_from_supported(poolconn):
|
||||
if not self.conn.check_pool_support(self.conn,
|
||||
self.conn.SUPPORT_STORAGE_CREATEVOLFROM):
|
||||
raise ValueError(_("Creating storage from an existing volume is"
|
||||
" not supported by this libvirt version."))
|
||||
self._input_vol = vol
|
||||
@@ -1232,7 +1223,7 @@ class StorageVolume(StorageObject):
|
||||
self.name)
|
||||
return vol
|
||||
except libvirt.libvirtError, e:
|
||||
if support.is_error_nosupport(e):
|
||||
if util.is_error_nosupport(e):
|
||||
raise RuntimeError("Libvirt version does not support "
|
||||
"storage cloning.")
|
||||
raise
|
||||
@@ -1313,14 +1304,15 @@ class FileVolume(StorageVolume):
|
||||
perms = property(StorageObject.get_perms, StorageObject.set_perms)
|
||||
format = property(StorageVolume.get_format, StorageVolume.set_format)
|
||||
|
||||
def __init__(self, name, capacity, pool=None, pool_name=None, conn=None,
|
||||
def __init__(self, conn, name, capacity,
|
||||
pool=None, pool_name=None,
|
||||
format="raw", allocation=None, perms=None):
|
||||
# pylint: disable=W0622
|
||||
# Redefining built-in 'format', but it matches the XML so keep it
|
||||
|
||||
StorageVolume.__init__(self, name=name, pool=pool, pool_name=pool_name,
|
||||
allocation=allocation, capacity=capacity,
|
||||
conn=conn)
|
||||
StorageVolume.__init__(self, conn, name=name,
|
||||
pool=pool, pool_name=pool_name,
|
||||
allocation=allocation, capacity=capacity)
|
||||
self.format = format
|
||||
if perms:
|
||||
self.perms = perms
|
||||
@@ -1342,11 +1334,12 @@ class DiskVolume(StorageVolume):
|
||||
# Register applicable property methods from parent class
|
||||
perms = property(StorageObject.get_perms, StorageObject.set_perms)
|
||||
|
||||
def __init__(self, name, capacity, pool=None, pool_name=None, conn=None,
|
||||
def __init__(self, conn, name, capacity,
|
||||
pool=None, pool_name=None,
|
||||
allocation=None, perms=None):
|
||||
StorageVolume.__init__(self, name=name, pool=pool, pool_name=pool_name,
|
||||
allocation=allocation, capacity=capacity,
|
||||
conn=conn)
|
||||
StorageVolume.__init__(self, conn, name=name,
|
||||
pool=pool, pool_name=pool_name,
|
||||
allocation=allocation, capacity=capacity)
|
||||
if perms:
|
||||
self.perms = perms
|
||||
|
||||
@@ -1366,14 +1359,15 @@ class LogicalVolume(StorageVolume):
|
||||
# Register applicable property methods from parent class
|
||||
perms = property(StorageObject.get_perms, StorageObject.set_perms)
|
||||
|
||||
def __init__(self, name, capacity, pool=None, pool_name=None, conn=None,
|
||||
def __init__(self, conn,
|
||||
name, capacity, pool=None, pool_name=None,
|
||||
allocation=None, perms=None):
|
||||
if allocation and allocation != capacity:
|
||||
logging.warn(_("Sparse logical volumes are not supported, "
|
||||
"setting allocation equal to capacity"))
|
||||
StorageVolume.__init__(self, name=name, pool=pool, pool_name=pool_name,
|
||||
allocation=capacity, capacity=capacity,
|
||||
conn=conn)
|
||||
StorageVolume.__init__(self, conn, name=name,
|
||||
pool=pool, pool_name=pool_name,
|
||||
allocation=capacity, capacity=capacity)
|
||||
if perms:
|
||||
self.perms = perms
|
||||
|
||||
@@ -1404,7 +1398,7 @@ class CloneVolume(StorageVolume):
|
||||
|
||||
format = property(StorageVolume.get_format, StorageVolume.set_format)
|
||||
|
||||
def __init__(self, name, input_vol):
|
||||
def __init__(self, conn, name, input_vol):
|
||||
if not isinstance(input_vol, libvirt.virStorageVol):
|
||||
raise ValueError(_("input_vol must be a virStorageVol"))
|
||||
|
||||
@@ -1417,7 +1411,7 @@ class CloneVolume(StorageVolume):
|
||||
alc = int(util.get_xml_path(xml, "/volume/allocation"))
|
||||
fmt = util.get_xml_path(xml, "/volume/target/format/@type")
|
||||
|
||||
StorageVolume.__init__(self, name=name, pool=pool,
|
||||
StorageVolume.__init__(self, conn, name=name, pool=pool,
|
||||
pool_name=pool.name(),
|
||||
allocation=alc, capacity=cap)
|
||||
|
||||
|
||||
+10
-8
@@ -106,7 +106,7 @@ def _check_if_pool_source(conn, path):
|
||||
If passed path is a host disk device like /dev/sda, want to let the user
|
||||
use it
|
||||
"""
|
||||
if not util.is_storage_capable(conn):
|
||||
if not conn.check_conn_support(conn.SUPPORT_CONN_STORAGE):
|
||||
return None
|
||||
|
||||
def check_pool(poolname, path):
|
||||
@@ -208,7 +208,7 @@ def _check_if_path_managed(conn, path):
|
||||
return vol, pool, path_is_pool
|
||||
|
||||
|
||||
def _build_vol_install(path, pool, size, sparse):
|
||||
def _build_vol_install(conn, path, pool, size, sparse):
|
||||
# Path wasn't a volume. See if base of path is a managed
|
||||
# pool, and if so, setup a StorageVolume object
|
||||
if size is None:
|
||||
@@ -227,7 +227,7 @@ def _build_vol_install(path, pool, size, sparse):
|
||||
else:
|
||||
alloc = cap
|
||||
|
||||
volinst = volclass(name=os.path.basename(path),
|
||||
volinst = volclass(conn, name=os.path.basename(path),
|
||||
capacity=cap, allocation=alloc, pool=pool)
|
||||
return volinst
|
||||
|
||||
@@ -521,7 +521,7 @@ class VirtualDisk(VirtualDevice):
|
||||
|
||||
if not conn:
|
||||
raise ValueError(_("'volName' requires a passed connection."))
|
||||
if not util.is_storage_capable(conn):
|
||||
if not conn.check_conn_support(conn.SUPPORT_CONN_STORAGE):
|
||||
raise ValueError(_("Connection does not support storage lookup."))
|
||||
|
||||
try:
|
||||
@@ -991,8 +991,8 @@ class VirtualDisk(VirtualDevice):
|
||||
Validates and updates params when the backing storage is changed
|
||||
"""
|
||||
pool = None
|
||||
|
||||
storage_capable = util.is_storage_capable(self.conn)
|
||||
storage_capable = self.conn.check_conn_support(
|
||||
self.conn.SUPPORT_CONN_STORAGE)
|
||||
|
||||
# Try to lookup self.path storage objects
|
||||
if vol_object or vol_install:
|
||||
@@ -1006,7 +1006,8 @@ class VirtualDisk(VirtualDevice):
|
||||
not vol_object and
|
||||
not path_is_pool and
|
||||
not self._is_parse()):
|
||||
vol_install = _build_vol_install(path, pool,
|
||||
vol_install = _build_vol_install(self.conn,
|
||||
path, pool,
|
||||
self.size,
|
||||
self.sparse)
|
||||
|
||||
@@ -1212,7 +1213,8 @@ class VirtualDisk(VirtualDevice):
|
||||
|
||||
return True
|
||||
|
||||
storage_capable = util.is_storage_capable(self.conn)
|
||||
storage_capable = self.conn.check_conn_support(
|
||||
self.conn.SUPPORT_CONN_STORAGE)
|
||||
|
||||
if self.conn.is_remote():
|
||||
if not storage_capable:
|
||||
|
||||
@@ -21,7 +21,6 @@ import re
|
||||
import os
|
||||
|
||||
from virtinst.VirtualDevice import VirtualDevice
|
||||
from virtinst import support
|
||||
from virtinst.XMLBuilderDomain import _xml_property
|
||||
|
||||
|
||||
@@ -132,8 +131,8 @@ class VirtualGraphics(VirtualDevice):
|
||||
|
||||
def _default_keymap(self, force_local=False):
|
||||
if (not force_local and
|
||||
support.check_conn_support(self.conn,
|
||||
support.SUPPORT_CONN_KEYMAP_AUTODETECT)):
|
||||
self.conn.check_conn_support(
|
||||
self.conn.SUPPORT_CONN_KEYMAP_AUTODETECT)):
|
||||
return None
|
||||
|
||||
if self._local_keymap == -1:
|
||||
|
||||
+2
-2
@@ -314,10 +314,10 @@ def install_fail(guest):
|
||||
|
||||
|
||||
def build_default_pool(guest):
|
||||
|
||||
if not virtinst.util.is_storage_capable(guest.conn):
|
||||
if not guest.conn.check_conn_support(guest.conn.SUPPORT_CONN_STORAGE):
|
||||
# VirtualDisk will raise an error for us
|
||||
return
|
||||
|
||||
pool = None
|
||||
try:
|
||||
pool = guest.conn.storagePoolLookupByName(DEFAULT_POOL_NAME)
|
||||
|
||||
@@ -22,6 +22,7 @@ import re
|
||||
|
||||
import libvirt
|
||||
|
||||
from virtinst import support
|
||||
from virtinst.cli import parse_optstr
|
||||
from virtinst.util import uri_split
|
||||
|
||||
@@ -149,6 +150,30 @@ class VirtualConnection(object):
|
||||
return self.is_lxc() or self.is_openvz()
|
||||
|
||||
|
||||
#########################
|
||||
# Support check helpers #
|
||||
#########################
|
||||
|
||||
for _supportname in [_supportname for _supportname in dir(support) if
|
||||
_supportname.startswith("SUPPORT_")]:
|
||||
locals()[_supportname] = getattr(support, _supportname)
|
||||
|
||||
def check_conn_support(self, feature):
|
||||
return support.check_support(self, feature, self)
|
||||
def check_conn_hv_support(self, feature, hv):
|
||||
return support.check_support(self, feature, hv)
|
||||
def check_domain_support(self, dom, feature):
|
||||
return support.check_support(self, feature, dom)
|
||||
def check_pool_support(self, pool, feature):
|
||||
return support.check_support(self, feature, pool)
|
||||
def check_nodedev_support(self, nodedev, feature):
|
||||
return support.check_support(self, feature, nodedev)
|
||||
def check_interface_support(self, iface, feature):
|
||||
return support.check_support(self, feature, iface)
|
||||
def check_stream_support(self, feature):
|
||||
return (self.check_conn_support(self.SUPPORT_CONN_STREAM) and
|
||||
support.check_support(self, feature, self))
|
||||
|
||||
|
||||
###################
|
||||
# Private helpers #
|
||||
|
||||
+1
-3
@@ -181,9 +181,7 @@ def parse_key_entry(conn, hv_type, key_entry, defaults):
|
||||
|
||||
# HV_ALL means don't check for support, just return the value
|
||||
if support_key != HV_ALL:
|
||||
support_ret = support.check_conn_hv_support(conn,
|
||||
support_key,
|
||||
hv_type)
|
||||
support_ret = conn.check_conn_hv_support(support_key, hv_type)
|
||||
|
||||
if support_ret is not True:
|
||||
continue
|
||||
|
||||
+6
-72
@@ -21,6 +21,7 @@
|
||||
|
||||
import libvirt
|
||||
|
||||
from virtinst import util
|
||||
|
||||
# Flags for check_conn_support
|
||||
(SUPPORT_CONN_STORAGE,
|
||||
@@ -297,20 +298,6 @@ def get_rhel6():
|
||||
return _rhel6
|
||||
|
||||
|
||||
# Pull a connection object from the passed libvirt object
|
||||
def _get_conn_from_object(obj):
|
||||
conn = None
|
||||
if hasattr(obj, "getURI"):
|
||||
conn = obj
|
||||
elif hasattr(obj, "_conn"):
|
||||
conn = getattr(obj, "_conn")
|
||||
|
||||
if conn:
|
||||
from virtinst import VirtualConnection
|
||||
return VirtualConnection(conn.getURI())
|
||||
return obj
|
||||
|
||||
|
||||
# Check that command is present in the python bindings, and return the
|
||||
# the requested function
|
||||
def _get_command(funcname, objname=None, obj=None):
|
||||
@@ -345,7 +332,7 @@ def _try_command(func, args, check_all_error=False):
|
||||
func(*args)
|
||||
|
||||
except libvirt.libvirtError, e:
|
||||
if is_error_nosupport(e):
|
||||
if util.is_error_nosupport(e):
|
||||
return False
|
||||
|
||||
if check_all_error:
|
||||
@@ -383,9 +370,8 @@ def _daemon_lib_ver(conn, is_remote, force_version, minimum_libvirt_version):
|
||||
|
||||
return conn.getLibVersion()
|
||||
|
||||
|
||||
# Return the hypervisor version
|
||||
|
||||
|
||||
def _hv_ver(conn, drv_type):
|
||||
args = ()
|
||||
|
||||
@@ -421,7 +407,7 @@ def _split_function_name(function):
|
||||
return (output[0], output[1])
|
||||
|
||||
|
||||
def _check_support(conn, feature, data=None):
|
||||
def check_support(conn, feature, data=None):
|
||||
"""
|
||||
Attempt to determine if a specific libvirt feature is support given
|
||||
the passed connection.
|
||||
@@ -437,12 +423,9 @@ def _check_support(conn, feature, data=None):
|
||||
"""
|
||||
is_remote = conn.is_remote()
|
||||
drv_type = conn.get_uri_driver()
|
||||
|
||||
# Temporary hack to make this work
|
||||
if "VirtualConnection" in repr(conn):
|
||||
conn = getattr(conn, "_libvirtconn")
|
||||
conn = conn.libvirtconn
|
||||
if "VirtualConnection" in repr(data):
|
||||
data = getattr(data, "_libvirtconn")
|
||||
data = data.libvirtconn
|
||||
|
||||
support_info = _support_dict[feature]
|
||||
key_list = support_info.keys()
|
||||
@@ -582,55 +565,6 @@ def _check_support(conn, feature, data=None):
|
||||
|
||||
return True
|
||||
|
||||
# Public API below
|
||||
|
||||
|
||||
def is_error_nosupport(err):
|
||||
"""
|
||||
Check if passed exception indicates that the called libvirt command isn't
|
||||
supported
|
||||
|
||||
@param err: Exception raised from command call
|
||||
@returns: True if command isn't supported, False if we can't determine
|
||||
"""
|
||||
if not isinstance(err, libvirt.libvirtError):
|
||||
return False
|
||||
|
||||
if (err.get_error_code() == libvirt.VIR_ERR_RPC or
|
||||
err.get_error_code() == libvirt.VIR_ERR_NO_SUPPORT):
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
|
||||
def support_threading():
|
||||
return bool(_local_lib_ver() >= 6000)
|
||||
|
||||
|
||||
def check_conn_support(conn, feature):
|
||||
return _check_support(conn, feature, conn)
|
||||
|
||||
|
||||
def check_conn_hv_support(conn, feature, hv):
|
||||
return _check_support(conn, feature, hv)
|
||||
|
||||
|
||||
def check_domain_support(dom, feature):
|
||||
return _check_support(_get_conn_from_object(dom), feature, dom)
|
||||
|
||||
|
||||
def check_pool_support(pool, feature):
|
||||
return _check_support(_get_conn_from_object(pool), feature, pool)
|
||||
|
||||
|
||||
def check_nodedev_support(nodedev, feature):
|
||||
return _check_support(_get_conn_from_object(nodedev), feature, nodedev)
|
||||
|
||||
|
||||
def check_interface_support(nodedev, feature):
|
||||
return _check_support(_get_conn_from_object(nodedev), feature, nodedev)
|
||||
|
||||
|
||||
def check_stream_support(conn, feature):
|
||||
return (check_conn_support(conn, SUPPORT_CONN_STREAM) and
|
||||
_check_support(conn, feature, conn))
|
||||
|
||||
+19
-8
@@ -473,13 +473,6 @@ def xml_escape(xml):
|
||||
return xml
|
||||
|
||||
|
||||
def is_storage_capable(conn):
|
||||
"""check if virConnectPtr passed has storage API support"""
|
||||
from virtinst import support
|
||||
|
||||
return support.check_conn_support(conn, support.SUPPORT_CONN_STORAGE)
|
||||
|
||||
|
||||
def get_xml_path(xml, path=None, func=None):
|
||||
"""
|
||||
Return the content from the passed xml xpath, or return the result
|
||||
@@ -523,7 +516,7 @@ def lookup_pool_by_path(conn, path):
|
||||
Favor running pools over inactive pools.
|
||||
@returns: virStoragePool object if found, None otherwise
|
||||
"""
|
||||
if not is_storage_capable(conn):
|
||||
if not conn.check_conn_support(conn.SUPPORT_CONN_STORAGE):
|
||||
return None
|
||||
|
||||
def check_pool(poolname, path):
|
||||
@@ -575,3 +568,21 @@ def uri_split(uri):
|
||||
else:
|
||||
scheme = uri.lower()
|
||||
return scheme, username, netloc, uri, query, fragment
|
||||
|
||||
|
||||
def is_error_nosupport(err):
|
||||
"""
|
||||
Check if passed exception indicates that the called libvirt command isn't
|
||||
supported
|
||||
|
||||
@param err: Exception raised from command call
|
||||
@returns: True if command isn't supported, False if we can't determine
|
||||
"""
|
||||
if not isinstance(err, libvirt.libvirtError):
|
||||
return False
|
||||
|
||||
if (err.get_error_code() == libvirt.VIR_ERR_RPC or
|
||||
err.get_error_code() == libvirt.VIR_ERR_NO_SUPPORT):
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
Reference in New Issue
Block a user