本文整理汇总了Python中xen.xend.XendDomain.instance方法的典型用法代码示例。如果您正苦于以下问题:Python XendDomain.instance方法的具体用法?Python XendDomain.instance怎么用?Python XendDomain.instance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类xen.xend.XendDomain
的用法示例。
在下文中一共展示了XendDomain.instance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: op_receive
# 需要导入模块: from xen.xend import XendDomain [as 别名]
# 或者: from xen.xend.XendDomain import instance [as 别名]
def op_receive(self, name, _):
if self.transport:
self.send_reply(["ready", name])
XendDomain.instance().domain_restore_fd(
self.transport.sock.fileno())
else:
log.error(name + ": no transport")
raise XendError(name + ": no transport")
示例2: getVBDs
# 需要导入模块: from xen.xend import XendDomain [as 别名]
# 或者: from xen.xend.XendDomain import instance [as 别名]
def getVBDs(self):
from xen.xend import XendDomain
vbd_refs = [d.get_vbds() for d in XendDomain.instance().list('all')]
vbd_refs = reduce(lambda x, y: x + y, vbd_refs)
vbds = []
for vbd_ref in vbd_refs:
vdi = XendDomain.instance().get_dev_property_by_uuid('vbd', vbd_ref, 'VDI')
if vdi == self.uuid:
vbds.append(vbd_ref)
return vbds
示例3: destroyDeviceModel
# 需要导入模块: from xen.xend import XendDomain [as 别名]
# 或者: from xen.xend.XendDomain import instance [as 别名]
def destroyDeviceModel(self):
if self.device_model is None:
return
self.sentinel_lock.acquire()
try:
stubdomid = self.vm.getStubdomDomid()
if stubdomid is not None :
from xen.xend import XendDomain
XendDomain.instance().domain_destroy(stubdomid)
elif self.pid:
try:
os.kill(self.pid, signal.SIGHUP)
except OSError, exn:
log.exception(exn)
# Try to reap the child every 100ms for 10s. Then SIGKILL it.
for i in xrange(100):
try:
(p, rv) = os.waitpid(self.pid, os.WNOHANG)
if p == self.pid:
break
except OSError:
# This is expected if Xend has been restarted within
# the life of this domain. In this case, we can kill
# the process, but we can't wait for it because it's
# not our child. We continue this loop, and after it is
# terminated make really sure the process is going away
# (SIGKILL).
pass
time.sleep(0.1)
else:
log.warning("DeviceModel %d took more than 10s "
"to terminate: sending SIGKILL" % self.pid)
try:
os.kill(self.pid, signal.SIGKILL)
os.waitpid(self.pid, 0)
except OSError:
# This happens if the process doesn't exist.
pass
finally:
self.pid = None
self.sentinel_lock.release()
state = xstransact.Remove("/local/domain/0/device-model/%i"
% self.vm.getDomid())
try:
os.unlink('/var/run/tap/qemu-read-%d' % self.vm.getDomid())
os.unlink('/var/run/tap/qemu-write-%d' % self.vm.getDomid())
except:
pass
try:
del sentinel_fifos_inuse[self.sentinel_path_fifo]
os.unlink(self.sentinel_path_fifo)
except:
pass
示例4: op_receive
# 需要导入模块: from xen.xend import XendDomain [as 别名]
# 或者: from xen.xend.XendDomain import instance [as 别名]
def op_receive(self, name, _):
if self.transport:
self.send_reply(["ready", name])
try:
XendDomain.instance().domain_restore_fd(
self.transport.sock.fileno(), relocating=True)
except:
self.send_error()
self.close()
else:
log.error(name + ": no transport")
raise XendError(name + ": no transport")
示例5: domains_with_state
# 需要导入模块: from xen.xend import XendDomain [as 别名]
# 或者: from xen.xend.XendDomain import instance [as 别名]
def domains_with_state(detail, state, full):
if detail:
domains = XendDomain.instance().list_sorted(state)
ret = []
for dom in domains:
try:
ret.append(fixup_sxpr(dom.sxpr(not full)))
except:
log.warn("Failed to query SXPR for domain %s" % str(dom))
pass
return ret
else:
return XendDomain.instance().list_names(state)
示例6: wait_devs
# 需要导入模块: from xen.xend import XendDomain [as 别名]
# 或者: from xen.xend.XendDomain import instance [as 别名]
def wait_devs(dominfo):
from xen.xend import XendDomain
lock = True;
try:
XendDomain.instance().domains_lock.release()
except:
lock = False;
try:
dominfo.waitForDevices() # Wait for backends to set up
except Exception, exn:
log.exception(exn)
if lock:
XendDomain.instance().domains_lock.acquire()
raise
示例7: check_status
# 需要导入模块: from xen.xend import XendDomain [as 别名]
# 或者: from xen.xend.XendDomain import instance [as 别名]
def check_status(self):
try:
global status_list
global status_last
global dest_ip
status_changed=False
status_list_copy=status_list
while True:
if status_list_copy[:5].count(1)==5:
status_now=True
elif status_list_copy[:5].count(0)==5 or status_list_copy.count(0)==10:
status_now=False
if status_now!=status_last:
status_changed=True
else:
status_changed=False
status_last=status_now
if status_changed==True:
if status_now==False:
xendom = XendDomain.instance()
doms = xendom.list('all')
for dom in doms:
vm_uuid = dom.get_uuid()
if cmp(vm_uuid, DOM0_UUID) == 0:
continue
self.hard_shutdown_and_delete(vm_uuid)
# print dest_ip,"status to Down"
# elif status_now==True:
# print dest_ip,"status to Up"
#print 'now status is: ', status_now
time.sleep(0.3)
except BaseException,e:
log.debug(e)
示例8: activate_xspolicy
# 需要导入模块: from xen.xend import XendDomain [as 别名]
# 或者: from xen.xend.XendDomain import instance [as 别名]
def activate_xspolicy(self, xspol, flags):
from xen.xend import XendDomain
domains = XendDomain.instance()
try:
domains.domains_lock.acquire()
return self.__activate_xspolicy(xspol, flags)
finally:
domains.domains_lock.release()
示例9: op_sslreceive
# 需要导入模块: from xen.xend import XendDomain [as 别名]
# 或者: from xen.xend.XendDomain import instance [as 别名]
def op_sslreceive(self, name, _):
if self.transport:
self.send_reply(["ready", name])
p2cread, p2cwrite = os.pipe()
threading.Thread(target=connection.SSLSocketServerConnection.recv2fd,
args=(self.transport.sock, p2cwrite)).start()
try:
XendDomain.instance().domain_restore_fd(p2cread,
relocating=True)
except:
os.close(p2cread)
os.close(p2cwrite)
self.send_error()
self.close()
else:
log.error(name + ": no transport")
raise XendError(name + ": no transport")
示例10: getDeviceDetails
# 需要导入模块: from xen.xend import XendDomain [as 别名]
# 或者: from xen.xend.XendDomain import instance [as 别名]
def getDeviceDetails(self, config):
(devid, back, front) = BlkifController.getDeviceDetails(self, config)
phantomDevid = 0
wrapped = False
try:
imagetype = self.vm.info['image']['type']
except:
imagetype = ""
if imagetype == 'hvm':
tdevname = back['dev']
index = ['c', 'd', 'e', 'f', 'g', 'h', 'i', \
'j', 'l', 'm', 'n', 'o', 'p']
while True:
global phantomDev
global phantomId
import os, stat
phantomId = phantomId + 1
if phantomId == 16:
if index[phantomDev] == index[-1]:
if wrapped:
raise VmError(" No loopback block \
devices are available. ")
wrapped = True
phantomDev = 0
else:
phantomDev = phantomDev + 1
phantomId = 1
devname = 'xvd%s%d' % (index[phantomDev], phantomId)
try:
info = os.stat('/dev/%s' % devname)
except:
break
vbd = { 'mode': 'w', 'device': devname }
fn = 'tap:%s' % back['params']
# recurse ... by creating the vbd, then fallthrough
# and finish creating the original device
from xen.xend import XendDomain
dom0 = XendDomain.instance().privilegedDomain()
phantomDevid = dom0.create_phantom_vbd_with_vdi(vbd, fn)
# we need to wait for this device at a higher level
# the vbd that gets created will have a link to us
# and will let them do it there
# add a hook to point to the phantom device,
# root path is always the same (dom0 tap)
if phantomDevid != 0:
front['phantom_vbd'] = '/local/domain/0/backend/tap/0/%s' \
% str(phantomDevid)
return (devid, back, front)
示例11: get_VM_ssidref
# 需要导入模块: from xen.xend import XendDomain [as 别名]
# 或者: from xen.xend.XendDomain import instance [as 别名]
def get_VM_ssidref(self, vm_ref):
dom = XendDomain.instance().get_vm_by_uuid(vm_ref)
if not dom:
raise InvalidHandleError("VM", vm_ref)
if dom._stateGet() not in [ XEN_API_VM_POWER_STATE_RUNNING, \
XEN_API_VM_POWER_STATE_PAUSED ]:
raise VMBadState("Domain is not running or paused.")
ssid = security.get_ssid(dom.getDomid())
if not ssid:
raise SecurityError(-xsconstants.XSERR_GENERAL_FAILURE)
return ssid[3]
示例12: get_memory_free
# 需要导入模块: from xen.xend import XendDomain [as 别名]
# 或者: from xen.xend.XendDomain import instance [as 别名]
def get_memory_free(self):
xendom = XendDomain.instance()
doms = xendom.list()
doms_mem_total = 0
for dom in doms:
if cmp(dom.get_uuid(), DOM0_UUID) == 0:
continue
dominfo = xendom.get_vm_by_uuid(dom.get_uuid())
doms_mem_total += dominfo.get_memory_dynamic_max()
return (self.host_instance.xc.physinfo()['total_memory'] * 1024 - doms_mem_total)/1024
示例13: reset_acmpolicy
# 需要导入模块: from xen.xend import XendDomain [as 别名]
# 或者: from xen.xend.XendDomain import instance [as 别名]
def reset_acmpolicy(self):
"""
Attempt to reset the system's policy by udating it with
the DEFAULT policy.
"""
from xen.xend import XendDomain
domains = XendDomain.instance()
try:
domains.domains_lock.acquire()
xml = ACMPolicy.get_reset_policy_xml()
flags = xsconstants.XS_INST_BOOT | xsconstants.XS_INST_LOAD
return self.__add_acmpolicy_to_system(xml, flags, True)
finally:
domains.domains_lock.release()
示例14: hard_shutdown_and_delete
# 需要导入模块: from xen.xend import XendDomain [as 别名]
# 或者: from xen.xend.XendDomain import instance [as 别名]
def hard_shutdown_and_delete(self, vm_ref):
xendom = XendDomain.instance()
dominfo = xendom.get_vm_by_uuid(vm_ref)
if not dominfo:
return
domid = dominfo.getDomid()
if domid and cmp (int(domid), -1) > 0:
xendom.domain_destroy(vm_ref)
i = 0
time_out = 30
while True:
i += 1
# ps_new = self.VM_get_power_state(session, vm_ref)['Value']
domid = dominfo.getDomid()
# log.debug(ps_new)
if not domid or cmp (int(domid), -1) == 0:
break
elif cmp(i, time_out) > 0:
break
else:
time.sleep(0.5)
continue
示例15: run
# 需要导入模块: from xen.xend import XendDomain [as 别名]
# 或者: from xen.xend.XendDomain import instance [as 别名]
def run(self):
if self.use_tcp:
# bind to something fixed for now as we may eliminate
# tcp support completely.
self.server = TCPXMLRPCServer(("localhost", 8005), logRequests=False)
else:
self.server = UnixXMLRPCServer(XML_RPC_SOCKET, False)
# Functions in XendDomainInfo
for name in methods:
fn = eval("lambda domid, *args: dispatch(domid, '%s', args)"%name)
self.server.register_function(fn, "xend.domain.%s" % name)
# Functions in XendDomain
inst = XendDomain.instance()
for name in dir(inst):
fn = getattr(inst, name)
if name.startswith("domain_") and callable(fn):
if name not in exclude:
self.server.register_function(fn, "xend.domain.%s" % name[7:])
# Functions in XendNode and XendDmesg
for type, lst, n in [(XendNode, ['info', 'cpu_bvt_slice_set'], 'node'),
(XendDmesg, ['info', 'clear'], 'node.dmesg')]:
inst = type.instance()
for name in lst:
self.server.register_function(getattr(inst, name),
"xend.%s.%s" % (n, name))
# A few special cases
self.server.register_function(domain, 'xend.domain')
self.server.register_function(domains, 'xend.domains')
self.server.register_function(get_log, 'xend.node.log')
self.server.register_function(domain_create, 'xend.domain.create')
self.server.register_function(domain_restore, 'xend.domain.restore')
self.server.register_introspection_functions()
self.ready = True
self.server.serve_forever()