Skip to content
__init__.py 1.18 KiB
Newer Older
Anael Beutot's avatar
Anael Beutot committed
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
Anael Beutot's avatar
Anael Beutot committed
from ccnode.hypervisor.domains import vm_tags


logger = logging.getLogger(__name__)


class VirtualMachine(object):
    """Represent a VM instance."""
Anael Beutot's avatar
Anael Beutot committed
    def __init__(self, dom, hypervisor):
        """
        :param dom: libvirt domain instance
Anael Beutot's avatar
Anael Beutot committed
        :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
Anael Beutot's avatar
Anael Beutot committed
        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):
Anael Beutot's avatar
Anael Beutot committed
        return self.lv_dom.name()

    @property
    def lv_dom(self):
        """Libvirt domain instance."""
        return _libvirt.connection.lookupByUUIDString(self.uuid)

    def start():
        pass

    def stop():
        pass

    def pause():
        pass

    def define():
        pass

    def undefined():
        pass