本文整理汇总了Python中karesansui.lib.virt.virt.KaresansuiVirtConnection.get_hypervisor_type方法的典型用法代码示例。如果您正苦于以下问题:Python KaresansuiVirtConnection.get_hypervisor_type方法的具体用法?Python KaresansuiVirtConnection.get_hypervisor_type怎么用?Python KaresansuiVirtConnection.get_hypervisor_type使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类karesansui.lib.virt.virt.KaresansuiVirtConnection
的用法示例。
在下文中一共展示了KaresansuiVirtConnection.get_hypervisor_type方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: process
# 需要导入模块: from karesansui.lib.virt.virt import KaresansuiVirtConnection [as 别名]
# 或者: from karesansui.lib.virt.virt.KaresansuiVirtConnection import get_hypervisor_type [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)))