本文整理汇总了Python中virttest.libvirt_xml.devices.disk.Disk.xml方法的典型用法代码示例。如果您正苦于以下问题:Python Disk.xml方法的具体用法?Python Disk.xml怎么用?Python Disk.xml使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类virttest.libvirt_xml.devices.disk.Disk
的用法示例。
在下文中一共展示了Disk.xml方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: set_domain_disk
# 需要导入模块: from virttest.libvirt_xml.devices.disk import Disk [as 别名]
# 或者: from virttest.libvirt_xml.devices.disk.Disk import xml [as 别名]
def set_domain_disk(vmxml, blk_source, params, test):
"""
Replace the domain disk with new setup device or download image
:param vmxml: The instance of VMXML class
:param params: Avocado params object
:param test: Avocado test object
:param blk_source: The domain disk image path
"""
disk_type = params.get("disk_type", "file")
boot_dev = params.get("boot_dev", "hd")
target_dev = params.get("target_dev", "vdb")
device_bus = params.get("device_bus", "virtio")
disk_img = params.get("disk_img")
image_size = params.get("image_size", "3G")
vol_name = params.get("vol_name")
disk_format = params.get("disk_format", "qcow2")
driver_type = params.get("driver_type", "qcow2")
mon_host = params.get("mon_host")
disk_src_name = params.get("disk_source_name")
disk_src_host = params.get("disk_source_host")
disk_src_port = params.get("disk_source_port")
source_protocol = params.get("source_protocol", "")
boot_iso_file = os.path.join(data_dir.get_tmp_dir(), "boot.iso")
non_release_os_url = params.get("non_release_os_url", "")
download_file_path = os.path.join(data_dir.get_tmp_dir(), "non_released_os.qcow2")
brick_path = os.path.join(test.virtdir, "gluster-pool")
global cleanup_iscsi
global cleanup_gluster
disk_params = {'disk_type': disk_type,
'target_dev': target_dev,
'target_bus': device_bus,
'driver_type': driver_type}
if source_protocol == 'iscsi':
if disk_type == 'block':
kwargs = {'image_size': image_size, 'disk_format': disk_format}
iscsi_target = prepare_iscsi_disk(blk_source, **kwargs)
if iscsi_target is None:
test.error("Failed to create iscsi disk")
else:
cleanup_iscsi = True
disk_params.update({'source_file': iscsi_target})
elif source_protocol == 'gluster':
if disk_type == 'network':
kwargs = {'vol_name': vol_name,
'brick_path': brick_path,
'disk_img': disk_img,
'disk_format': disk_format}
host_ip = prepare_gluster_disk(blk_source, test, **kwargs)
if host_ip is None:
test.error("Failed to create glusterfs disk")
else:
cleanup_gluster = True
source_name = "%s/%s" % (vol_name, disk_img)
disk_params.update({'source_name': source_name,
'source_host_name': host_ip,
'source_host_port': '24007',
'source_protocol': source_protocol})
elif source_protocol == 'rbd':
if disk_type == 'network':
disk_path = ("rbd:%s:mon_host=%s" %
(disk_src_name, mon_host))
disk_cmd = ("qemu-img convert -O %s %s %s"
% (disk_format, blk_source, disk_path))
process.run(disk_cmd, ignore_status=False)
disk_params.update({'source_name': disk_src_name,
'source_host_name': disk_src_host,
'source_host_port': disk_src_port,
'source_protocol': source_protocol})
elif non_release_os_url:
disk_params.update({'source_file': download_file_path})
elif boot_dev == "cdrom":
disk_params.update({'device_type': 'cdrom',
'source_file': boot_iso_file})
else:
disk_params.update({'source_file': blk_source})
new_disk = Disk(type_name=disk_type)
new_disk.xml = open(create_disk_xml(disk_params)).read()
vmxml.remove_all_disk()
vmxml.add_device(new_disk)