Commit 4dd4ec1c authored by Anael Beutot's avatar Anael Beutot
Browse files

VM tags new tag API.

parent b39958ea
Loading
Loading
Loading
Loading
+10 −1
Original line number Diff line number Diff line
@@ -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."""
+9 −4
Original line number Diff line number Diff line
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