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 three different source where information relating to the RAPI can be found.
  1. The Ganeti RAPI PyDocs
  2. The Ganeti RAPI HTMLDocs.
  3. The gnt-instance man page.
  4. The rapi client code contained in the upstream ganeti project.
  5. The rapi tests which are also contained in the upstream ganeti project.

RAPI in a Python Shell

  1. Start up a python shell using the manage django script.
    $ ./ shell
  2. In the python shell import from util.
    >>> from util import client
  3. 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:
    >>> pp(rapi.GetInfo())
  • RAPI commands can now be accessed as functions of the rapi variable.
    >>> rapi.GetInstance('my.test.instance')