From 4de1b5cbb1182860c58daee56b389725bf61a81e Mon Sep 17 00:00:00 2001 From: Antoine Millet Date: Mon, 8 Jun 2015 14:49:59 +0200 Subject: [PATCH] Implemented titles on VMs --- cloudcontrol/node/hypervisor/domains/__init__.py | 9 +++++++++ cloudcontrol/node/hypervisor/domains/vm_tags.py | 8 ++++++++ 2 files changed, 17 insertions(+) diff --git a/cloudcontrol/node/hypervisor/domains/__init__.py b/cloudcontrol/node/hypervisor/domains/__init__.py index fdbcb3f..b196d48 100644 --- a/cloudcontrol/node/hypervisor/domains/__init__.py +++ b/cloudcontrol/node/hypervisor/domains/__init__.py @@ -61,6 +61,15 @@ class VirtualMachine(object): #: UUID string of domain self.uuid = dom.UUIDString() self.name = dom.name() + + # Get title of VM + try: + self.title = dom.metadata(libvirt.VIR_DOMAIN_METADATA_TITLE, None) + except (libvirt.libvirtError, AttributeError): + # libvirtError handle the case where the title is not defined on the + # vm, AttributeError handle the case where the libvirt is too old + # to allow metadata handling + self.title = None #: state of VM: started, stoped, paused self._state = STATE[dom.info()[0]] #: tags for this VM diff --git a/cloudcontrol/node/hypervisor/domains/vm_tags.py b/cloudcontrol/node/hypervisor/domains/vm_tags.py index 83c4e36..518c847 100644 --- a/cloudcontrol/node/hypervisor/domains/vm_tags.py +++ b/cloudcontrol/node/hypervisor/domains/vm_tags.py @@ -83,6 +83,14 @@ def h(dom): return dom.name +def t(dom): + """Title of the VM (or name if title is not defined).""" + if dom.title is None: + return dom.name + else: + return dom.title + + @_vir_tag def cpu(dom): """Number of CPU of the VM.""" -- GitLab