rapi.rst 1.8 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
Ganeti remote API
=================

Documents Ganeti version 2.0

.. contents::

Introduction
------------

Ganeti supports a remote API for enable external tools to easily
retrieve information about a cluster's state. The remote API daemon,
*ganeti-rapi*, is automatically started on the master node. By default
it runs on TCP port 5080, but this can be changed either in
``.../constants.py`` or via the command line parameter *-p*. SSL mode,
which is used by default, can also be disabled by passing command line
parameters.

Protocol
--------

The protocol used is JSON_ over HTTP designed after the REST_
principle.

.. _JSON: http://www.json.org/
.. _REST: http://en.wikipedia.org/wiki/Representational_State_Transfer

Usage examples
--------------

You can access the API using your favorite programming language as
long as it supports network connections.

Shell
+++++

Using wget::

  wget -q -O - https://CLUSTERNAME:5080/2/info

or curl::

  curl https://CLUSTERNAME:5080/2/info


Python
++++++

::

  import urllib2
Tim Boring's avatar
Tim Boring committed
52
  f = urllib2.urlopen('https://CLUSTERNAME:5080/2/info')
53 54 55 56 57 58 59 60 61 62 63 64 65
  print f.read()


JavaScript
++++++++++

.. warning:: While it's possible to use JavaScript, it poses several potential
  problems, including browser blocking request due to
  non-standard ports or different domain names. Fetching the data
  on the webserver is easier.

::

Tim Boring's avatar
Tim Boring committed
66
  var url = 'https://CLUSTERNAME:5080/2/info';
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
  var info;
  var xmlreq = new XMLHttpRequest();
  xmlreq.onreadystatechange = function () {
    if (xmlreq.readyState != 4) return;
    if (xmlreq.status == 200) {
      info = eval("(" + xmlreq.responseText + ")");
      alert(info);
    } else {
      alert('Error fetching cluster info');
    }
    xmlreq = null;
  };
  xmlreq.open('GET', url, true);
  xmlreq.send(null);

Resources
---------

.. include:: rapi-resources.gen