本文整理汇总了Python中libvirt.VIR_DOMAIN_RUNNING属性的典型用法代码示例。如果您正苦于以下问题:Python libvirt.VIR_DOMAIN_RUNNING属性的具体用法?Python libvirt.VIR_DOMAIN_RUNNING怎么用?Python libvirt.VIR_DOMAIN_RUNNING使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类libvirt
的用法示例。
在下文中一共展示了libvirt.VIR_DOMAIN_RUNNING属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_xml_with_files_clean
# 需要导入模块: import libvirt [as 别名]
# 或者: from libvirt import VIR_DOMAIN_RUNNING [as 别名]
def create_xml_with_files_clean(params):
logger = params['logger']
guestname = params['guestname']
for i in range(len(files)):
ret = utils.del_file("/tmp/libvirt-test-api-create-file-%d" % i, logger)
ret = utils.del_file("/tmp/libvirt_passfile_check", logger)
conn = libvirt.open("lxc:///")
dom = conn.lookupByName(guestname)
guest_state = dom.info()[0]
if guest_state == libvirt.VIR_DOMAIN_RUNNING:
logger.debug("destroy guest: %s." % guestname)
time.sleep(5)
dom.destroyFlags()
define_list = conn.listDefinedDomains()
if guestname in define_list:
time.sleep(3)
dom.undefine()
time.sleep(3)
elif guest_state == libvirt.VIR_DOMAIN_SHUTOFF:
time.sleep(5)
dom.undefine()
time.sleep(3)
示例2: create_with_files_clean
# 需要导入模块: import libvirt [as 别名]
# 或者: from libvirt import VIR_DOMAIN_RUNNING [as 别名]
def create_with_files_clean(params):
logger = params['logger']
for i in range(len(files)):
ret = utils.del_file("/tmp/libvirt-test-api-create-file-%d" % i, logger)
ret = utils.del_file("/tmp/libvirt_passfile_check", logger)
conn = libvirt.open("lxc:///")
dom = conn.lookupByName(guestname)
guest_state = dom.info()[0]
if guest_state == libvirt.VIR_DOMAIN_RUNNING:
logger.debug("destroy guest: %s." % guestname)
time.sleep(5)
dom.destroyFlags()
define_list = conn.listDefinedDomains()
if guestname in define_list:
time.sleep(3)
dom.undefine()
time.sleep(3)
elif guest_state == libvirt.VIR_DOMAIN_SHUTOFF:
time.sleep(5)
dom.undefine()
time.sleep(3)
示例3: get_state
# 需要导入模块: import libvirt [as 别名]
# 或者: from libvirt import VIR_DOMAIN_RUNNING [as 别名]
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
示例4: test_create_vm_overlay
# 需要导入模块: import libvirt [as 别名]
# 或者: from libvirt import VIR_DOMAIN_RUNNING [as 别名]
def test_create_vm_overlay(self):
disk_path=self.base_vm_path
dbconn, matching_basevm = PackagingUtil._get_matching_basevm(disk_path)
base_diskpath = matching_basevm.disk_path
options = Options()
options.TRIM_SUPPORT = True
options.ZIP_CONTAINER = True
options.FREE_SUPPORT = False
options.DISK_ONLY = False
try:
vm_overlay = synthesis.VM_Overlay(base_diskpath, options)
machine = vm_overlay.resume_basevm()
VM_status = VMUtility.get_VM_status(machine)
self.assertEqual(VM_status, libvirt.VIR_DOMAIN_RUNNING)
# wait for VM running
time.sleep(10)
vm_overlay.create_overlay()
self.overlay_filepath = vm_overlay.overlay_zipfile
self.assertTrue(os.path.exists(self.overlay_filepath), True)
except Exception as e:
self.assertTrue(False, "cannot create VM overlay: %s" % str(e))
示例5: main
# 需要导入模块: import libvirt [as 别名]
# 或者: from libvirt import VIR_DOMAIN_RUNNING [as 别名]
def main():
args = parse_args()
conn = libvirt.openReadOnly(None)
now = str(int(time()))
core2node = get_cpu_core_to_numa_node_mapping()
total_mem_used = 0
for dom in conn.listAllDomains():
name = dom.name()
if args.trim_domain:
if name.endswith('.' + args.trim_domain):
name = name[:-len('.' + args.trim_domain)]
# Strip objectid from domain name to get the hostname
if '_' in name:
name = name.split('_', 1)[1]
# Make hostname save for graphite
name = name.replace('.', '_')
dom_state, dom_reason = dom.state()
if dom_state == libvirt.VIR_DOMAIN_RUNNING:
get_dom_vcpu_stats(dom, args.prefix, name, now, core2node)
get_dom_network_stats(dom, args.prefix, name, now)
get_dom_disk_stats(dom, args.prefix, name, now)
total_mem_used += get_dom_memory_stats(dom, args.prefix, name, now)
get_dom_storage_usage(conn, dom, args.prefix, name, now)
get_hv_storage_usage(conn, args.prefix, now)
get_hv_memory_usage(conn, args.prefix, now, total_mem_used)
示例6: _get_power_state
# 需要导入模块: import libvirt [as 别名]
# 或者: from libvirt import VIR_DOMAIN_RUNNING [as 别名]
def _get_power_state(self):
"""Return the power state of the VM in the form of a PowerStates enum."""
if self.isRegistered():
remote_libvirt = (self.isRegisteredRemotely() and not self.po__cluster_disabled)
libvirt_object = self._get_libvirt_domain_object(allow_remote=remote_libvirt)
if libvirt_object.state()[0] == libvirt.VIR_DOMAIN_RUNNING:
return PowerStates.RUNNING
else:
return PowerStates.STOPPED
else:
return PowerStates.UNKNOWN
示例7: check_dom_state
# 需要导入模块: import libvirt [as 别名]
# 或者: from libvirt import VIR_DOMAIN_RUNNING [as 别名]
def check_dom_state(domobj):
state = domobj.info()[0]
expect_states = [libvirt.VIR_DOMAIN_RUNNING, libvirt.VIR_DOMAIN_NOSTATE,
libvirt.VIR_DOMAIN_BLOCKED]
if state in expect_states:
return 1
return 0
示例8: check_dom_state
# 需要导入模块: import libvirt [as 别名]
# 或者: from libvirt import VIR_DOMAIN_RUNNING [as 别名]
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
示例9: managedsave_define_xml_clean
# 需要导入模块: import libvirt [as 别名]
# 或者: from libvirt import VIR_DOMAIN_RUNNING [as 别名]
def managedsave_define_xml_clean(params):
guestname = params['guestname']
logger = params['logger']
conn = libvirt.open()
dom = conn.lookupByName(guestname)
state = dom.info()[0]
if state == libvirt.VIR_DOMAIN_RUNNING:
dom.destroy()
dom.undefineFlags(libvirt.VIR_DOMAIN_UNDEFINE_MANAGED_SAVE)
示例10: managedsave_get_xml_desc_clean
# 需要导入模块: import libvirt [as 别名]
# 或者: from libvirt import VIR_DOMAIN_RUNNING [as 别名]
def managedsave_get_xml_desc_clean(params):
guestname = params['guestname']
logger = params['logger']
conn = libvirt.open()
dom_list = conn.listAllDomains()
for dom in dom_list:
if dom.name() == guestname:
if dom.info()[0] == libvirt.VIR_DOMAIN_RUNNING:
dom.destroy()
dom.undefineFlags(libvirt.VIR_DOMAIN_UNDEFINE_MANAGED_SAVE)
示例11: check_domain_state
# 需要导入模块: import libvirt [as 别名]
# 或者: from libvirt import VIR_DOMAIN_RUNNING [as 别名]
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
示例12: check_events
# 需要导入模块: import libvirt [as 别名]
# 或者: from libvirt import VIR_DOMAIN_RUNNING [as 别名]
def check_events(events, event_list, guestname, flags, domstate, dom, logger):
values = {}
if ((domstate == libvirt.VIR_DOMAIN_RUNNING) and
((flags == libvirt.VIR_DOMAIN_AFFECT_CURRENT) or
(flags == libvirt.VIR_DOMAIN_AFFECT_LIVE))):
xmlstr = minidom.parse("%s%s.xml" % (XML_PATH, guestname))
else:
guestxml = dom.XMLDesc(libvirt.VIR_DOMAIN_XML_INACTIVE)
xmlstr = minidom.parseString(guestxml)
perf = xmlstr.getElementsByTagName('perf')
if perf:
perf = xmlstr.getElementsByTagName('perf')[0]
for item in perf.getElementsByTagName('event'):
for i in event_list:
if item.getAttribute('name') == i:
if item.getAttribute('enabled') == "yes":
values[i] = True
elif item.getAttribute('enabled') == "no":
values[i] = False
logger.info("values: %s" % values)
for i in event_list:
if i in list(values.keys()) and i in list(events.keys()):
if values[i] != events[i]:
return 1
return 0
示例13: check_dom_state
# 需要导入模块: import libvirt [as 别名]
# 或者: from libvirt import VIR_DOMAIN_RUNNING [as 别名]
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
示例14: test_synthesis_step_by_step
# 需要导入模块: import libvirt [as 别名]
# 或者: from libvirt import VIR_DOMAIN_RUNNING [as 别名]
def test_synthesis_step_by_step(self):
# decompress VM overlay
overlay_filename = NamedTemporaryFile(prefix="cloudlet-test-overlay-file-")
meta_info = compression.decomp_overlayzip(self.overlay_url,
overlay_filename.name)
self.assertIsInstance(meta_info, dict)
self.assertTrue(meta_info.has_key(Cloudlet_Const.META_OVERLAY_FILES))
# recover launch VM
launch_disk, launch_mem, fuse, delta_proc, fuse_thread = \
synthesis.recover_launchVM(self.base_vm_path, meta_info, overlay_filename.name)
self.assertTrue(os.path.exists(launch_disk))
self.assertTrue(os.path.exists(launch_mem))
self.assertIsInstance(fuse, CloudletFS)
# resume launch VM
synthesized_VM = synthesis.SynthesizedVM(
launch_disk, launch_mem, fuse, disk_only=False
)
delta_proc.start()
fuse_thread.start()
delta_proc.join()
fuse_thread.join()
synthesized_VM.resume()
# check VM's status
VM_status = VMUtility.get_VM_status(synthesized_VM.machine)
self.assertEqual(VM_status, libvirt.VIR_DOMAIN_RUNNING)
# cleanup
synthesized_VM.monitor.terminate()
synthesized_VM.monitor.join()
synthesized_VM.terminate()
示例15: update_servers_status
# 需要导入模块: import libvirt [as 别名]
# 或者: from libvirt import VIR_DOMAIN_RUNNING [as 别名]
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