libvirtobject: Add is_X object type helpers

This commit is contained in:
Cole Robinson 2018-10-13 17:21:22 -04:00
parent d39b7d1079
commit 535e34481d
2 changed files with 31 additions and 21 deletions

View File

@ -671,11 +671,11 @@ class vmmConnection(vmmGObject):
return self._backend.interfaceDefineXML(xml, 0)
def rename_object(self, obj, origxml, newxml, oldconnkey):
if obj.class_name() == "domain":
if obj.is_domain():
define_cb = self.define_domain
elif obj.class_name() == "pool":
elif obj.is_pool():
define_cb = self.define_pool
elif obj.class_name() == "network":
elif obj.is_network():
define_cb = self.define_network
else:
raise RuntimeError("programming error: rename_object "
@ -708,7 +708,7 @@ class vmmConnection(vmmGObject):
# Reinsert handle into new obj
obj.change_name_backend(newobj)
if newobj and obj.class_name() == "domain":
if newobj and obj.is_domain():
self.emit("vm-renamed", oldconnkey, obj.get_connkey())
@ -1107,16 +1107,15 @@ class vmmConnection(vmmGObject):
#######################
def _remove_object_signal(self, obj):
class_name = obj.class_name()
if class_name == "domain":
if obj.is_domain():
self.emit("vm-removed", obj.get_connkey())
elif class_name == "network":
elif obj.is_network():
self.emit("net-removed", obj.get_connkey())
elif class_name == "pool":
elif obj.is_pool():
self.emit("pool-removed", obj.get_connkey())
elif class_name == "interface":
elif obj.is_interface():
self.emit("interface-removed", obj.get_connkey())
elif class_name == "nodedev":
elif obj.is_nodedev():
self.emit("nodedev-removed", obj.get_connkey())
def _gone_object_signals(self, gone_objects):
@ -1167,19 +1166,19 @@ class vmmConnection(vmmGObject):
class_name, obj.get_name())
return
if class_name != "nodedev":
if not obj.is_nodedev():
# Skip nodedev logging since it's noisy and not interesting
logging.debug("%s=%s status=%s added", class_name,
obj.get_name(), obj.run_status())
if class_name == "domain":
if obj.is_domain():
self.emit("vm-added", obj.get_connkey())
elif class_name == "network":
elif obj.is_network():
self.emit("net-added", obj.get_connkey())
elif class_name == "pool":
elif obj.is_pool():
self.emit("pool-added", obj.get_connkey())
elif class_name == "interface":
elif obj.is_interface():
self.emit("interface-added", obj.get_connkey())
elif class_name == "nodedev":
elif obj.is_nodedev():
self.emit("nodedev-added", obj.get_connkey())
finally:
if self._init_object_event:
@ -1323,15 +1322,15 @@ class vmmConnection(vmmGObject):
try:
if obj.reports_stats() and stats_update:
pass
elif obj.__class__ is vmmDomain and not pollvm:
elif obj.is_domain() and not pollvm:
continue
elif obj.__class__ is vmmNetwork and not pollnet:
elif obj.is_network() and not pollnet:
continue
elif obj.__class__ is vmmStoragePool and not pollpool:
elif obj.is_pool() and not pollpool:
continue
elif obj.__class__ is vmmInterface and not polliface:
elif obj.is_interface() and not polliface:
continue
elif obj.__class__ is vmmNodeDevice and not pollnodedev:
elif obj.is_nodedev() and not pollnodedev:
continue
obj.tick(stats_update=stats_update)

View File

@ -97,6 +97,17 @@ class vmmLibvirtObject(vmmGObject):
def get_connkey(self):
return self._key
def is_domain(self):
return self.class_name() == "domain"
def is_network(self):
return self.class_name() == "network"
def is_pool(self):
return self.class_name() == "pool"
def is_nodedev(self):
return self.class_name() == "nodedev"
def is_interface(self):
return self.class_name() == "interface"
def change_name_backend(self, newbackend):
# Used for changing the backing object after a rename
self._backend = newbackend