Loading ccnode/hypervisor/__init__.py +2 −2 Original line number Diff line number Diff line Loading @@ -105,11 +105,11 @@ class Hypervisor(object): # find defined domains for dom_name in _libvirt.connection.listDefinedDomains(): dom = _libvirt.connection.lookupByName(dom_name) self.domains[dom.UUID()] = VirtualMachine(dom) self.domains[dom.UUID()] = VirtualMachine(dom, self) # find started domains for dom_id in _libvirt.connection.listDomainsID(): dom = _libvirt.connection.lookupByID(dom_id) self.domains[dom.UUID()] = VirtualMachine(dom) self.domains[dom.UUID()] = VirtualMachine(dom, self) logger.debug('Domains: %s', self.domains) Loading ccnode/hypervisor/domains/__init__.py +20 −6 Original line number Diff line number Diff line from ccnode.tags import Tag import logging import weakref from ccnode.tags import tag_inspector from ccnode.hypervisor import lib as _libvirt from ccnode.hypervisor.lib import DOMAIN_STATES as STATE from ccnode.hypervisor.domains import vm_tags logger = logging.getLogger(__name__) class VirtualMachine(object): """Represent a VM instance.""" def __init__(self, dom): def __init__(self, dom, hypervisor): """ :param dom: libvirt domain instance :param hypervisor: hypervisor where the VM is """ #: UUID string of domain self.uuid = dom.UUIDString() #: state of VM: started, stoped, paused self.state = STATE[dom.info()[0]] #: tags for this VM self.tags = dict( test=Tag('test', 'plop'), ) self.tags = dict((t.name, t) for t in tag_inspector(vm_tags, self)) logger.debug(self.tags) self.hypervisor = weakref.proxy(hypervisor) @property def name(self): return _libvirt.connection.lookupByUUIDString(self.uuid).name() return self.lv_dom.name() @property def lv_dom(self): """Libvirt domain instance.""" return _libvirt.connection.lookupByUUIDString(self.uuid) def start(): pass Loading ccnode/hypervisor/domains/vm_tags.py 0 → 100644 +92 −0 Original line number Diff line number Diff line from xml.etree import cElementTree as et from StringIO import StringIO from ccnode.tags import DynamicTags def uuid(dom): """Unique identifier of the domain.""" return dom.uuid def status(dom): return dom.state def hv(dom): #FIXME: what shoud be the value of this tag ? return dom.hypervisor.name def htype(dom): return dom.hypervisor.type def arch(dom): """VM CPU architecture.""" try: return dict(i686='x86', x86_64='x64')[et.ElementTree().parse( StringIO(dom.lv_dom.XMLDesc(0))).find('os/type').get('arch')] except Exception: logger.exception('Error while get Architecture tag') def h(): pass def cpu(dom): """Number of CPU of the VM.""" return dom.lv_dom.info()[3] def cpuuse(): pass def mem(dom): """Memory currently allocated.""" return dom.lv_dom.info()[2] * 1024 def memmax(dom): """Maximum memory allocation.""" return dom.lv_dom.info()[1] * 1024 def vncport(dom): """VNC port for the VM console access.""" try: return et.ElementTree().parse( StringIO(dom.lv_dom.XMLDesc(0)) ).find('devices/graphics').get('port') except Exception: logger.exception('VNCPort') def status(dom): return dom.state status.ttl = 1 def disk(dom): """Get backend disks.""" try: return et.ElementTree().parse( StringIO(dom.lv_dom.XMLDesc(0)) ).find('devices/disk').get('port') except Exception: logger.exception('VNCPort') class Disks(DynamicTags): def __init__(self): for d in et.ElementTree().parse( StringIO(dom.lv_dom.XMLDesc(0)) ).findall('devices/disk'): # self.disks[] = plop pass def nic_(): pass Loading
ccnode/hypervisor/__init__.py +2 −2 Original line number Diff line number Diff line Loading @@ -105,11 +105,11 @@ class Hypervisor(object): # find defined domains for dom_name in _libvirt.connection.listDefinedDomains(): dom = _libvirt.connection.lookupByName(dom_name) self.domains[dom.UUID()] = VirtualMachine(dom) self.domains[dom.UUID()] = VirtualMachine(dom, self) # find started domains for dom_id in _libvirt.connection.listDomainsID(): dom = _libvirt.connection.lookupByID(dom_id) self.domains[dom.UUID()] = VirtualMachine(dom) self.domains[dom.UUID()] = VirtualMachine(dom, self) logger.debug('Domains: %s', self.domains) Loading
ccnode/hypervisor/domains/__init__.py +20 −6 Original line number Diff line number Diff line from ccnode.tags import Tag import logging import weakref from ccnode.tags import tag_inspector from ccnode.hypervisor import lib as _libvirt from ccnode.hypervisor.lib import DOMAIN_STATES as STATE from ccnode.hypervisor.domains import vm_tags logger = logging.getLogger(__name__) class VirtualMachine(object): """Represent a VM instance.""" def __init__(self, dom): def __init__(self, dom, hypervisor): """ :param dom: libvirt domain instance :param hypervisor: hypervisor where the VM is """ #: UUID string of domain self.uuid = dom.UUIDString() #: state of VM: started, stoped, paused self.state = STATE[dom.info()[0]] #: tags for this VM self.tags = dict( test=Tag('test', 'plop'), ) self.tags = dict((t.name, t) for t in tag_inspector(vm_tags, self)) logger.debug(self.tags) self.hypervisor = weakref.proxy(hypervisor) @property def name(self): return _libvirt.connection.lookupByUUIDString(self.uuid).name() return self.lv_dom.name() @property def lv_dom(self): """Libvirt domain instance.""" return _libvirt.connection.lookupByUUIDString(self.uuid) def start(): pass Loading
ccnode/hypervisor/domains/vm_tags.py 0 → 100644 +92 −0 Original line number Diff line number Diff line from xml.etree import cElementTree as et from StringIO import StringIO from ccnode.tags import DynamicTags def uuid(dom): """Unique identifier of the domain.""" return dom.uuid def status(dom): return dom.state def hv(dom): #FIXME: what shoud be the value of this tag ? return dom.hypervisor.name def htype(dom): return dom.hypervisor.type def arch(dom): """VM CPU architecture.""" try: return dict(i686='x86', x86_64='x64')[et.ElementTree().parse( StringIO(dom.lv_dom.XMLDesc(0))).find('os/type').get('arch')] except Exception: logger.exception('Error while get Architecture tag') def h(): pass def cpu(dom): """Number of CPU of the VM.""" return dom.lv_dom.info()[3] def cpuuse(): pass def mem(dom): """Memory currently allocated.""" return dom.lv_dom.info()[2] * 1024 def memmax(dom): """Maximum memory allocation.""" return dom.lv_dom.info()[1] * 1024 def vncport(dom): """VNC port for the VM console access.""" try: return et.ElementTree().parse( StringIO(dom.lv_dom.XMLDesc(0)) ).find('devices/graphics').get('port') except Exception: logger.exception('VNCPort') def status(dom): return dom.state status.ttl = 1 def disk(dom): """Get backend disks.""" try: return et.ElementTree().parse( StringIO(dom.lv_dom.XMLDesc(0)) ).find('devices/disk').get('port') except Exception: logger.exception('VNCPort') class Disks(DynamicTags): def __init__(self): for d in et.ElementTree().parse( StringIO(dom.lv_dom.XMLDesc(0)) ).findall('devices/disk'): # self.disks[] = plop pass def nic_(): pass