Python libvirt 模块,VIR_DOMAIN_CRASHED 实例源码

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

项目: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',
        }
项目:lib9    作者:Jumpscale    | 项目源码 | 文件源码
def shutdown(self, id):
        if self.isCurrentStorageAction(id):
            raise Exception("Can't stop a locked machine")
        domain = self._get_domain(id)
        if domain.state(0)[0] in [libvirt.VIR_DOMAIN_SHUTDOWN, libvirt.VIR_DOMAIN_SHUTOFF, libvirt.VIR_DOMAIN_CRASHED]:
            return True
        return domain.shutdown() == 0
项目:lib9    作者:Jumpscale    | 项目源码 | 文件源码
def isCurrentStorageAction(self, domainid):
        domain = self._get_domain(domainid)
        if not domain:
            return False
        # at this moment we suppose the machine is following the default naming
        # of disks
        if domain.state()[0] not in [libvirt.VIR_DOMAIN_SHUTDOWN,
                                     libvirt.VIR_DOMAIN_SHUTOFF, libvirt.VIR_DOMAIN_CRASHED]:
            status = domain.blockJobInfo('vda', 0)
            if 'cur' in status:
                return True
        # check also that there is no qemu-img job running
        if self.isLocked(domainid):
            return True
        return False
项目:lib9    作者:Jumpscale    | 项目源码 | 文件源码
def _clone(self, id, name, clonefrom):
        domain = self.connection.lookupByUUIDString(id)
        domainconfig = domain.XMLDesc()
        name = '%s_%s.qcow2' % (name, time.time())
        destination_path = os.path.join(self.templatepath, name)
        if domain.state()[0] in [
                libvirt.VIR_DOMAIN_SHUTDOWN,
                libvirt.VIR_DOMAIN_SHUTOFF,
                libvirt.VIR_DOMAIN_CRASHED,
                libvirt.VIR_DOMAIN_PAUSED] or not self._isRootVolume(
                domain,
                clonefrom):
            if not self.isLocked(id):
                lock = self._lockDomain(id)
                if lock != LOCKCREATED:
                    raise Exception('Failed to create lock: %s' % str(lock))
            else:
                raise Exception("Can't perform this action on a locked domain")
            q2 = Qcow2(clonefrom)
            try:
                q2.export(destination_path)
            finally:
                if self.isLocked(id):
                    self._unlockDomain(id)
        else:
            domain.undefine()
            try:
                domain.blockRebase(clonefrom, destination_path,
                                   0, libvirt.VIR_DOMAIN_BLOCK_REBASE_COPY)
                rebasedone = False
                while not rebasedone:
                    rebasedone = self._block_job_info(domain, clonefrom)
                domain.blockJobAbort(clonefrom, 0)
            except BaseException:
                self.connection.defineXML(domainconfig)
                raise
            self.connection.defineXML(domainconfig)
        return destination_path
项目: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)