本文整理汇总了Python中karesansui.lib.virt.virt.KaresansuiVirtConnection.domname_to_uuid方法的典型用法代码示例。如果您正苦于以下问题:Python KaresansuiVirtConnection.domname_to_uuid方法的具体用法?Python KaresansuiVirtConnection.domname_to_uuid怎么用?Python KaresansuiVirtConnection.domname_to_uuid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类karesansui.lib.virt.virt.KaresansuiVirtConnection
的用法示例。
在下文中一共展示了KaresansuiVirtConnection.domname_to_uuid方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: process
# 需要导入模块: from karesansui.lib.virt.virt import KaresansuiVirtConnection [as 别名]
# 或者: from karesansui.lib.virt.virt.KaresansuiVirtConnection import domname_to_uuid [as 别名]
def process(self):
(opts, args) = getopts()
chkopts(opts)
self.up_progress(10)
conn = KaresansuiVirtConnection(readonly=False)
try:
uuid = conn.domname_to_uuid(opts.name)
try: # physical
conn.set_domain_name(opts.name)
conn.delete_guest(opts.name, opts.pool, opts.volume)
self.up_progress(20)
except Exception, e:
print >>sys.stderr, '[Warn] Failed to delete the guest OS physical. - dom=%s - detail : %s' \
% (opts.name, str(e.args))
self.logger.warn('Failed to delete the guest OS physical. - dom=%s - detail : %s' \
% (opts.name, str(e.args)))
# Check the presence of residual files
try:
self.up_progress(10)
# /etc
config = ""
hypervisor = conn.get_hypervisor_type()
if hypervisor == "XEN":
config = "%s/%s" % (XEN_VIRT_CONFIG_DIR, opts.name,)
elif hypervisor == "KVM" or hypervisor == "QEMU":
config = "%s/%s" % (KVM_VIRT_CONFIG_DIR, opts.name,)
if os.path.isfile(config) is True:
os.remove(config)
self.logger.info("physical config remove. - path=%s" % config)
self.up_progress(5)
xml_config = '%s/%s.xml' % (VIRT_XML_CONFIG_DIR, opts.name)
if os.path.isfile(xml_config) is True:
os.remove(xml_config)
self.logger.info("physical xml config remove. - path=%s" % xml_config)
self.up_progress(5)
self.logger.info('To remove the storage volume even more.')
tmp_pool = conn.get_storage_pool_name_bydomain(opts.name, 'os')
if tmp_pool:
domains_dir = conn.get_storage_pool_targetpath(tmp_pool[0])
else:
domains_dir = conn.get_storage_pool_targetpath(opts.pool)
disk_image = '%s/%s/images/%s.img' % (domains_dir, opts.name, opts.name,)
if os.path.isfile(disk_image) is True or os.path.islink(disk_image) is True:
os.remove(disk_image)
self.logger.info("physical disk image remove. - path=%s" % disk_image)
self.up_progress(5)
if 0 < len(opts.name.split()): # double check
snapshot_dir = '%s/%s/snapshot' % (domains_dir, opts.name,)
if os.path.isdir(snapshot_dir) is True:
for root, dirs, files in os.walk(snapshot_dir):
for fname in files:
file_path = os.path.join(root, fname)
os.remove(file_path)
self.logger.info("physical snapshots file remove. - file=%s" % file_path)
os.removedirs(snapshot_dir)
self.logger.info("physical snapshots directory remove. - dir=%s" % snapshot_dir)
self.up_progress(5)
if 0 < len(opts.name.split()): # double check
disk_dir = '%s/%s/disk' % (domains_dir, opts.name,)
if os.path.isdir(disk_dir) is True:
for root, dirs, files in os.walk(disk_dir):
for fname in files:
file_path = os.path.join(root, fname)
os.remove(file_path)
self.logger.info("physical disk file remove. - file=%s" % file_path)
os.removedirs(disk_dir)
self.logger.info("physical disk directory remove. - dir=%s" % disk_dir)
self.up_progress(5)
# Delete GuestOS directory
domain_dir = "%s/%s" % (domains_dir, opts.name)
if os.path.isdir(domain_dir) is True:
shutil.rmtree(domain_dir)
self.up_progress(5)
except Exception, e:
print >>sys.stderr, '[Warn] Failed to remove the residual file.. - dom=%s - detail : %s' \
% (opts.name, str(e.args))
self.logger.warn('Failed to remove the residual file.. - dom=%s - detail : %s' \
% (opts.name, str(e.args)))
示例2: process
# 需要导入模块: from karesansui.lib.virt.virt import KaresansuiVirtConnection [as 别名]
# 或者: from karesansui.lib.virt.virt.KaresansuiVirtConnection import domname_to_uuid [as 别名]
def process(self):
(opts, args) = getopts()
chkopts(opts)
self.up_progress(10)
conn = KaresansuiVirtConnection(readonly=False)
try:
try:
src_pool = conn.get_storage_pool_name_bydomain(opts.name, "os")
if not src_pool:
raise KssCommandException("Source storage pool not found. domain=%s" % (opts.name))
if conn.get_storage_pool_type(src_pool) == 'dir':
raise KssCommandException("Storage pool type 'dir' is not. domain=%s" % (opts.name))
src_path = conn.get_storage_pool_targetpath(src_pool[0])
self.domain_dir = "%s/%s" % (src_path, opts.name,)
if os.path.isdir(self.domain_dir) is False:
raise KssCommandException(
'domain directory is not found or not directory. - %s' % (self.domain_dir))
# Model
virt_uuid = conn.domname_to_uuid(opts.name)
model = findby1uniquekey(self.kss_session, virt_uuid)
if not model:
raise KssCommandException("Export data does not exist in the database.")
database = {}
database['attribute'] = model.attribute
database['hypervisor'] = model.hypervisor
database['icon'] = model.icon
database['name'] = model.name
database['notebook'] = {"title" : model.notebook.title,
"value" : model.notebook.value,
}
tags = []
for _tag in model.tags:
tags.append(_tag.name)
database['tags'] = ",".join(tags)
database['uniq_key'] = model.uniq_key
# Snapshot
snapshots = []
kvs = KaresansuiVirtSnapshot(readonly=False)
try:
guest_id = model.id
snapshot_list = kvs.listNames(opts.name)[opts.name]
if len(snapshot_list) > 0:
for snapshot in snapshot_list:
s_model = s_findbyname_guestby1(self.kss_session, snapshot, guest_id)
if s_model is not None:
name = s_model.name
title = s_model.notebook.title
value = s_model.notebook.value
snapshots.append({"name":name, "title":title, "value":value,})
except:
raise KssCommandException("Cannot fetch the information of snapshots correctly.")
kvs.finish()
# Pool
target_dir = ""
if opts.pool:
inactive_storage_pools = conn.list_inactive_storage_pool()
active_storage_pools = conn.list_active_storage_pool()
if not (opts.pool in active_storage_pools or opts.pool in inactive_storage_pools):
raise KssCommandException('Target storage pool does not exist. - pool=%s' % (opts.pool))
pool = conn.search_kvn_storage_pools(opts.pool)
storage_info = pool[0].get_info()
if storage_info["type"] == "dir" and storage_info["target"]["path"] != "":
target_dir = storage_info["target"]["path"]
else:
raise KssCommandException("Target storage pool type is not 'dir'. pool=%s" % (opts.pool))
elif opts.dir:
target_dir = opts.dir
self.up_progress(10)
progresscb = None
if opts.verbose:
try:
from karesansui.lib.progress import ProgressMeter
progresscb = ProgressMeter(command_object=self)
except:
pass
else:
try:
from karesansui.lib.progress import ProgressMeter
progresscb = ProgressMeter(command_object=self,quiet=True)
except:
pass
if opts.title[0:4] == "b64:":
title = base64_decode(opts.title[4:])
else:
title = opts.title
uuid = StrFromUUID(GenUUID())
conn.export_guest(uuid=uuid,
name=opts.name,
#.........这里部分代码省略.........