Working With The RAPI¶
There are several places to view documentation detailing how to interface with the python RAPI, though none of them are comprehensive.
The following is a list of five different sources where information relating to the RAPI can be found.
The Ganeti RAPI PyDocs
The Ganeti RAPI HTML Docs
The gnt-instance man-page
The rapi client code contained in the upstream ganeti project
The rapi-tests which are also contained in the upstream ganeti project
RAPI in a Python Shell¶
Start up a python shell using the
manage.py django script.
$ ./ganeti_webmgr/manage.py shell
In the python shell import
>>> from util import client
Assign a variable to the rapi client and pass in the name of the cluster as a string to the GanetiRapiClient object.
>>> rapi = client.GanetiRapiClient('my.test.cluster')
Note - For R/W access to the cluster you need to pass in ‘username’ and ‘password’ as kwargs to the GanetiRapiClient object. Replace USERNAME and PASSWORD with the correct cluster R/W credentials
>>> rapi = client.GanetiRapiClient('my.test.cluster', username='USERNAME', password='PASSWORD')
Optional - Setup PrettyPrinter to prettify the output of RAPI functions that return dictionaries.
>>> import pprint >>> pp = pprint.PrettyPrinter(indent=4).pprint
Now you are able to prettify output like this:
RAPI commands can now be accessed as functions of the rapi variable.