Python libvirt 模块,VIR_DOMAIN_RUNNING 实例源码

我们从Python开源项目中,提取了以下7个代码示例,用于说明如何使用libvirt.VIR_DOMAIN_RUNNING

项目:paws    作者:rhpit    | 项目源码 | 文件源码
def __init__(self, args):
        self.args = args
        self.userdir = args.userdir
        self.resources = args.resources
        self.credentials = args.credentials
        self.resources_paws_file = args.resources_paws_file
        self.verbose = args.verbose

        self.util = Util(self)
        self.ansible = Ansible(self.userdir)

        self.resources_paws = None

        # Libvirt domain/VM states
        self.states = {
            libvirt.VIR_DOMAIN_NOSTATE: 'no state',
            libvirt.VIR_DOMAIN_RUNNING: 'running',
            libvirt.VIR_DOMAIN_BLOCKED: 'blocked on resource',
            libvirt.VIR_DOMAIN_PAUSED: 'paused by user',
            libvirt.VIR_DOMAIN_SHUTDOWN: 'being shut down',
            libvirt.VIR_DOMAIN_SHUTOFF: 'shut off',
            libvirt.VIR_DOMAIN_CRASHED: 'crashed',
        }
项目:convirt    作者:fromanirh    | 项目源码 | 文件源码
def test_info(self):
        info = self.dom.info()
        self.assertEquals(info[0],
                          libvirt.VIR_DOMAIN_RUNNING)
项目:convirt    作者:fromanirh    | 项目源码 | 文件源码
def info(self):
        # TODO: check all but the first value
        return [libvirt.VIR_DOMAIN_RUNNING, 0, 0, 1, 0]
项目:lib9    作者:Jumpscale    | 项目源码 | 文件源码
def create(self, id, xml):
        if self.isCurrentStorageAction(id):
            raise Exception("Can't start a locked machine")
        domain = self._get_domain(id)
        if not domain and xml:
            domain = self.connection.defineXML(xml)
        if domain.state(0)[0] == libvirt.VIR_DOMAIN_RUNNING:
            return True
        return domain.create() == 0
项目:lib9    作者:Jumpscale    | 项目源码 | 文件源码
def resume(self, id):
        domain = self._get_domain(id)
        if domain.state(0)[0] == libvirt.VIR_DOMAIN_RUNNING:
            return True
        return domain.resume() == 0
项目:lib9    作者:Jumpscale    | 项目源码 | 文件源码
def memory_usage(self):
        ids = self.readonly.listDomainsID()
        hostmem = self.readonly.getInfo()[1]
        totalmax = 0
        totalrunningmax = 0
        for id in ids:
            dom = self.readonly.lookupByID(id)
            machinestate, maxmem, mem = dom.info()[0:3]
            totalmax += maxmem / 1000
            if machinestate == libvirt.VIR_DOMAIN_RUNNING:
                totalrunningmax += maxmem / 1000
        return (hostmem, totalmax, totalrunningmax)
项目:JimV-N    作者:jamesiter    | 项目源码 | 文件源码
def guest_state_report(guest):

        try:
            _uuid = guest.UUIDString()
            state, maxmem, mem, ncpu, cputime = guest.info()
            # state ?????
            # http://libvirt.org/docs/libvirt-appdev-guide-python/en-US/html/libvirt_application_development_guide_using_python-Guest_Domains-Information-State.html
            # http://stackoverflow.com/questions/4986076/alternative-to-virsh-libvirt

            log = u' '.join([u'?', guest.name(), u', UUID', _uuid, u'??????'])

            if state == libvirt.VIR_DOMAIN_RUNNING:
                log += u' Running?'
                guest_event_emit.running(uuid=_uuid)

            elif state == libvirt.VIR_DOMAIN_BLOCKED:
                log += u' Blocked?'
                guest_event_emit.blocked(uuid=_uuid)

            elif state == libvirt.VIR_DOMAIN_PAUSED:
                log += u' Paused?'
                guest_event_emit.paused(uuid=_uuid)

            elif state == libvirt.VIR_DOMAIN_SHUTDOWN:
                log += u' Shutdown?'
                guest_event_emit.shutdown(uuid=_uuid)

            elif state == libvirt.VIR_DOMAIN_SHUTOFF:
                log += u' Shutoff?'
                guest_event_emit.shutoff(uuid=_uuid)

            elif state == libvirt.VIR_DOMAIN_CRASHED:
                log += u' Crashed?'
                guest_event_emit.crashed(uuid=_uuid)

            elif state == libvirt.VIR_DOMAIN_PMSUSPENDED:
                log += u' PM_Suspended?'
                guest_event_emit.pm_suspended(uuid=_uuid)

            else:
                log += u' NO_State?'

                guest_event_emit.no_state(uuid=_uuid)

            logger.info(log)
            log_emit.info(log)

        except Exception as e:
            logger.error(e.message)
            log_emit.error(e.message)