2.20. 例:Python を使用した Cloud-Init での仮想マシンの起動
Python を使用して Cloud-Init で仮想マシンの起動
例2.21 Python を使用した Cloud-Init での仮想マシンの起動
この例は、Cloud-Init ツールを使用して仮想マシンを起動し、eth0 インターフェイスのホスト名と静的 IP を設定する方法を示しています。
from ovirtsdk.api import API
from ovirtsdk.xml import params
try:
api = API (url="https://HOST",
username="USER@DOMAIN",
password="PASS",
ca_file="ca.crt")
except Exception as ex:
print "Failed to connect to API: %s" % ex
try:
vm = api.vms.get(name="MyVM")
except Exception as ex:
print "Failed to retrieve VM: %s" % ex
try:
vm.start(
use_cloud_init=True,
action=params.Action(
vm=params.VM(
initialization=params.Initialization(
cloud_init=params.CloudInit(
host=params.Host(address="MyHost.example.com"),
network_configuration=params.NetworkConfiguration(
nics=params.Nics(
nic=[params.NIC(
name="eth0",
boot_protocol="static",
on_boot=True,
network=params.Network(
ip=params.IP(
address="10.10.10.1",
netmask="255.255.255.0",
gateway="10.10.10.1"
)
)
)
]
)
)
)
)
)
)
)
except Exception as ex:
print "Failed to start VM: %s" % ex