Show Table of Contents
2.19. 示例:使用 Python 启动覆盖参数的虚拟机
启动覆盖参数的虚拟机
例 2.20. 使用 Python 启动覆盖参数的虚拟机
这个示例演示了如何使用 Windows ISO 启动虚拟机,并附加包含 Windows 驱动程序的
virtio-win_x86.vfd 软盘。这个动作与使用管理或用户门户网站中的 Run Once 窗口启动虚拟机一致。
from ovirtsdk.api import API
from ovirtsdk.xml import params
try:
api = API (url="https://HOST",
username="USER@DOMAIN",
password="PASS",
ca_file="ca.crt")
except Exception as ex:
print "Failed to connect to API: %s" % ex
try:
vm = api.vms.get(name="Win_machine")
except Exception as ex:
print "Failed to retrieve VM: %s" % ex
cdrom = params.CdRom(file=params.File(id="windows_example.iso"))
floppy = params.Floppy(file=params.File(id="virtio-win_x86.vfd"))
try:
vm.start(
action=params.Action(
vm=params.VM(
os=params.OperatingSystem(
boot=[params.Boot(dev="cdrom")]
),
cdroms=params.CdRoms(cdrom=[cdrom]),
floppies=params.Floppies(floppy=[floppy])
)
)
)
except Exception as ex:
print "Failed to start VM: %s" % ex
注意
CD 镜像和软盘文件需要已存在于 ISO 域中。如果还没有存在于 ISO 域中,使用 ISO 上传工具来它们上传到域中。如需了解更多相关信息,请参阅 The ISO Uploader Tool。

Where did the comment section go?
Red Hat's documentation publication system recently went through an upgrade to enable speedier, more mobile-friendly content. We decided to re-evaluate our commenting platform to ensure that it meets your expectations and serves as an optimal feedback mechanism. During this redesign, we invite your input on providing feedback on Red Hat documentation via the discussion platform.