3.19. 使用 Overridden 参数启动虚拟机
您可以启动虚拟机覆盖其默认参数。
例 3.17. 使用覆盖的参数启动虚拟机
本示例使用 Windows ISO 引导虚拟机并附加 virtio-win_x86.vfd
软盘磁盘,其中包含 Windows 驱动程序。此操作等同于使用管理门户中的 Run Once 窗口启动虚拟机。
V4
import time import ovirtsdk4 as sdk import ovirtsdk4.types as types connection = sdk.Connection( url='https://engine.example.com/ovirt-engine/api', username='admin@internal', password='password', ca_file='ca.pem', ) # Get the reference to the "vms" service: vms_service = connection.system_service().vms_service() # Find the virtual machine: vm = vms_service.list(search='name=vm1')[0] # Locate the service that manages the virtual machine: vm_service = vms_service.vm_service(vm.id) # Locate the service that manages the CDROM devices of the virtual machine: cdroms_service = vm_service.cdroms_service() # Get the first CDROM: cdrom = cdroms_service.list()[0] # Locate the service that manages the CDROM device found in previous step: cdrom_service = cdroms_service.cdrom_service(cdrom.id) # Change the CD of the VM to 'windows_example.iso': cdrom_service.update( cdrom=types.Cdrom( file=types.File( id='windows_example.iso' ), ), current=False, ) # Call the "start" method of the service to start it: vm_service.start( vm=types.Vm( os=types.OperatingSystem( boot=types.Boot( devices=[ types.BootDevice.CDROM, ] ) ), ) ) # Wait until the virtual machine's status is "UP": while True: time.sleep(5) vm = vm_service.get() if vm.status == types.VmStatus.UP: break print("Started '%s'." % vm.name()) # Close the connection to the server: connection.close()
注意
CD 映像和软盘文件必须可供虚拟机使用。详情请参阅将镜像上传到数据存储域。