3.16. ISO イメージの仮想マシンへのアタッチ
新しく作成した仮想マシンにゲストオペレーティングシステムをインストールするには、オペレーティングシステムのインストールメディアを含む ISO ファイルをアタッチする必要があります。ISO ファイルを見つけるには、ISO ストレージドメイン内のファイルの一覧表示 参照してください。
例3.14 仮想マシンへの ISO イメージのアタッチ
この例では、仮想マシンの cdroms
コレクションの add
メソッドを使用して、my_iso_file.iso を vm1
仮想マシンにアタッチします。
V4
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 'my_iso_file.iso'. By default the # operation permanently changes the disk that is visible to the # virtual machine after the next boot, but has no effect # on the currently running virtual machine. If you want to change the # disk that is visible to the current running virtual machine, change # the `current` parameter's value to `True`. cdrom_service.update( cdrom=types.Cdrom( file=types.File( id='my_iso_file.iso' ), ), current=False, ) print("Attached CD to '%s'." % vm.name()) # Close the connection to the server: connection.close()
add
リクエストが成功すると、例は次のテキストを出力します。
Attached CD to 'vm1'.
例3.15 仮想マシンからの CD-ROM の取り出し
この例では、仮想マシンの cdrom
コレクションから ISO イメージを取り出します。
V4
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 VM: cdroms_service = vm_service.cdroms_service() # Get the first found CDROM: cdrom = cdroms_service.list()[0] # Locate the service that manages the CDROM device found in previous step # of the VM: cdrom_service = cdroms_service.cdrom_service(cdrom.id) cdrom_service.remove() print("Removed CD from '%s'." % vm.name()) connection.close()
delete
または remove
リクエストが成功すると、例は次のテキストを出力します。
Removed CD from 'vm1'.