Python libvirt.VIR_DOMAIN_PAUSED Examples

The following are 8 code examples of libvirt.VIR_DOMAIN_PAUSED(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module libvirt , or try the search function .
Example #1
Source File: migrate.py    From libvirt-test-API with GNU General Public License v2.0 6 votes vote down vote up
def get_state(state):
    dom_state = ''
    if state == libvirt.VIR_DOMAIN_NOSTATE:
        dom_state = 'nostate'
    elif state == libvirt.VIR_DOMAIN_RUNNING:
        dom_state = 'running'
    elif state == libvirt.VIR_DOMAIN_BLOCKED:
        dom_state = 'blocked'
    elif state == libvirt.VIR_DOMAIN_PAUSED:
        dom_state = 'paused'
    elif state == libvirt.VIR_DOMAIN_SHUTDOWN:
        dom_state = 'shutdown'
    elif state == libvirt.VIR_DOMAIN_SHUTOFF:
        dom_state = 'shutoff'
    elif state == libvirt.VIR_DOMAIN_CRASHED:
        dom_state = 'crashed'
    else:
        dom_state = 'no sure'
    return dom_state 
Example #2
Source File: migrate_tls.py    From libvirt-test-API with GNU General Public License v2.0 6 votes vote down vote up
def get_state(state):
    dom_state = ''
    if state == libvirt.VIR_DOMAIN_NOSTATE:
        dom_state = 'nostate'
    elif state == libvirt.VIR_DOMAIN_RUNNING:
        dom_state = 'running'
    elif state == libvirt.VIR_DOMAIN_BLOCKED:
        dom_state = 'blocked'
    elif state == libvirt.VIR_DOMAIN_PAUSED:
        dom_state = 'paused'
    elif state == libvirt.VIR_DOMAIN_SHUTDOWN:
        dom_state = 'shutdown'
    elif state == libvirt.VIR_DOMAIN_SHUTOFF:
        dom_state = 'shutoff'
    elif state == libvirt.VIR_DOMAIN_CRASHED:
        dom_state = 'crashed'
    else:
        dom_state = 'no sure'
    return dom_state 
Example #3
Source File: managedsave_define_xml.py    From libvirt-test-API with GNU General Public License v2.0 5 votes vote down vote up
def check_dom_state(domobj):
    state = domobj.info()[0]
    expect_states = [libvirt.VIR_DOMAIN_PAUSED, libvirt.VIR_DOMAIN_RUNNING]
    if state in expect_states:
        return state
    return 0 
Example #4
Source File: snapshot_revert.py    From libvirt-test-API with GNU General Public License v2.0 5 votes vote down vote up
def check_domain_state(*args):
    """ check if the domain state after revert """

    (flagn, domobj, snapshot) = args
    state = domobj.info()[0]

    if snapshot.isCurrent(0):
        logger.info("Successfull revert to given snapshotname")

        # The passed flags include "running"
        if (flagn == 1) or (flagn == 5):
            logger.info("After reverting, change state to running")
            expect_states = [libvirt.VIR_DOMAIN_RUNNING,
                             libvirt.VIR_DOMAIN_RUNNING_FROM_SNAPSHOT,
                             libvirt.VIR_DOMAIN_RUNNING_BOOTED]
            if state in expect_states:
                logger.info("Successful revert.The domain state is running.")
                return True
            else:
                logger.error("Failed to revert.The domain state isn't running")
                return False
        # The passed flags include "paused"
        elif (flagn == 2) or (flagn == 6):
            expect_states = [libvirt.VIR_DOMAIN_PAUSED,
                             libvirt.VIR_DOMAIN_PAUSED_FROM_SNAPSHOT,
                             libvirt.VIR_DOMAIN_PAUSED_SNAPSHOT]
            if state in expect_states:
                logger.info("Successful revert.The domain state is paused.")
                return True
            else:
                logger.error("Failed to revert.The domain state isn't paused")
                return False
    else:
        logger.error("Failed to revert to given snapshotname ")
        return False 
Example #5
Source File: domain_common.py    From libvirt-test-API with GNU General Public License v2.0 5 votes vote down vote up
def check_dom_state(domobj):
    state = domobj.info()[0]
    expect_states = [libvirt.VIR_DOMAIN_PAUSED, libvirt.VIR_DOMAIN_RUNNING]
    if state in expect_states:
        return state
    return -1 
Example #6
Source File: host_thread.py    From openmano with Apache License 2.0 4 votes vote down vote up
def update_servers_status(self):
                            # # virDomainState
                            # VIR_DOMAIN_NOSTATE = 0
                            # VIR_DOMAIN_RUNNING = 1
                            # VIR_DOMAIN_BLOCKED = 2
                            # VIR_DOMAIN_PAUSED = 3
                            # VIR_DOMAIN_SHUTDOWN = 4
                            # VIR_DOMAIN_SHUTOFF = 5
                            # VIR_DOMAIN_CRASHED = 6
                            # VIR_DOMAIN_PMSUSPENDED = 7   #TODO suspended
    
        if self.test or len(self.server_status)==0:
            return            
        
        try:
            conn = libvirt.open("qemu+ssh://"+self.user+"@"+self.host+"/system")
            domains=  conn.listAllDomains() 
            domain_dict={}
            for domain in domains:
                uuid = domain.UUIDString() ;
                libvirt_status = domain.state()
                #print libvirt_status
                if libvirt_status[0] == libvirt.VIR_DOMAIN_RUNNING or libvirt_status[0] == libvirt.VIR_DOMAIN_SHUTDOWN:
                    new_status = "ACTIVE"
                elif libvirt_status[0] == libvirt.VIR_DOMAIN_PAUSED:
                    new_status = "PAUSED"
                elif libvirt_status[0] == libvirt.VIR_DOMAIN_SHUTOFF:
                    new_status = "INACTIVE"
                elif libvirt_status[0] == libvirt.VIR_DOMAIN_CRASHED:
                    new_status = "ERROR"
                else:
                    new_status = None
                domain_dict[uuid] = new_status
            conn.close
        except libvirt.libvirtError as e:
            print self.name, ": get_state() Exception '", e.get_error_message()
            return

        for server_id, current_status in self.server_status.iteritems():
            new_status = None
            if server_id in domain_dict:
                new_status = domain_dict[server_id]
            else:
                new_status = "INACTIVE"
                            
            if new_status == None or new_status == current_status:
                continue
            if new_status == 'INACTIVE' and current_status == 'ERROR':
                continue #keep ERROR status, because obviously this machine is not running
            #change status
            print self.name, ": server ", server_id, "status change from ", current_status, "to", new_status
            STATUS={'progress':100, 'status':new_status}
            if new_status == 'ERROR':
                STATUS['last_error'] = 'machine has crashed'
            self.db_lock.acquire()
            r,_ = self.db.update_rows('instances', STATUS, {'uuid':server_id}, log=False)
            self.db_lock.release()
            if r>=0:
                self.server_status[server_id] = new_status 
Example #7
Source File: suspend.py    From libvirt-test-API with GNU General Public License v2.0 4 votes vote down vote up
def suspend(params):
    """Suspend domain

        Argument is a dictionary with two keys:
        {'logger': logger, 'guestname': guestname}

        logger -- an object of utils/log.py
        guestname -- same as the domain name

        Return 0 on SUCCESS or 1 on FAILURE
    """
    domname = params['guestname']
    logger = params['logger']

    conn = sharedmod.libvirtobj['conn']

    domobj = conn.lookupByName(domname)

    # Suspend domain
    logger.info('suspend domain')
    try:
        domobj.suspend()
    except libvirtError as e:
        logger.error("API error message: %s, error code is %s"
                     % (e.get_error_message(), e.get_error_code()))
        return 1
    time.sleep(1)
    state = domobj.info()[0]

    if state != libvirt.VIR_DOMAIN_PAUSED:
        logger.error('The domain state is not equal to "paused"')
        return 1

    mac = utils.get_dom_mac_addr(domname)

    time.sleep(3)
    logger.info("get ip by mac address")
    ip = utils.mac_to_ip(mac, 10)

    time.sleep(10)

    logger.info('ping guest')
    if utils.do_ping(ip, 20):
        logger.error('The guest is still active, IP: ' + str(ip))
        return 1

    logger.info('PASS')
    return 0 
Example #8
Source File: handoff.py    From elijah-provisioning with Apache License 2.0 4 votes vote down vote up
def get_monitoring_info(self):
        """return montioring information including
        1) base vm hash list
        2) used/freed disk block list
        3) freed memory page
        """
        time1 = time.time()
        # do not pause VM since we're doing semi-live migration
        # this will be done by qmp
        # if self.machine is not None:
        #    vm_state, reason = self.machine.state(0)
        #    if vm_state != libvirt.VIR_DOMAIN_PAUSED:
        #        self.machine.suspend()

        time2 = time.time()
        # 2. get dma & discard information
        if self.options.TRIM_SUPPORT:
            dma_dict, trim_dict = disk.parse_qemu_log(
                self.qemu_logfile, Const.CHUNK_SIZE)
            if len(trim_dict) == 0:
                LOG.warning("No TRIM Discard, Check /etc/fstab configuration")
        else:
            trim_dict = dict()
        free_memory_dict = dict()
        time3 = time.time()
        # 3. get used sector information from x-ray
        used_blocks_dict = None
        if self.options.XRAY_SUPPORT:
            import xray
            used_blocks_dict = xray.get_used_blocks(modified_disk)

        info_dict = dict()
        info_dict[_MonitoringInfo.DISK_USED_BLOCKS] = used_blocks_dict
        info_dict[_MonitoringInfo.DISK_FREE_BLOCKS] = trim_dict
        info_dict[_MonitoringInfo.MEMORY_FREE_BLOCKS] = free_memory_dict

        time4 = time.time()
        # mark the modifid disk area at original VM overlay as modified
        if self.dirty_disk_chunks is not None:
            for dirty_chunk in self.dirty_disk_chunks:
                self.modified_disk_queue.put((dirty_chunk, 1.0))
        info_dict[
            _MonitoringInfo.DISK_MODIFIED_BLOCKS] = self.modified_disk_queue
        time5 = time.time()

        LOG.debug(
            "consumed time %f, %f, %f, %f" %
            ((time5-time4), (time4-time3), (time3-time2), (time2-time1)))

        self.monitoring_info = _MonitoringInfo(info_dict)
        return self.monitoring_info