本文整理汇总了Python中virttest.libvirt_xml.devices.disk.Disk.new_auth方法的典型用法代码示例。如果您正苦于以下问题:Python Disk.new_auth方法的具体用法?Python Disk.new_auth怎么用?Python Disk.new_auth使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类virttest.libvirt_xml.devices.disk.Disk
的用法示例。
在下文中一共展示了Disk.new_auth方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run
# 需要导入模块: from virttest.libvirt_xml.devices.disk import Disk [as 别名]
# 或者: from virttest.libvirt_xml.devices.disk.Disk import new_auth [as 别名]
#.........这里部分代码省略.........
pool_name = params.get("pool_name", "nfs_pool")
pool_target = params.get("pool_target", "nfs_mount")
pool_type = params.get("pool_type", "netfs")
nfs_server_dir = params.get("nfs_server_dir", "nfs_server")
emulated_image = params.get("emulated_image")
image_name = params.get("nfs_image_name", "nfs.img")
tmp_dir = data_dir.get_tmp_dir()
pvt = libvirt.PoolVolumeTest(test, params)
pvt.pre_pool(pool_name, pool_type, pool_target, emulated_image)
nfs_mount_dir = os.path.join(tmp_dir, pool_target)
device_source = nfs_mount_dir + image_name
disk_src_dict = {'attrs': {'file': device_source,
'type_name': 'file'}}
else:
test.cancel("Only iscsi/gluster/rbd/nfs can be tested for now.")
logging.debug("device source is: %s", device_source)
luks_sec_uuid = libvirt.create_secret(params)
logging.debug("A secret created with uuid = '%s'", luks_sec_uuid)
ret = virsh.secret_set_value(luks_sec_uuid, luks_secret_passwd,
encode=True, debug=True)
encrypt_dev(device_source, params)
libvirt.check_exit_status(ret)
# Add disk xml.
vmxml = vm_xml.VMXML.new_from_dumpxml(vm_name)
disk_xml = Disk(type_name=device_type)
disk_xml.device = device
disk_xml.target = {"dev": device_target, "bus": device_bus}
driver_dict = {"name": "qemu", "type": device_format}
disk_xml.driver = driver_dict
disk_source = disk_xml.new_disk_source(**disk_src_dict)
if disk_auth_dict:
logging.debug("disk auth dict is: %s" % disk_auth_dict)
if auth_in_source:
disk_source.auth = disk_xml.new_auth(**disk_auth_dict)
else:
disk_xml.auth = disk_xml.new_auth(**disk_auth_dict)
disk_encryption_dict = {"encryption": "luks",
"secret": {"type": "passphrase",
"uuid": luks_sec_uuid}}
disk_encryption = disk_xml.new_encryption(**disk_encryption_dict)
if encryption_in_source:
disk_source.encryption = disk_encryption
else:
disk_xml.encryption = disk_encryption
disk_xml.source = disk_source
logging.debug("new disk xml is: %s", disk_xml)
# Sync VM xml
if not hotplug_disk:
vmxml.add_device(disk_xml)
vmxml.sync()
try:
vm.start()
vm.wait_for_login()
except virt_vm.VMStartError as details:
# When use wrong password in disk xml for cold plug cases,
# VM cannot be started
if status_error and not hotplug_disk:
logging.info("VM failed to start as expected: %s" % str(details))
else:
test.fail("VM should start but failed: %s" % str(details))
if hotplug_disk:
result = virsh.attach_device(vm_name, disk_xml.xml,
ignore_status=True, debug=True)
libvirt.check_exit_status(result, status_error)
if check_partitions and not status_error:
if not check_in_vm(device_target, old_parts):
示例2: Controller
# 需要导入模块: from virttest.libvirt_xml.devices.disk import Disk [as 别名]
# 或者: from virttest.libvirt_xml.devices.disk.Disk import new_auth [as 别名]
disk_xml.driver = driver_dict
# Check if we want to use a faked uuid.
if not uuid:
uuid = secret_uuid
auth_dict = {}
if auth_uuid:
auth_dict = {"auth_user": chap_user,
"secret_type": secret_usage_type,
"secret_uuid": uuid}
elif auth_usage:
auth_dict = {"auth_user": chap_user,
"secret_type": secret_usage_type,
"secret_usage": secret_usage_target}
if auth_dict:
disk_xml.auth = disk_xml.new_auth(**auth_dict)
# Sync VM xml.
vmxml.add_device(disk_xml)
# After virtio 1.0 is enabled, lun type device need use virtio-scsi
# instead of virtio, so addtional controller is needed.
# Add controller.
if device == "lun":
ctrl = Controller(type_name=cntlr_type)
if cntlr_model is not None:
ctrl.model = cntlr_model
if cntlr_index is not None:
ctrl.index = cntlr_index
ctrl_addr_dict = {}
for addr_option in controller_addr_options.split(','):
if addr_option != "":
示例3: run
# 需要导入模块: from virttest.libvirt_xml.devices.disk import Disk [as 别名]
# 或者: from virttest.libvirt_xml.devices.disk.Disk import new_auth [as 别名]
#.........这里部分代码省略.........
vmxml = vm_xml.VMXML.new_from_dumpxml(vm_name)
disk_xml = Disk(type_name=device_type)
disk_xml.device = device
disk_xml.target = {"dev": device_target, "bus": device_bus}
driver_dict = {"name": "qemu", "type": device_format}
# For lun type device, iothread attribute need to be set in controller.
if driver_iothread and device != "lun":
driver_dict.update({"iothread": driver_iothread})
vmxml.iothreads = int(driver_iothread)
elif driver_iothread:
vmxml.iothreads = int(driver_iothread)
disk_xml.driver = driver_dict
# Check if we want to use a faked uuid.
if not uuid:
uuid = secret_uuid
auth_dict = {}
if auth_uuid:
auth_dict = {"auth_user": chap_user,
"secret_type": secret_usage_type,
"secret_uuid": uuid}
elif auth_usage:
auth_dict = {"auth_user": chap_user,
"secret_type": secret_usage_type,
"secret_usage": secret_usage_target}
disk_source = disk_xml.new_disk_source(
**{"attrs": {"protocol": "iscsi",
"name": "%s/%s" % (iscsi_target, lun_num)},
"hosts": [{"name": iscsi_host, "port": iscsi_port}]})
if auth_dict:
disk_auth = disk_xml.new_auth(**auth_dict)
if 'source' in auth_place_in_location:
disk_source.auth = disk_auth
if 'disk' in auth_place_in_location:
disk_xml.auth = disk_auth
disk_xml.source = disk_source
# Sync VM xml.
vmxml.add_device(disk_xml)
# After virtio 1.0 is enabled, lun type device need use virtio-scsi
# instead of virtio, so additional controller is needed.
# Add controller.
if device == "lun":
ctrl = Controller(type_name=cntlr_type)
if cntlr_model is not None:
ctrl.model = cntlr_model
if cntlr_index is not None:
ctrl.index = cntlr_index
ctrl_addr_dict = {}
for addr_option in controller_addr_options.split(','):
if addr_option != "":
addr_part = addr_option.split('=')
ctrl_addr_dict.update({addr_part[0].strip(): addr_part[1].strip()})
ctrl.address = ctrl.new_controller_address(attrs=ctrl_addr_dict)
# If driver_iothread is true, need add iothread attribute in controller.
if driver_iothread:
ctrl_driver_dict = {}
ctrl_driver_dict.update({"iothread": driver_iothread})
ctrl.driver = ctrl_driver_dict
logging.debug("Controller XML is:%s", ctrl)
if cntlr_type: