libvirtobject: Make parseclass non-optional

All libvirtobject child classes have an associated XMLBuilder now, so
make it mandatory.
This commit is contained in:
Cole Robinson
2013-09-23 08:34:50 -04:00
parent b690557a53
commit a7b1414dc5
9 changed files with 96 additions and 111 deletions

View File

@@ -650,7 +650,7 @@ class vmmConnection(vmmGObject):
def get_nodedevs(self, devtype=None, devcap=None):
retdevs = []
for dev in self.nodedevs.values():
vdev = dev.get_virtinst_obj()
vdev = dev.get_xmlobj()
if devtype and vdev.device_type != devtype:
continue

View File

@@ -145,19 +145,15 @@ class vmmDomainSnapshot(vmmLibvirtObject):
"""
def __init__(self, conn, backend):
vmmLibvirtObject.__init__(self, conn, backend, backend.getName(),
parseclass=virtinst.DomainSnapshot)
virtinst.DomainSnapshot)
self.refresh_xml()
def get_name(self):
return self.xmlobj.name
return self.get_xmlobj().name
def _XMLDesc(self, flags):
return self._backend.getXMLDesc(flags=flags)
def _get_xmlobj_prop(self):
return self._get_xmlobj()
xmlobj = property(_get_xmlobj_prop)
def is_current(self):
return self._backend.isCurrent()
def delete(self):
@@ -179,7 +175,7 @@ class vmmDomain(vmmLibvirtObject):
def __init__(self, conn, backend, key):
vmmLibvirtObject.__init__(self, conn, backend, key,
parseclass=virtinst.Guest)
virtinst.Guest)
self.uuid = key
self.cloning = False
@@ -386,7 +382,7 @@ class vmmDomain(vmmLibvirtObject):
# 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
@@ -394,7 +390,7 @@ class vmmDomain(vmmLibvirtObject):
"inactive VM configuration: %s") % repr(origdev))
def get_guest_for_virtinst_func(self, *args, **kwargs):
return self._get_xmlobj(*args, **kwargs)
return self.get_xmlobj(*args, **kwargs)
##############################
@@ -954,49 +950,49 @@ class vmmDomain(vmmLibvirtObject):
########################
def is_container(self):
return self._get_xmlobj().os.is_container()
return self.get_xmlobj().os.is_container()
def is_xenpv(self):
return self._get_xmlobj().os.is_xenpv()
return self.get_xmlobj().os.is_xenpv()
def is_hvm(self):
return self._get_xmlobj().os.is_hvm()
return self.get_xmlobj().os.is_hvm()
def get_uuid(self):
return self.uuid
def get_abi_type(self):
return self._get_xmlobj().os.os_type
return self.get_xmlobj().os.os_type
def get_hv_type(self):
return self._get_xmlobj().type
return self.get_xmlobj().type
def get_pretty_hv_type(self):
return uihelpers.pretty_hv(self.get_abi_type(), self.get_hv_type())
def get_arch(self):
return self._get_xmlobj().os.arch
return self.get_xmlobj().os.arch
def get_init(self):
return self._get_xmlobj().os.init
return self.get_xmlobj().os.init
def get_emulator(self):
return self._get_xmlobj().emulator
return self.get_xmlobj().emulator
def get_acpi(self):
return self._get_xmlobj().features["acpi"]
return self.get_xmlobj().features["acpi"]
def get_apic(self):
return self._get_xmlobj().features["apic"]
return self.get_xmlobj().features["apic"]
def get_clock(self):
return self._get_xmlobj().clock.offset
return self.get_xmlobj().clock.offset
def get_machtype(self):
return self._get_xmlobj().os.machine
return self.get_xmlobj().os.machine
def get_description(self):
# Always show the inactive <description>, let's us fake hotplug
# for a field that's strictly metadata
return self._get_xmlobj(inactive=True).description
return self.get_xmlobj(inactive=True).description
def get_memory(self):
return int(self._get_xmlobj().memory)
return int(self.get_xmlobj().memory)
def maximum_memory(self):
return int(self._get_xmlobj().maxmemory)
return int(self.get_xmlobj().maxmemory)
def vcpu_count(self):
return int(self._get_xmlobj().vcpus)
return int(self.get_xmlobj().vcpus)
def vcpu_max_count(self):
guest = self._get_xmlobj()
guest = self.get_xmlobj()
has_xml_max = (guest.curvcpus != guest.vcpus)
if has_xml_max or not self.is_active():
return guest.vcpus
@@ -1006,22 +1002,22 @@ class vmmDomain(vmmLibvirtObject):
return int(self._startup_vcpus)
def vcpu_pinning(self):
return self._get_xmlobj().cpuset or ""
return self.get_xmlobj().cpuset or ""
def get_cpu_config(self):
return self._get_xmlobj().cpu
return self.get_xmlobj().cpu
def get_boot_device(self):
return self._get_xmlobj().os.bootorder
return self.get_xmlobj().os.bootorder
def get_boot_menu(self):
guest = self._get_xmlobj()
guest = self.get_xmlobj()
return bool(guest.os.enable_bootmenu)
def get_boot_kernel_info(self):
guest = self._get_xmlobj()
guest = self.get_xmlobj()
return (guest.os.kernel, guest.os.initrd,
guest.os.dtb, guest.os.kernel_args)
def get_seclabel(self):
seclabel = self._get_xmlobj().seclabel
seclabel = self.get_xmlobj().seclabel
model = seclabel.model
t = seclabel.type or "dynamic"
label = seclabel.label or ""
@@ -1047,7 +1043,7 @@ class vmmDomain(vmmLibvirtObject):
def _build_device_list(self, device_type,
refresh_if_nec=True, inactive=False):
guest = self._get_xmlobj(refresh_if_nec=refresh_if_nec,
guest = self.get_xmlobj(refresh_if_nec=refresh_if_nec,
inactive=inactive)
devs = guest.get_devices(device_type)
@@ -1783,7 +1779,7 @@ class vmmDomainVirtinst(vmmDomain):
if not self._orig_xml:
self._orig_xml = self._backend.get_xml_config()
def _get_xmlobj(self, inactive=False, refresh_if_nec=True):
def get_xmlobj(self, inactive=False, refresh_if_nec=True):
self._refresh_orig_xml()
return self._backend
def _reparse_xml(self, *args, **kwargs):

View File

@@ -25,8 +25,7 @@ from virtManager.libvirtobject import vmmLibvirtObject
class vmmInterface(vmmLibvirtObject):
def __init__(self, conn, backend, key):
vmmLibvirtObject.__init__(self, conn, backend, key,
parseclass=Interface)
vmmLibvirtObject.__init__(self, conn, backend, key, Interface)
self._name = key
self._active = True
@@ -74,7 +73,7 @@ class vmmInterface(vmmLibvirtObject):
return self._name
def get_mac(self):
return self._get_xmlobj().macaddr
return self.get_xmlobj().macaddr
def _kick_conn(self):
self.conn.schedule_priority_tick(polliface=True)
@@ -98,7 +97,7 @@ class vmmInterface(vmmLibvirtObject):
return typ == "bridge"
def get_type(self):
return self._get_xmlobj().type
return self.get_xmlobj().type
def get_pretty_type(self):
itype = self.get_type()
@@ -111,7 +110,7 @@ class vmmInterface(vmmLibvirtObject):
return "Interface"
def get_startmode(self):
return self._get_xmlobj().start_mode or "none"
return self.get_xmlobj().start_mode or "none"
def set_startmode(self, newmode):
def change(obj):
@@ -121,14 +120,14 @@ class vmmInterface(vmmLibvirtObject):
def get_slaves(self):
return [[obj.name, obj.type or "Unknown"] for obj in
self._get_xmlobj().interfaces]
self.get_xmlobj().interfaces]
def get_slave_names(self):
# Returns a list of names of all enslaved interfaces
return [x[0] for x in self.get_slaves()]
def _get_ip(self, iptype):
obj = self._get_xmlobj()
obj = self.get_xmlobj()
found = None
for protocol in obj.protocols:
if protocol.family == iptype:
@@ -164,4 +163,4 @@ class vmmInterface(vmmLibvirtObject):
return [proto.dhcp, proto.autoconf, ips]
def get_protocol_xml(self):
return self._get_xmlobj().protocols[:]
return self.get_xmlobj().protocols[:]

View File

@@ -47,7 +47,7 @@ class vmmLibvirtObject(vmmGObject):
"stopped": (GObject.SignalFlags.RUN_FIRST, None, []),
}
def __init__(self, conn, backend, key, parseclass=None):
def __init__(self, conn, backend, key, parseclass):
vmmGObject.__init__(self)
self._conn = conn
self._backend = backend
@@ -78,13 +78,13 @@ class vmmLibvirtObject(vmmGObject):
def get_key(self):
return self._key
#############################################################
# Functions that should probably be overridden in sub class #
#############################################################
def get_name(self):
raise NotImplementedError()
def _XMLDesc(self, flags):
raise NotImplementedError()
@@ -101,9 +101,21 @@ class vmmLibvirtObject(vmmGObject):
"""
See _get_raw_xml for parameter docs
"""
if self._parseclass:
return self._get_xmlobj(*args, **kwargs).get_xml_config()
return self._get_raw_xml(*args, **kwargs)
return self.get_xmlobj(*args, **kwargs).get_xml_config()
def get_xmlobj(self, inactive=False, refresh_if_nec=True):
xml = self._get_raw_xml(inactive, refresh_if_nec)
if inactive:
# If inactive XML requested, always return a fresh object even
# the current object is inactive XML (like when the domain is
# stopped). Callers that request inactive are basically expecting
# a new copy.
return self._build_xmlobj(xml)
if not self._xmlobj:
self._reparse_xml()
return self._xmlobj
def refresh_xml(self, forcesignal=False):
# Force an xml update. Signal 'config-changed' if domain xml has
@@ -154,20 +166,6 @@ class vmmLibvirtObject(vmmGObject):
return self._xml
def _get_xmlobj(self, inactive=False, refresh_if_nec=True):
xml = self._get_raw_xml(inactive, refresh_if_nec)
if inactive:
# If inactive XML requested, always return a fresh object even
# the current object is inactive XML (like when the domain is
# stopped). Callers that request inactive are basically expecting
# a new copy.
return self._build_xmlobj(xml)
if not self._xmlobj:
self._reparse_xml()
return self._xmlobj
def _xml_to_redefine(self):
return _sanitize_xml(self.get_xml(inactive=True))
@@ -181,8 +179,6 @@ class vmmLibvirtObject(vmmGObject):
self._redefine_xml(xml)
def _reparse_xml(self, ignore=None):
if not self._parseclass:
return
self._xmlobj = self._build_xmlobj(self._get_raw_xml())
def _build_xmlobj(self, xml):
@@ -190,7 +186,7 @@ class vmmLibvirtObject(vmmGObject):
def _get_xmlobj_to_define(self):
if not self._xmlobj_to_define:
self._xmlobj_to_define = self._get_xmlobj(inactive=True)
self._xmlobj_to_define = self.get_xmlobj(inactive=True)
return self._xmlobj_to_define
def _redefine_helper(self, origxml, newxml):

View File

@@ -40,7 +40,7 @@ class vmmMediaDevice(vmmGObject):
@staticmethod
def mediadev_from_nodedev(dev):
nodedev = dev.get_virtinst_obj()
nodedev = dev.get_xmlobj()
if nodedev.device_type != "storage":
return None

View File

@@ -40,7 +40,7 @@ def _make_addr_str(addrStr, prefix, netmaskStr):
class vmmNetwork(vmmLibvirtObject):
def __init__(self, conn, backend, key):
vmmLibvirtObject.__init__(self, conn, backend, key, parseclass=Network)
vmmLibvirtObject.__init__(self, conn, backend, key, Network)
self._active = True
self._support_isactive = None
@@ -113,23 +113,23 @@ class vmmNetwork(vmmLibvirtObject):
###############
def get_uuid(self):
return self._get_xmlobj().uuid
return self.get_xmlobj().uuid
def get_bridge_device(self):
return self._get_xmlobj().bridge
return self.get_xmlobj().bridge
def get_name_domain(self):
return self._get_xmlobj().domain_name
return self.get_xmlobj().domain_name
def get_ipv6_enabled(self):
return self._get_xmlobj().ipv6
return self.get_xmlobj().ipv6
def get_ipv4_forward_mode(self):
return self._get_xmlobj().forward.mode
return self.get_xmlobj().forward.mode
def pretty_forward_mode(self):
return self._get_xmlobj().forward.pretty_desc()
return self.get_xmlobj().forward.pretty_desc()
def can_pxe(self):
return self._get_xmlobj().can_pxe()
return self.get_xmlobj().can_pxe()
def _get_static_route(self, family):
xmlobj = self._get_xmlobj()
xmlobj = self.get_xmlobj()
route = None
for r in xmlobj.routes:
if (r.family == family or (family == "ipv4" and not r.family)):
@@ -149,7 +149,7 @@ class vmmNetwork(vmmLibvirtObject):
dhcpstart = None
dhcpend = None
xmlobj = self._get_xmlobj()
xmlobj = self.get_xmlobj()
ip = None
for i in xmlobj.ips:
if (i.family == family or

View File

@@ -23,14 +23,14 @@ from virtinst import NodeDevice
from virtManager.libvirtobject import vmmLibvirtObject
def _parse_convert(conn, parsexml=None):
return NodeDevice.parse(conn, parsexml)
class vmmNodeDevice(vmmLibvirtObject):
def __init__(self, conn, backend, key):
vmmLibvirtObject.__init__(self, conn, backend, key)
vmmLibvirtObject.__init__(self, conn, backend, key, _parse_convert)
self._name = key
self._virtinst_obj = None
self.get_virtinst_obj()
def _XMLDesc(self, flags):
return self._backend.XMLDesc(flags)
@@ -39,11 +39,5 @@ class vmmNodeDevice(vmmLibvirtObject):
def is_active(self):
return True
def get_virtinst_obj(self):
if not self._virtinst_obj:
self._virtinst_obj = NodeDevice.parse(self.conn.get_backend(),
self._backend.XMLDesc(0))
return self._virtinst_obj
def tick(self):
pass

View File

@@ -173,7 +173,7 @@ class vmmSnapshotPage(vmmGObjectUI):
do_select = None
for snap in snapshots:
desc = snap.xmlobj.description
desc = snap.get_xmlobj().description
if not uihelpers.can_set_row_none:
desc = desc or ""
@@ -197,13 +197,14 @@ class vmmSnapshotPage(vmmGObjectUI):
def _set_snapshot_state(self, snap=None):
self.widget("snapshot-notebook").set_current_page(0)
name = snap and snap.get_name() or ""
desc = snap and snap.xmlobj.description or ""
state = snap and snap.xmlobj.state or "shutoff"
xmlobj = snap and snap.get_xmlobj() or None
name = snap and xmlobj.name or ""
desc = snap and xmlobj.description or ""
state = snap and xmlobj.state or "shutoff"
timestamp = ""
if snap:
timestamp = str(datetime.datetime.fromtimestamp(
snap.xmlobj.creationTime))
xmlobj.creationTime))
current = ""
if snap and snap.is_current():
@@ -249,8 +250,9 @@ class vmmSnapshotPage(vmmGObjectUI):
desc_widget = self.widget("snapshot-description")
desc = desc_widget.get_buffer().get_property("text") or ""
snap.xmlobj.description = desc
newxml = snap.xmlobj.get_xml_config()
xmlobj = snap.get_xmlobj()
xmlobj.description = desc
newxml = xmlobj.get_xml_config()
self.vm.create_snapshot(newxml, redefine=True)
snap.refresh_xml()
self._set_snapshot_state(snap)

View File

@@ -30,8 +30,7 @@ from virtManager.libvirtobject import vmmLibvirtObject
class vmmStorageVolume(vmmLibvirtObject):
def __init__(self, conn, backend, key):
vmmLibvirtObject.__init__(self, conn, backend, key,
parseclass=StorageVolume)
vmmLibvirtObject.__init__(self, conn, backend, key, StorageVolume)
##########################
@@ -39,7 +38,7 @@ class vmmStorageVolume(vmmLibvirtObject):
##########################
def get_name(self):
return self._get_xmlobj().name
return self.get_xmlobj().name
def _XMLDesc(self, flags):
return self._backend.XMLDesc(flags)
@@ -62,13 +61,13 @@ class vmmStorageVolume(vmmLibvirtObject):
#################
def get_target_path(self):
return self._get_xmlobj().target_path or ""
return self.get_xmlobj().target_path or ""
def get_format(self):
return self._get_xmlobj().format
return self.get_xmlobj().format
def get_capacity(self):
return self._get_xmlobj().capacity
return self.get_xmlobj().capacity
def get_allocation(self):
return self._get_xmlobj().allocation
return self.get_xmlobj().allocation
def get_pretty_capacity(self):
return util.pretty_bytes(self.get_capacity())
@@ -82,8 +81,7 @@ class vmmStoragePool(vmmLibvirtObject):
}
def __init__(self, conn, backend, key):
vmmLibvirtObject.__init__(self, conn, backend, key,
parseclass=StoragePool)
vmmLibvirtObject.__init__(self, conn, backend, key, StoragePool)
self._active = True
self._support_isactive = None
@@ -99,7 +97,7 @@ class vmmStoragePool(vmmLibvirtObject):
##########################
def get_name(self):
return self._get_xmlobj().name
return self.get_xmlobj().name
def _XMLDesc(self, flags):
return self._backend.XMLDesc(flags)
def _define(self, xml):
@@ -143,7 +141,7 @@ class vmmStoragePool(vmmLibvirtObject):
typ = self.get_type()
return (typ in [StoragePool.TYPE_LOGICAL])
def supports_volume_creation(self):
return self._get_xmlobj().supports_volume_creation()
return self.get_xmlobj().supports_volume_creation()
def start(self):
self._backend.create(0)
@@ -212,18 +210,18 @@ class vmmStoragePool(vmmLibvirtObject):
#################
def get_type(self):
return self._get_xmlobj().type
return self.get_xmlobj().type
def get_uuid(self):
return self._get_xmlobj().uuid
return self.get_xmlobj().uuid
def get_target_path(self):
return self._get_xmlobj().target_path or ""
return self.get_xmlobj().target_path or ""
def get_allocation(self):
return self._get_xmlobj().allocation
return self.get_xmlobj().allocation
def get_available(self):
return self._get_xmlobj().available
return self.get_xmlobj().available
def get_capacity(self):
return self._get_xmlobj().capacity
return self.get_xmlobj().capacity
def get_pretty_allocation(self):
return util.pretty_bytes(self.get_allocation())