3.19. Overridden 매개변수를 사용하여 가상 머신 시작

가상 머신을 시작하여 기본 매개변수를 재정의할 수 있습니다.

예 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 이미지와 플로피 디스크 파일은 가상 머신에서 사용할 수 있어야 합니다. 자세한 내용은 데이터 스토리지 도메인에 이미지 업로드 를 참조하십시오.