Red Hat Training
A Red Hat training course is available for Red Hat Virtualization
2.18. Example: Starting a Virtual Machine using Python
Starting a virtual machine
Example 2.19. Starting a virtual machine using Python
This example starts the virtual machine using the
start
method.
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") vm = api.vms.get(name="vm1") try: vm.start() print "Started '%s'." % vm.get_name() except Exception as ex: print "Unable to start '%s': %s" % (vm.get_name(), ex) api.disconnect() except Exception as ex: print "Unexpected error: %s" % ex
If the
start
request is successful then the script will output:
Started 'vm1'.
Note that the
status
reflects that the virtual machine has been started and is now up
.