Show Table of Contents
2.20. 例: Python を使用した Cloud-Init での仮想マシンの起動
Python を使用して Cloud-Init で仮想マシンを起動します。
例2.21 Python を使用した Cloud-Init での仮想マシンの起動
以下の例では、Cloud-Init ツールを使用して仮想マシンを起動し、etho0 インターフェースの静的 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(
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

Where did the comment section go?
Red Hat's documentation publication system recently went through an upgrade to enable speedier, more mobile-friendly content. We decided to re-evaluate our commenting platform to ensure that it meets your expectations and serves as an optimal feedback mechanism. During this redesign, we invite your input on providing feedback on Red Hat documentation via the discussion platform.