Show Table of Contents
2.20. Example: Starting a Virtual Machine with Cloud-Init using Python
Starting a virtual machine with Cloud-Init using Python.
Example 2.21. Starting a virtual machine with Cloud-Init using Python
This example shows you how to start a virtual machine using the Cloud-Init tool to set a host name and a static IP for the eth0 interface.
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.