本文整理汇总了Python中karesansui.lib.virt.virt.KaresansuiVirtConnection.list_active_guest方法的典型用法代码示例。如果您正苦于以下问题:Python KaresansuiVirtConnection.list_active_guest方法的具体用法?Python KaresansuiVirtConnection.list_active_guest怎么用?Python KaresansuiVirtConnection.list_active_guest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类karesansui.lib.virt.virt.KaresansuiVirtConnection
的用法示例。
在下文中一共展示了KaresansuiVirtConnection.list_active_guest方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: process
# 需要导入模块: from karesansui.lib.virt.virt import KaresansuiVirtConnection [as 别名]
# 或者: from karesansui.lib.virt.virt.KaresansuiVirtConnection import list_active_guest [as 别名]
def process(self):
(opts, args) = getopts()
chkopts(opts)
self.up_progress(10)
conn = KaresansuiVirtConnection(readonly=False)
try:
conn.set_domain_name(opts.name)
active_guests = conn.list_active_guest()
inactive_guests = conn.list_inactive_guest()
if opts.name in active_guests or opts.name in inactive_guests:
try:
self.up_progress(10)
conn.destroy_guest()
self.up_progress(40)
except Exception, e:
self.logger.error('Failed to destroy guest. - dom=%s' % (opts.name))
print >>sys.stderr, _('Failed to destroy guest. - dom=%s') % (opts.name)
raise e
status = conn.guest.status()
self.up_progress(10)
if status == VIR_DOMAIN_SHUTOFF or status == VIR_DOMAIN_SHUTDOWN:
self.logger.info('Succeeded to destroy guest. - dom=%s' % (opts.name))
print >>sys.stdout, _('Succeeded to destroy guest. - dom=%s') % (opts.name)
else:
示例2: process
# 需要导入模块: from karesansui.lib.virt.virt import KaresansuiVirtConnection [as 别名]
# 或者: from karesansui.lib.virt.virt.KaresansuiVirtConnection import list_active_guest [as 别名]
def process(self):
(opts, args) = getopts()
chkopts(opts)
self.up_progress(10)
conn = KaresansuiVirtConnection(readonly=False)
try:
conn.set_domain_name(opts.name)
active_guests = conn.list_active_guest()
inactive_guests = conn.list_inactive_guest()
if opts.name in active_guests or opts.name in inactive_guests:
try:
self.up_progress(10)
conn.guest.set_vcpus(vcpus=opts.vcpus,max_vcpus=opts.max_vcpus)
self.up_progress(20)
info = conn.guest.get_vcpus_info()
self.up_progress(10)
self.logger.info('Set vcpus. - dom=%s vcpus=%s max_vcpus=%s bootup_vcpus=%s' \
% (opts.name, info['vcpus'], info['max_vcpus'], info['bootup_vcpus']))
print >>sys.stdout, _('Set vcpus. - dom=%s vcpus=%s max_vcpus=%s bootup_vcpus=%s') \
% (opts.name, info['vcpus'], info['max_vcpus'], info['bootup_vcpus'])
except Exception, e:
self.logger.error('Failed to set vcpus. - dom=%s' % (opts.name))
print >>sys.stderr, _('Failed to set vcpus. - dom=%s') % (opts.name)
raise e
else:
示例3: process
# 需要导入模块: from karesansui.lib.virt.virt import KaresansuiVirtConnection [as 别名]
# 或者: from karesansui.lib.virt.virt.KaresansuiVirtConnection import list_active_guest [as 别名]
def process(self):
(opts, args) = getopts()
chkopts(opts)
self.up_progress(10)
conn = KaresansuiVirtConnection(readonly=False)
try:
conn.set_domain_name(opts.name)
active_guests = conn.list_active_guest()
inactive_guests = conn.list_inactive_guest()
if opts.name in active_guests or opts.name in inactive_guests:
try:
self.up_progress(10)
conn.suspend_guest()
self.up_progress(40)
except:
raise KssCommandException('Failed to suspend guest. - dom=%s' % (opts.name))
self.up_progress(10)
status = conn.guest.status()
self.up_progress(10)
if status == VIR_DOMAIN_PAUSED:
self.logger.info('Succeeded to suspend guest. - dom=%s' % (opts.name))
print >>sys.stdout, _('Succeeded to suspend guest. - dom=%s') % (opts.name)
else:
raise KssCommandException(
'Could not find guest. - dom=%s' % (opts.name))
return True
finally:
conn.close()
示例4: process
# 需要导入模块: from karesansui.lib.virt.virt import KaresansuiVirtConnection [as 别名]
# 或者: from karesansui.lib.virt.virt.KaresansuiVirtConnection import list_active_guest [as 别名]
def process(self):
(opts, args) = getopts()
chkopts(opts)
self.up_progress(10)
if opts.maxmem:
opts.maxmem = str(opts.maxmem) + 'm'
if opts.memory:
opts.memory = str(opts.memory) + 'm'
self.up_progress(10)
conn = KaresansuiVirtConnection(readonly=False)
try:
conn.set_domain_name(opts.name)
active_guests = conn.list_active_guest()
inactive_guests = conn.list_inactive_guest()
if opts.name in active_guests or opts.name in inactive_guests:
try:
self.up_progress(10)
conn.guest.set_memory(opts.maxmem,opts.memory)
self.up_progress(20)
info = conn.guest.get_info()
self.up_progress(10)
self.logger.info('Set memory size. - dom=%s max=%d mem=%d' \
% (opts.name, info['maxMem'], info['memory']))
print >>sys.stdout, _('Set memory size. - dom=%s max=%d mem=%d') \
% (opts.name, info['maxMem'], info['memory'])
except Exception, e:
self.logger.error('Failed to set memory size. - dom=%s' % (opts.name))
print >>sys.stderr, _('Failed to set memory size. - dom=%s') % (opts.name)
raise e
else:
示例5: __init__
# 需要导入模块: from karesansui.lib.virt.virt import KaresansuiVirtConnection [as 别名]
# 或者: from karesansui.lib.virt.virt.KaresansuiVirtConnection import list_active_guest [as 别名]
class KaresansuiVirtSnapshot:
def __init__(self,uri=None,readonly=True):
self.__prep()
self.logger.debug(get_inspect_stack())
try:
self.kvc = KaresansuiVirtConnection(uri=uri, readonly=readonly)
except:
raise KaresansuiVirtSnapshotException(_("Cannot open '%s'") % uri)
try:
from libvirtmod import virDomainRevertToSnapshot
from libvirtmod import virDomainSnapshotCreateXML
from libvirtmod import virDomainSnapshotCurrent
from libvirtmod import virDomainSnapshotDelete
from libvirtmod import virDomainSnapshotGetXMLDesc
from libvirtmod import virDomainSnapshotLookupByName
except:
raise KaresansuiVirtSnapshotException(_("Snapshot is not supported by this version of libvirt"))
self.error_msg = []
def __del__(self):
self.finish()
def __prep(self):
self.logger = logging.getLogger('karesansui.virt.snapshot')
def finish(self):
try:
self.kvc.close()
except:
pass
def append_error_msg(self,string):
self.error_msg.append(string)
def reset_error_msg(self):
self.error_msg = []
def generateXML(self, doc):
out = StringIO()
out.write(doc,toxml())
return out.getvalue()
def isSupportedDomain(self,domain=None):
retval = True
inactives = self.kvc.list_inactive_guest()
actives = self.kvc.list_active_guest()
if domain is not None:
if domain in inactives + actives:
guest = self.kvc.search_guests(domain)[0]
param = ConfigParam(domain)
param.load_xml_config(guest.XMLDesc(1))
for info in param.disks:
"""
{ 'bus' :'ide',
'device' :'disk',
'disk_type' :'file',
'driver_name':'qemu',
'driver_type':'qcow2',
'path' :'/path/to/disk_image.img',
'target' :'hda'}
"""
try:
if info['driver_type'] == "qcow2":
pass
elif info['device'] == "cdrom":
pass
else:
if info['disk_type'] != "block":
self.append_error_msg(_("%s: unsupported image format %s") % (info['target'],info['driver_type']))
retval = False
#break
except:
retval = False
#break
else:
retval = False
return retval
def _snapshotListNames(self,domain=None):
retval = []
if domain is not None:
for xml_path in glob.glob("%s/%s/*.xml" % (VIRT_SNAPSHOT_DIR,domain,)):
retval.append(os.path.basename(xml_path)[0:-4])
return retval
def listNames(self,domain=None,all=False):
retval = {}
inactives = self.kvc.list_inactive_guest()
actives = self.kvc.list_active_guest()
#.........这里部分代码省略.........
示例6: Guest
# 需要导入模块: from karesansui.lib.virt.virt import KaresansuiVirtConnection [as 别名]
# 或者: from karesansui.lib.virt.virt.KaresansuiVirtConnection import list_active_guest [as 别名]
class Guest(Rest):
def _post(self, f):
ret = Rest._post(self, f)
if hasattr(self, "kvc") is True:
self.kvc.close()
return ret
@auth
def _GET(self, *param, **params):
host_id = self.chk_hostby1(param)
if host_id is None: return web.notfound()
model = findbyhost1(self.orm, host_id)
uris = available_virt_uris()
self.kvc = KaresansuiVirtConnection()
try: # libvirt connection scope -->
# Storage Pool
#inactive_pool = self.kvc.list_inactive_storage_pool()
inactive_pool = []
active_pool = self.kvc.list_active_storage_pool()
pools = inactive_pool + active_pool
pools.sort()
if not pools:
return web.badrequest('One can not start a storage pool.')
# Output .input
if self.is_mode_input() is True:
self.view.pools = pools
pools_info = {}
pools_vols_info = {}
pools_iscsi_blocks = {}
already_vols = []
guests = []
guests += self.kvc.list_inactive_guest()
guests += self.kvc.list_active_guest()
for guest in guests:
already_vol = self.kvc.get_storage_volume_bydomain(domain=guest,
image_type=None,
attr='path')
if already_vol:
already_vols += already_vol.keys()
for pool in pools:
pool_obj = self.kvc.search_kvn_storage_pools(pool)[0]
if pool_obj.is_active() is True:
pools_info[pool] = pool_obj.get_info()
blocks = None
if pools_info[pool]['type'] == 'iscsi':
blocks = self.kvc.get_storage_volume_iscsi_block_bypool(pool)
if blocks:
pools_iscsi_blocks[pool] = []
vols_obj = pool_obj.search_kvn_storage_volumes(self.kvc)
vols_info = {}
for vol_obj in vols_obj:
vol_name = vol_obj.get_storage_volume_name()
vols_info[vol_name] = vol_obj.get_info()
if blocks:
if vol_name in blocks and vol_name not in already_vols:
pools_iscsi_blocks[pool].append(vol_obj.get_info())
pools_vols_info[pool] = vols_info
self.view.pools_info = pools_info
self.view.pools_vols_info = pools_vols_info
self.view.pools_iscsi_blocks = pools_iscsi_blocks
bridge_prefix = {
"XEN":"xenbr",
"KVM":KVM_BRIDGE_PREFIX,
}
self.view.host_id = host_id
self.view.DEFAULT_KEYMAP = DEFAULT_KEYMAP
self.view.DISK_NON_QEMU_FORMAT = DISK_NON_QEMU_FORMAT
self.view.DISK_QEMU_FORMAT = DISK_QEMU_FORMAT
self.view.hypervisors = {}
self.view.mac_address = {}
self.view.keymaps = {}
self.view.phydev = {}
self.view.virnet = {}
used_ports = {}
for k,v in MACHINE_HYPERVISOR.iteritems():
if k in available_virt_mechs():
self.view.hypervisors[k] = v
uri = uris[k]
mem_info = self.kvc.get_mem_info()
active_networks = self.kvc.list_active_network()
used_graphics_ports = self.kvc.list_used_graphics_port()
bus_types = self.kvc.bus_types
self.view.bus_types = bus_types
self.view.max_mem = mem_info['host_max_mem']
self.view.free_mem = mem_info['host_free_mem']
#.........这里部分代码省略.........
示例7: process
# 需要导入模块: from karesansui.lib.virt.virt import KaresansuiVirtConnection [as 别名]
# 或者: from karesansui.lib.virt.virt.KaresansuiVirtConnection import list_active_guest [as 别名]
def process(self):
(opts, args) = getopts()
chkopts(opts)
self.up_progress(10)
conn = KaresansuiVirtConnection(readonly=False)
try:
# dest storage pool
dest_target_path = conn.get_storage_pool_targetpath(opts.pool)
if not dest_target_path:
raise KssCommandException(
"Could not get the target path of the storage pool. - path=%s" % dest_target_path)
self.dest_disk = "%s/%s/images/%s.img" \
% (dest_target_path, opts.name,opts.name,)
# source storage pool
src_pool = conn.get_storage_pool_name_bydomain(opts.src_name, "os")
if not src_pool:
raise KssCommandException("Source storage pool is not found.")
src_pool_type = conn.get_storage_pool_type(src_pool)
if src_pool_type == 'dir':
raise KssCommandException(
"Storage pool type 'dir' is not. - type=%s" % src_pool_type)
src_target_path = conn.get_storage_pool_targetpath(src_pool[0])
self.src_disk = "%s/%s/images/%s.img" \
% (src_target_path, opts.src_name,opts.src_name,)
if os.path.isfile(self.src_disk) is False:
raise KssCommandException(
'source disk image is not found. - src=%s' % (self.src_disk))
if os.path.isfile(self.dest_disk) is True:
raise KssCommandException(
'destination disk image already exists. - dest=%s' % (self.dest_disk))
self.up_progress(10)
active_storage_pools = conn.list_active_storage_pool()
self.up_progress(10)
if not (opts.pool in active_storage_pools):
raise KssCommandException('Storage pool does not exist. - pool=%s'
% (opts.pool))
try:
active_guests = conn.list_active_guest()
inactive_guests = conn.list_inactive_guest()
# source guestos
if not (opts.src_name in active_guests or opts.src_name in inactive_guests):
raise KssCommandException(
"Unable to get the source guest OS. - src_name=%s" % opts.src_name)
if (opts.name in active_guests or opts.name in inactive_guests):
raise KssCommandException(
"Destination Guest OS is already there. - dest_name=%s" % opts.name)
self.up_progress(10)
conn.replicate_guest(opts.name,
opts.src_name,
opts.pool,
opts.mac,
opts.uuid,
opts.vnc_port)
self.up_progress(40)
except:
self.logger.error('Failed to replicate guest. - src=%s dom=%s' % (opts.src_name,opts.name))
raise
finally:
conn.close()
conn1 = KaresansuiVirtConnection(readonly=False)
try:
self.up_progress(10)
active_guests = conn1.list_active_guest()
inactive_guests = conn1.list_inactive_guest()
if opts.name in active_guests or opts.name in inactive_guests:
self.logger.info('Replicated guest. - src=%s dom=%s' % (opts.src_name,opts.name))
print >>sys.stdout, _('Replicated guest. - src=%s dom=%s') % (opts.src_name,opts.name)
return True
else:
raise KssCommandException(
'Replicate guest not found. - src=%s dom=%s' % (opts.src_name,opts.name))
finally:
conn1.close()
return True
示例8: process
# 需要导入模块: from karesansui.lib.virt.virt import KaresansuiVirtConnection [as 别名]
# 或者: from karesansui.lib.virt.virt.KaresansuiVirtConnection import list_active_guest [as 别名]
def process(self):
(opts, args) = getopts()
chkopts(opts)
self.up_progress(10)
conn = KaresansuiVirtConnection(readonly=False)
try:
conn.set_interface_format(opts.interface_format)
active_guests = conn.list_active_guest()
inactive_guests = conn.list_inactive_guest()
if opts.name in active_guests or opts.name in inactive_guests:
raise KssCommandException('Guest already exists. - dom=%s' % (opts.name))
self.up_progress(10)
inactive_storage_pools = conn.list_inactive_storage_pool()
active_storage_pools = conn.list_active_storage_pool()
if not (opts.storage_pool in active_storage_pools or opts.storage_pool in inactive_storage_pools):
raise KssCommandException('Storage pool does not exist. - pool=%s' % (opts.storage_pool))
# TODO
#if conn.get_storage_volume(opts.storage_pool, opts.uuid) is None:
# raise KssCommandException('Specified storage volume does not exist. - pool=%s, vol=%s'
# % (opts.storage_pool, opts.uuid))
try:
self.up_progress(10)
if not conn.create_guest(name=opts.name,
type=opts.type.lower(),
ram=opts.mem_size,
disk=opts.disk,
disksize=opts.disk_size,
mac=opts.mac,
uuid=opts.uuid,
kernel=opts.kernel,
initrd=opts.initrd,
iso=opts.iso,
vnc=opts.vnc_port,
vcpus=opts.vcpus,
extra=opts.extra,
keymap=opts.keymap,
bus=opts.bus,
disk_format=opts.disk_format,
storage_pool=opts.storage_pool,
storage_volume=opts.storage_volume,
) is True:
raise KssCommandException('Failed to create guest. - dom=%s' % (opts.name))
except Exception, e:
self.logger.error('Failed to create guest. - dom=%s - detail %s' % (opts.name, str(e.args)))
print >>sys.stderr, _('Failed to create guest. - dom=%s - detail %s') % (opts.name, str(e.args))
raise e
self.up_progress(40)
active_guests = conn.list_active_guest()
inactive_guests = conn.list_inactive_guest()
if not (opts.name in active_guests or opts.name in inactive_guests):
raise KssCommandException('Guest OS is not recognized. - dom=%s' % (opts.name))
self.logger.info('Created guest. - dom=%s' % (opts.name))
print >>sys.stdout, 'Created guest. - dom=%s' % opts.name
return True
示例9: GuestBy1Device
# 需要导入模块: from karesansui.lib.virt.virt import KaresansuiVirtConnection [as 别名]
# 或者: from karesansui.lib.virt.virt.KaresansuiVirtConnection import list_active_guest [as 别名]
class GuestBy1Device(Rest):
@auth
def _GET(self, *param, **params):
(host_id, guest_id) = self.chk_guestby1(param)
if guest_id is None: return web.notfound()
bridge_prefix = {
"XEN":"xenbr",
"KVM":"br|bondbr",
#"KVM":"eth|bondbr",
}
model = findbyguest1(self.orm, guest_id)
# virt
self.kvc = KaresansuiVirtConnection()
try:
domname = self.kvc.uuid_to_domname(model.uniq_key)
if not domname:
return web.notfound()
virt = self.kvc.search_kvg_guests(domname)[0]
guest = MergeGuest(model, virt)
self.view.guest = guest
# Output .input
if self.is_mode_input() is True:
try:
VMType = guest.info["virt"].get_info()["VMType"].upper()
except:
VMType = "KVM"
self.view.VMType = VMType
# Network
phydev = []
phydev_regex = re.compile(r"%s" % bridge_prefix[VMType])
for dev,dev_info in get_ifconfig_info().iteritems():
try:
if phydev_regex.match(dev):
phydev.append(dev)
except:
pass
if len(phydev) == 0:
phydev.append("%s0" % bridge_prefix[VMType])
phydev.sort()
self.view.phydev = phydev # Physical device
self.view.virnet = sorted(self.kvc.list_active_network()) # Virtual device
self.view.mac_address = generate_mac_address() # new mac address
# Disk
inactive_pool = []
active_pool = self.kvc.list_active_storage_pool()
pools = inactive_pool + active_pool
pools.sort()
if not pools:
return web.badrequest('One can not start a storage pool.')
pools_info = {}
pools_vols_info = {}
pools_iscsi_blocks = {}
already_vols = []
guests = []
guests += self.kvc.list_inactive_guest()
guests += self.kvc.list_active_guest()
for guest in guests:
already_vol = self.kvc.get_storage_volume_bydomain(domain=guest,
image_type=None,
attr='path')
if already_vol:
already_vols += already_vol.keys()
for pool in pools:
pool_obj = self.kvc.search_kvn_storage_pools(pool)[0]
if pool_obj.is_active() is True:
pools_info[pool] = pool_obj.get_info()
blocks = None
if pools_info[pool]['type'] == 'iscsi':
blocks = self.kvc.get_storage_volume_iscsi_block_bypool(pool)
if blocks:
pools_iscsi_blocks[pool] = []
vols_obj = pool_obj.search_kvn_storage_volumes(self.kvc)
vols_info = {}
for vol_obj in vols_obj:
vol_name = vol_obj.get_storage_volume_name()
vols_info[vol_name] = vol_obj.get_info()
if blocks:
if vol_name in blocks and vol_name not in already_vols:
pools_iscsi_blocks[pool].append(vol_obj.get_info())
pools_vols_info[pool] = vols_info
self.view.pools = pools
self.view.pools_info = pools_info
#.........这里部分代码省略.........
示例10: _POST
# 需要导入模块: from karesansui.lib.virt.virt import KaresansuiVirtConnection [as 别名]
# 或者: from karesansui.lib.virt.virt.KaresansuiVirtConnection import list_active_guest [as 别名]
#.........这里部分代码省略.........
options["uuid"] = uuid
src_pools = kvc.get_storage_pool_name_bydomain(domname)
if not src_pools:
self.view.alert = _("Source storage pool is not found.")
self.logger.debug(self.view.alert)
return web.badrequest(self.view.alert)
for src_pool in src_pools :
src_pool_type = kvc.get_storage_pool_type(src_pool)
if src_pool_type != 'dir':
self.view.alert = _("'%s' disk contains the image.") % src_pool_type
self.logger.debug(self.view.alert)
return web.badrequest(self.view.alert)
# disk check
target_pool = kvc.get_storage_pool_name_bydomain(domname, 'os')[0]
target_path = kvc.get_storage_pool_targetpath(target_pool)
src_disk = "%s/%s/images/%s.img" % \
(target_path, options["src-name"], options["src-name"])
s_size = os.path.getsize(src_disk) / (1024 * 1024) # a unit 'MB'
if os.access(target_path, os.F_OK):
if chk_create_disk(target_path, s_size) is False:
partition = get_partition_info(target_path, header=False)
self.view.alert = _("No space available to create disk image in '%s' partition.") % partition[5][0]
self.logger.debug(self.view.alert)
return web.badrequest(self.view.alert)
#else: # Permission denied
#TODO:check disk space for root
active_guests = kvc.list_active_guest()
inactive_guests = kvc.list_inactive_guest()
used_vnc_ports = kvc.list_used_vnc_port()
used_mac_addrs = kvc.list_used_mac_addr()
conflict_location = "%s/host/%d/guest/%d.json" \
% (web.ctx.homepath, src_guest.parent_id, src_guest.id)
# source guestos
if not (options["src-name"] in active_guests or options["src-name"] in inactive_guests):
return web.conflict(conflict_location, "Unable to get the source guest.")
# Check on whether value has already been used
# destination guestos
if (options["dest-name"] in active_guests or options["dest-name"] in inactive_guests):
return web.conflict(conflict_location, "Destination guest %s is already there." % options["dest-name"])
# VNC port number
if(int(self.input.vm_vncport) in used_vnc_ports):
return web.conflict(conflict_location, "VNC port %s is already used." % self.input.vm_vncport)
# MAC address
if(self.input.vm_mac in used_mac_addrs):
return web.conflict(conflict_location, "MAC address %s is already used." % self.input.vm_mac)
# Replicate Guest
order = 0 # job order
disk_jobs = [] # Add Disk
volume_jobs = [] # Create Storage Volume
for disk in virt.get_disk_info():
if disk['type'] != 'file':
self.view.alert = _("The type of the storage pool where the disk is to be added must be 'file'. dev=%s") % disk['target']['dev']
self.logger.debug(self.view.alert)
return web.badrequest(self.view.alert)
disk_pool = kvc.get_storage_pool_name_byimage(disk['source']['file'])