Newer
Older
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."""
"""
:param dom: libvirt domain instance
"""
#: 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((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 self.lv_dom.name()
@property
def lv_dom(self):
"""Libvirt domain instance."""
return _libvirt.connection.lookupByUUIDString(self.uuid)