本文整理汇总了Python中virttest.libvirt_xml.devices.disk.Disk.new_input_address方法的典型用法代码示例。如果您正苦于以下问题:Python Disk.new_input_address方法的具体用法?Python Disk.new_input_address怎么用?Python Disk.new_input_address使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类virttest.libvirt_xml.devices.disk.Disk
的用法示例。
在下文中一共展示了Disk.new_input_address方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Disk
# 需要导入模块: from virttest.libvirt_xml.devices.disk import Disk [as 别名]
# 或者: from virttest.libvirt_xml.devices.disk.Disk import new_input_address [as 别名]
dev_xml = Disk(type_name="file")
dev_xml.device = "disk"
dev_xml.source = dev_xml.new_disk_source(**{"attrs": {'file': path}})
dev_xml.driver = {"name": "qemu", "type": 'qcow2', "cache": "none"}
dev_xml.target = {"dev": 'sdb', "bus": "usb"}
dev_xml.address = dev_xml.new_disk_address(**{"attrs": attributes})
else:
if usb_type == "mouse":
dev_xml = Input("mouse")
elif usb_type == "tablet":
dev_xml = Input("tablet")
else:
dev_xml = Input("keyboard")
dev_xml.input_bus = "usb"
dev_xml.address = dev_xml.new_input_address(**{"attrs": attributes})
result = virsh.attach_device(vm_name, dev_xml.xml)
if result.exit_status:
raise error.CmdError(result.command, result)
if status_error and usb_type == "storage":
if utils_misc.wait_for(is_hotplug_ok, timeout=30):
# Sometimes we meet an error but the ret in $? is 0.
raise error.TestFail("\nAttach device successfully in negative case."
"\nExcept it fail when attach count exceed maximum."
"\nDetail: %s" % result)
for i in range(attach_count):
attach_cmd = "device_del"
if attach_type == "qemu_monitor":
示例2: run
# 需要导入模块: from virttest.libvirt_xml.devices.disk import Disk [as 别名]
# 或者: from virttest.libvirt_xml.devices.disk.Disk import new_input_address [as 别名]
#.........这里部分代码省略.........
except ShellTimeoutError as detail:
test.fail("unhotplug failed: %s, " % detail)
tmp_dir = os.path.join(data_dir.get_tmp_dir(), "usb_hotplug_files")
if not os.path.isdir(tmp_dir):
os.mkdir(tmp_dir)
try:
result = None
dev_xml = None
opt = "--hmp"
for i in range(attach_count):
if usb_type == "storage":
path = os.path.join(tmp_dir, "%s.img" % i)
libvirt.create_local_disk("file", path, size="1M", disk_format="qcow2")
os.chmod(path, 0o666)
if attach_type == "qemu_monitor":
if usb_type == "storage":
attach_cmd = "drive_add"
attach_cmd += (" 0 id=drive-usb-%s,if=none,file=%s" % (i, path))
result = virsh.qemu_monitor_command(vm_name, attach_cmd, options=opt)
if result.exit_status or (result.stdout.strip().find("OK") == -1):
raise process.CmdError(result.command, result)
attach_cmd = "device_add usb-storage,"
attach_cmd += ("id=drive-usb-%s,bus=usb1.0,drive=drive-usb-%s" % (i, i))
else:
attach_cmd = "device_add"
attach_cmd += " usb-%s,bus=usb1.0,id=%s%s" % (usb_type, usb_type, i)
result = virsh.qemu_monitor_command(vm_name, attach_cmd, options=opt)
if result.exit_status:
raise process.CmdError(result.command, result)
else:
attributes = {'type_name': "usb", 'bus': "1", 'port': "0"}
if usb_type == "storage":
dev_xml = Disk(type_name="file")
dev_xml.device = "disk"
dev_xml.source = dev_xml.new_disk_source(**{"attrs": {'file': path}})
dev_xml.driver = {"name": "qemu", "type": 'qcow2', "cache": "none"}
dev_xml.target = {"dev": 'sdb', "bus": "usb"}
dev_xml.address = dev_xml.new_disk_address(**{"attrs": attributes})
else:
if usb_type == "mouse":
dev_xml = Input("mouse")
elif usb_type == "tablet":
dev_xml = Input("tablet")
else:
dev_xml = Input("keyboard")
dev_xml.input_bus = "usb"
dev_xml.address = dev_xml.new_input_address(**{"attrs": attributes})
result = virsh.attach_device(vm_name, dev_xml.xml)
if result.exit_status:
raise process.CmdError(result.command, result)
if status_error and usb_type == "storage":
if utils_misc.wait_for(is_hotplug_ok, timeout=30):
# Sometimes we meet an error but the ret in $? is 0.
test.fail("\nAttach device successfully in negative case."
"\nExcept it fail when attach count exceed maximum."
"\nDetail: %s" % result)
for i in range(attach_count):
attach_cmd = "device_del"
if attach_type == "qemu_monitor":
if usb_type == "storage":
attach_cmd += (" drive-usb-%s" % i)
else:
if usb_type == "mouse":
attach_cmd += " mouse"
elif usb_type == "tablet":
attach_cmd += " tablet"
else:
attach_cmd += " keyboard"
result = virsh.qemu_monitor_command(vm_name, attach_cmd, options=opt)
if result.exit_status:
raise process.CmdError(result.command, result)
else:
result = virsh.detach_device(vm_name, dev_xml.xml)
if result.exit_status:
raise process.CmdError(result.command, result)
except process.CmdError as e:
if not status_error:
# live attach of device 'input' is not supported
ret = result.stderr.find("Operation not supported")
if usb_type != "storage" and ret > -1:
pass
else:
test.fail("failed to attach device.\nDetail: %s." % result)
finally:
session.close()
if os.path.isdir(tmp_dir):
shutil.rmtree(tmp_dir)
utils_selinux.set_status(backup_sestatus)
vm_xml_backup.sync()