3.13. 仮想マシンの作成
仮想マシンの作成は、いくつかの手順で実行されます。ここで説明する最初の手順は、仮想マシンオブジェクト自体を作成することです。
例3.11 仮想マシンの作成
この例では、次の要件を持つ仮想マシン vm1 を作成します。
- 512MB のメモリー (バイト単位)。
-
Defaultクラスターにアタッチされており、したがってDefaultデータセンターにアタッチされている。 -
デフォルトの
Blankテンプレートに基づく。 - 仮想ハードディスクドライブから起動する。
V4
V4 では、オプションは add メソッドを使用して types として追加されます。
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()
# Use the "add" method to create a new virtual machine:
vms_service.add(
types.Vm(
name='vm1',
memory = 512*1024*1024
cluster=types.Cluster(
name='Default',
),
template=types.Template(
name='Blank',
),
os=types.OperatingSystem(boot=types.Boot(devices=[types.BootDevice.HD)]
),
)
print("Virtual machine '%s' added." % vm.name)
# Close the connection to the server:
connection.close()
add リクエストが成功すると、例は次のテキストを出力します。
Virtual machine 'vm1' added.