3.19. パラメーターのオーバーライドによる仮想マシンの起動
デフォルトのパラメーターをオーバーライドして、仮想マシンを起動できます。
例3.17 パラメーターのオーバーライドによる仮想マシンの起動
この例では、Windows ISO を使用して仮想マシンを起動し、Windows ドライバーを含む virtio-win_x86.vfd
フロッピーディスクをアタッチします。この操作は、管理ポータルの 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 イメージとフロッピーディスクファイルが仮想マシンで利用可能である必要があります。詳細は、データストレージドメインへのイメージのアップロード を参照してください。