4.2. Example: Accessing the API Entry Point using Python
The ovirtsdk Python library provides the
API class, which acts as the entry point for the API.
Example 4.1. Accessing the API entry point using Python
This python example connects to an instance of the REST API provided by the Red Hat Enterprise Virtualization Manager at
rhevm.demo.redhat.com. To connect the example creates an instance of the API class If connection was successful a message is printed. Finally the disconnect() method of the API class is called to close the connection.
The parameters provided to the constructor for the
The constructor for the
API class in this example are:
- The
urlof the Manager to connect to. - The
usernameof the user to authenticate as. - The
passwordof the user to authenticate as. - The
ca_filewhich is the path to a certificate. The certificate is expected to be a copy of the one for the Manager's Certificate Authority. It can be obtained fromhttps://HOST/ca.crt.
API class supports other parameters. Only mandatory parameters are specified in this example.
from ovirtsdk.api import API from ovirtsdk.xml import params try: api = API (url="https://HOST", username="USER", password="PASS", ca_file="ca.crt") print "Connected to %s successfully!" % api.get_product_info().name api.disconnect() except Exception as ex: print "Unexpected error: %s" % ex
If the connection attempt was successful, the example outputs the text:
Connected to Red Hat Enterprise Virtualization Manager successfully!