Various cleanup and sync between libvirtobject classes
This commit is contained in:
parent
ed5e67485c
commit
b044dd94c7
|
@ -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)
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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 #
|
||||
#############################################################
|
||||
|
|
|
@ -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())
|
||||
|
||||
|
||||
########################
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue