From b044dd94c7965dc9901e9a2ba00d960d3a891d28 Mon Sep 17 00:00:00 2001 From: Cole Robinson Date: Sun, 7 Jul 2013 08:42:57 -0400 Subject: [PATCH] Various cleanup and sync between libvirtobject classes --- virtManager/connection.py | 6 +++- virtManager/createinterface.py | 2 +- virtManager/createvol.py | 6 ++-- virtManager/domain.py | 11 +++---- virtManager/host.py | 2 +- virtManager/interface.py | 34 +++++++++----------- virtManager/libvirtobject.py | 9 +++++- virtManager/network.py | 45 +++++++++++++------------- virtManager/nodedev.py | 12 +++---- virtManager/storagepool.py | 59 ++++++++++++++++------------------ virtManager/storagevol.py | 19 ++++++----- virtManager/util.py | 2 +- 12 files changed, 103 insertions(+), 104 deletions(-) diff --git a/virtManager/connection.py b/virtManager/connection.py index eda4d909..40930e20 100644 --- a/virtManager/connection.py +++ b/virtManager/connection.py @@ -752,8 +752,12 @@ class vmmConnection(vmmGObject): def define_domain(self, xml): return self._backend.defineXML(xml) + def define_network(self, xml): + return self._backend.networkDefineXML(xml) + def define_pool(self, xml): + return self._backend.storagePoolDefineXML(xml, 0) def define_interface(self, xml): - self._backend.interfaceDefineXML(xml, 0) + return self._backend.interfaceDefineXML(xml, 0) def restore(self, frm): self._backend.restore(frm) diff --git a/virtManager/createinterface.py b/virtManager/createinterface.py index a5537648..48cff084 100644 --- a/virtManager/createinterface.py +++ b/virtManager/createinterface.py @@ -517,7 +517,7 @@ class vmmCreateInterface(vmmGObjectUI): for name in self.conn.list_interface_names(): iface = self.conn.get_interface(name) - key = iface.interface + key = iface.get_backend() iface_type = iface.get_type() active = iface.is_active() name = iface.get_name() diff --git a/virtManager/createvol.py b/virtManager/createvol.py index 843b3e63..edde1957 100644 --- a/virtManager/createvol.py +++ b/virtManager/createvol.py @@ -111,8 +111,8 @@ class vmmCreateVolume(vmmGObjectUI): ret = "" try: ret = Storage.StorageVolume.find_free_name(self.name_hint, - pool_object=self.parent_pool.pool, - suffix=suffix) + pool_object=self.parent_pool.get_backend(), + suffix=suffix) ret = ret.rstrip(suffix) except: pass @@ -273,7 +273,7 @@ class vmmCreateVolume(vmmGObjectUI): name=volname, allocation=(alloc * 1024 * 1024), capacity=(cap * 1024 * 1024), - pool=self.parent_pool.pool) + pool=self.parent_pool.get_backend()) if fmt: self.vol.format = fmt except ValueError, e: diff --git a/virtManager/domain.py b/virtManager/domain.py index 8fa76b62..0b98ff02 100644 --- a/virtManager/domain.py +++ b/virtManager/domain.py @@ -152,11 +152,10 @@ class vmmDomain(vmmLibvirtObject): "pre-startup": (GObject.SignalFlags.RUN_FIRST, None, [object]), } - def __init__(self, conn, backend, uuid): - vmmLibvirtObject.__init__(self, conn) + def __init__(self, conn, backend, key): + vmmLibvirtObject.__init__(self, conn, backend, key) - self._backend = backend - self.uuid = uuid + self.uuid = key self.cloning = False self.record = [] @@ -1771,8 +1770,8 @@ class vmmDomainVirtinst(vmmDomain): Used for launching a details window for customizing a VM before install. """ - def __init__(self, conn, backend, uuid): - vmmDomain.__init__(self, conn, backend, uuid) + def __init__(self, conn, backend, key): + vmmDomain.__init__(self, conn, backend, key) self._orig_xml = None diff --git a/virtManager/host.py b/virtManager/host.py index 78cb5de0..3b713c8d 100644 --- a/virtManager/host.py +++ b/virtManager/host.py @@ -906,7 +906,7 @@ class vmmHost(vmmGObjectUI): def refresh_storage_pool(self, src_ignore, uuid): refresh_pool_in_list(self.widget("pool-list"), self.conn, uuid) curpool = self.current_pool() - if curpool.uuid != uuid: + if curpool.get_uuid() != uuid: return # Currently selected pool changed state: force a 'pool_selected' to diff --git a/virtManager/interface.py b/virtManager/interface.py index 96398509..bdae722e 100644 --- a/virtManager/interface.py +++ b/virtManager/interface.py @@ -25,19 +25,18 @@ from virtManager.libvirtobject import vmmLibvirtObject class vmmInterface(vmmLibvirtObject): - def __init__(self, conn, interface, name): - vmmLibvirtObject.__init__(self, conn) + def __init__(self, conn, backend, key): + vmmLibvirtObject.__init__(self, conn, backend, key) - self.interface = interface # Libvirt virInterface object - self.name = name # String name - self.active = True # bool indicating if it is running + self._name = key + self._active = True - self._xml = None # xml cache + self._xml = None self._xml_flags = None (self._inactive_xml_flags, self._active_xml_flags) = self.conn.get_interface_flags( - self.interface) + self._backend) self._support_isactive = None @@ -46,8 +45,7 @@ class vmmInterface(vmmLibvirtObject): # Routines from vmmLibvirtObject def _XMLDesc(self, flags): - return self.interface.XMLDesc(flags) - + return self._backend.XMLDesc(flags) def _define(self, xml): return self.conn.define_interface(xml) @@ -63,46 +61,46 @@ class vmmInterface(vmmLibvirtObject): return util.xpath(self.get_xml(inactive=True), *args, **kwargs) def set_active(self, state): - if state == self.active: + if state == self._active: return self.idle_emit(state and "started" or "stopped") - self.active = state + self._active = state self.refresh_xml() def _backend_get_active(self): ret = True if self._support_isactive is None: self._support_isactive = self.conn.check_interface_support( - self.interface, + self._backend, self.conn.SUPPORT_INTERFACE_ISACTIVE) if not self._support_isactive: return True - return bool(self.interface.isActive()) + return bool(self._backend.isActive()) def tick(self): self.set_active(self._backend_get_active()) def is_active(self): - return self.active + return self._active def get_name(self): - return self.name + return self._name def get_mac(self): return self.xpath("/interface/mac/@address") def start(self): - self.interface.create(0) + self._backend.create(0) self.idle_add(self.refresh_xml) def stop(self): - self.interface.destroy(0) + self._backend.destroy(0) self.idle_add(self.refresh_xml) def delete(self): - self.interface.undefine() + self._backend.undefine() def is_bridge(self): typ = self.get_type() diff --git a/virtManager/libvirtobject.py b/virtManager/libvirtobject.py index 0c5f0009..4e8fdb56 100644 --- a/virtManager/libvirtobject.py +++ b/virtManager/libvirtobject.py @@ -47,9 +47,11 @@ class vmmLibvirtObject(vmmGObject): "stopped": (GObject.SignalFlags.RUN_FIRST, None, []), } - def __init__(self, conn): + def __init__(self, conn, backend, key): vmmGObject.__init__(self) self._conn = conn + self._backend = backend + self._key = key self._xml = None self._is_xml_valid = False @@ -65,6 +67,11 @@ class vmmLibvirtObject(vmmGObject): return self._conn conn = property(_get_conn) + def get_backend(self): + return self._backend + def get_key(self): + return self._key + ############################################################# # Functions that should probably be overridden in sub class # ############################################################# diff --git a/virtManager/network.py b/virtManager/network.py index c9d5b4d7..547bc011 100644 --- a/virtManager/network.py +++ b/virtManager/network.py @@ -47,11 +47,10 @@ class vmmNetwork(vmmLibvirtObject): return desc - def __init__(self, conn, net, uuid): - vmmLibvirtObject.__init__(self, conn) - self.net = net - self.uuid = uuid - self.active = True + def __init__(self, conn, backend, key): + vmmLibvirtObject.__init__(self, conn, backend, key) + self._uuid = key + self._active = True self._support_isactive = None @@ -60,61 +59,61 @@ class vmmNetwork(vmmLibvirtObject): # Required class methods def get_name(self): - return self.net.name() + return self._backend.name() def _XMLDesc(self, flags): - return self.net.XMLDesc(flags) + return self._backend.XMLDesc(flags) def _define(self, xml): - return self.conn.get_backend().networkDefineXML(xml) + return self.conn.define_network(xml) - def set_active(self, state): - if state == self.active: + def _set_active(self, state): + if state == self._active: return self.idle_emit(state and "started" or "stopped") - self.active = state + self._active = state def is_active(self): - return self.active + return self._active def get_label(self): return self.get_name() def get_uuid(self): - return self.uuid + return self._uuid def get_bridge_device(self): try: - return self.net.bridgeName() + return self._backend.bridgeName() except: return "" def start(self): - self.net.create() + self._backend.create() def stop(self): - self.net.destroy() + self._backend.destroy() def delete(self): - self.net.undefine() - self.net = None + self._backend.undefine() + self._backend = None def set_autostart(self, value): - self.net.setAutostart(value) + self._backend.setAutostart(value) def get_autostart(self): - return self.net.autostart() + return self._backend.autostart() def _backend_get_active(self): if self._support_isactive is None: self._support_isactive = self.conn.check_net_support( - self.net, + self._backend, self.conn.SUPPORT_NET_ISACTIVE) if not self._support_isactive: return True - return bool(self.net.isActive()) + return bool(self._backend.isActive()) def tick(self): - self.set_active(self._backend_get_active()) + self._set_active(self._backend_get_active()) ######################## diff --git a/virtManager/nodedev.py b/virtManager/nodedev.py index 3e5726d3..9aa57e51 100644 --- a/virtManager/nodedev.py +++ b/virtManager/nodedev.py @@ -24,22 +24,18 @@ from virtManager.libvirtobject import vmmLibvirtObject class vmmNodeDevice(vmmLibvirtObject): - def __init__(self, conn, backend, name): - vmmLibvirtObject.__init__(self, conn) - - self.name = name - self._backend = backend + def __init__(self, conn, backend, key): + vmmLibvirtObject.__init__(self, conn, backend, key) + self._name = key self._virtinst_obj = None self.get_virtinst_obj() def _XMLDesc(self, flags): return self._backend.XMLDesc(flags) - def get_name(self): - return self.name - + return self._name def is_active(self): return True diff --git a/virtManager/storagepool.py b/virtManager/storagepool.py index 365d3fc5..e56ba6fb 100644 --- a/virtManager/storagepool.py +++ b/virtManager/storagepool.py @@ -34,16 +34,13 @@ class vmmStoragePool(vmmLibvirtObject): "refreshed": (GObject.SignalFlags.RUN_FIRST, None, []) } - def __init__(self, conn, pool, uuid): - vmmLibvirtObject.__init__(self, conn) + def __init__(self, conn, backend, key): + vmmLibvirtObject.__init__(self, conn, backend, key) - self.pool = pool # Libvirt pool object - self.uuid = uuid # String UUID - self.active = True # bool indicating if it is running - - self._volumes = {} # UUID->vmmStorageVolume mapping of the - # pools associated volumes + self._uuid = key + self._active = True + self._volumes = {} self._support_isactive = None self.tick() @@ -51,50 +48,50 @@ class vmmStoragePool(vmmLibvirtObject): # Required class methods def get_name(self): - return self.pool.name() + return self._backend.name() def _XMLDesc(self, flags): - return self.pool.XMLDesc(flags) + return self._backend.XMLDesc(flags) def _define(self, xml): - return self.conn.get_backend().storagePoolDefineXML(xml, 0) + return self.conn.define_pool(xml) - def set_active(self, state): - if state == self.active: + def _set_active(self, state): + if state == self._active: return self.idle_emit(state and "started" or "stopped") - self.active = state + self._active = state self.refresh_xml() def is_active(self): - return self.active + return self._active def can_change_alloc(self): typ = self.get_type() return (typ in [virtinst.Storage.StoragePool.TYPE_LOGICAL]) def get_uuid(self): - return self.uuid + return self._uuid def start(self): - self.pool.create(0) + self._backend.create(0) self.idle_add(self.refresh_xml) def stop(self): - self.pool.destroy() + self._backend.destroy() self.idle_add(self.refresh_xml) def delete(self, nodelete=True): if nodelete: - self.pool.undefine() + self._backend.undefine() else: - self.pool.delete(0) - del(self.pool) + self._backend.delete(0) + self._backend = None def set_autostart(self, value): - self.pool.setAutostart(value) + self._backend.setAutostart(value) def get_autostart(self): - return self.pool.autostart() + return self._backend.autostart() def get_target_path(self): return util.xpath(self.get_xml(), "/pool/target/path") or "" @@ -126,18 +123,18 @@ class vmmStoragePool(vmmLibvirtObject): def _backend_get_active(self): if self._support_isactive is None: self._support_isactive = self.conn.check_pool_support( - self.pool, + self._backend, self.conn.SUPPORT_STORAGE_ISACTIVE) if not self._support_isactive: return True - return bool(self.pool.isActive()) + return bool(self._backend.isActive()) def tick(self): - self.set_active(self._backend_get_active()) + self._set_active(self._backend_get_active()) def refresh(self): - if not self.active: + if not self.is_active(): return def cb(): @@ -145,7 +142,7 @@ class vmmStoragePool(vmmLibvirtObject): self.update_volumes(refresh=True) self.emit("refreshed") - self.pool.refresh(0) + self._backend.refresh(0) self.idle_add(cb) def update_volumes(self, refresh=False): @@ -153,7 +150,7 @@ class vmmStoragePool(vmmLibvirtObject): self._volumes = {} return - vols = self.pool.listVolumes() + vols = self._backend.listVolumes() new_vol_list = {} for volname in vols: @@ -163,6 +160,6 @@ class vmmStoragePool(vmmLibvirtObject): new_vol_list[volname].refresh_xml() else: new_vol_list[volname] = vmmStorageVolume(self.conn, - self.pool.storageVolLookupByName(volname), - volname) + self._backend.storageVolLookupByName(volname), + volname) self._volumes = new_vol_list diff --git a/virtManager/storagevol.py b/virtManager/storagevol.py index 2a0c5789..0746557f 100644 --- a/virtManager/storagevol.py +++ b/virtManager/storagevol.py @@ -23,28 +23,27 @@ from virtManager.libvirtobject import vmmLibvirtObject class vmmStorageVolume(vmmLibvirtObject): - def __init__(self, conn, vol, name): - vmmLibvirtObject.__init__(self, conn) + def __init__(self, conn, backend, key): + vmmLibvirtObject.__init__(self, conn, backend, key) - self.vol = vol # Libvirt storage volume object - self.name = name + self._name = key # Required class methods def get_name(self): - return self.name + return self._name def _XMLDesc(self, flags): - return self.vol.XMLDesc(flags) + return self._backend.XMLDesc(flags) def get_path(self): - return self.vol.path() + return self._backend.path() def get_pool(self): - pobj = self.vol.storagePoolLookupByVolume() + pobj = self._backend.storagePoolLookupByVolume() return self.conn.get_pool_by_name(pobj.name()) def delete(self): - self.vol.delete(0) - del(self.vol) + self._backend.delete(0) + self._backend = None def get_target_path(self): return util.xpath(self.get_xml(), "/volume/target/path") diff --git a/virtManager/util.py b/virtManager/util.py index 3961e0d1..15fc6005 100644 --- a/virtManager/util.py +++ b/virtManager/util.py @@ -136,7 +136,7 @@ def get_default_path(conn, name, collidelist=None): newcollidelist.append(os.path.basename(c)) path = virtinst.Storage.StorageVolume.find_free_name(name, - pool_object=pool.pool, suffix=suffix, + pool_object=pool.get_backend(), suffix=suffix, collidelist=newcollidelist) path = os.path.join(target, path)