From 4dd4ec1cfb97f4cca758efd9ca4edbc6a3e17ef9 Mon Sep 17 00:00:00 2001 From: Anael Beutot Date: Fri, 4 May 2012 17:53:29 +0200 Subject: [PATCH] VM tags new tag API. --- ccnode/hypervisor/domains/__init__.py | 11 ++++++++++- ccnode/hypervisor/domains/vm_tags.py | 13 +++++++++---- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/ccnode/hypervisor/domains/__init__.py b/ccnode/hypervisor/domains/__init__.py index 759f112..a90856d 100644 --- a/ccnode/hypervisor/domains/__init__.py +++ b/ccnode/hypervisor/domains/__init__.py @@ -29,7 +29,7 @@ class VirtualMachine(object): self.uuid = dom.UUIDString() self.name = dom.name() #: state of VM: started, stoped, paused - self.state = STATE[dom.info()[0]] + self._state = STATE[dom.info()[0]] #: tags for this VM self.tags = dict((t.name, t) for t in tag_inspector(vm_tags, self)) # define dynamic tags @@ -55,6 +55,15 @@ class VirtualMachine(object): logger.debug('Virtual Machine tags: %s', self.tags) + @property + def state(self): + return self._state + + @state.setter + def state(self, value): + self._state = value + self.tags['status'].value = value + @property def lv_dom(self): """Libvirt domain instance.""" diff --git a/ccnode/hypervisor/domains/vm_tags.py b/ccnode/hypervisor/domains/vm_tags.py index 25d90ce..a89ce4d 100644 --- a/ccnode/hypervisor/domains/vm_tags.py +++ b/ccnode/hypervisor/domains/vm_tags.py @@ -1,15 +1,17 @@ from xml.etree import cElementTree as et from StringIO import StringIO +from ccnode.tags import ttl, refresh + def uuid(dom): """Unique identifier of the domain.""" return dom.uuid +@ttl(5) def status(dom): return dom.state -status.ttl = 5 def hv(dom): @@ -40,9 +42,10 @@ def cpu(dom): return dom.lv_dom.info()[3] +@ttl(10) +@refresh(5) def cpuuse(): pass -cpuuse.ttl = 10 def mem(dom): @@ -65,13 +68,15 @@ def vncport(dom): logger.exception('VNCPort') +@ttl(10) +@refresh(10) def disk(dom): """Get backend disks.""" return u' '.join(map(str, xrange(len(dom.disks)))) or None -disk.ttl = 10 +@ttl(10) +@refresh(10) def nic(dom): """VM network interfaces.""" return u' '.join(map(str, xrange(len(dom.nics)))) or None -disk.nic = 10 -- GitLab