diff --git a/cloudcontrol/node/hypervisor/domains/__init__.py b/cloudcontrol/node/hypervisor/domains/__init__.py index fdbcb3fc1b1144b6f0f247f66b91b891205cbaca..b196d48a05b894e7b8a1c68f56c660254ac4fc56 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 83c4e362ec16adcd84c9a53e8cfbfaa0b18224f2..518c84786c524fe3846a0f138d5b600bdd263f62 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."""