1 <!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook V4.2//EN" [
2 <!ENTITY JsonLink "http://www.json.org/">
3 <!ENTITY WikipediaRESTLink
4 "http://en.wikipedia.org/wiki/Representational_State_Transfer">
6 <article class="specification">
8 <title>Ganeti remote API</title>
11 <para>Documents Ganeti version 1.2</para>
14 <title>Introduction</title>
16 <para>Ganeti supports a remote API for enable external tools to easily
17 retrieve information about a cluster's state. The remote API daemon,
18 <computeroutput>ganeti-rapi</computeroutput>, is automatically started on
19 the master node if the <computeroutput>--enable-rapi</computeroutput>
20 parameter is passed to the <computeroutput>configure</computeroutput>
21 script. Alternatively you can start it manually. By default it runs on TCP
22 port 5080, but this can be changed either in
23 <filename>…/constants.py</filename> or via the command line
24 parameter <computeroutput>-p</computeroutput>. SSL support can also be
25 enabled by passing command line parameters.</para>
28 <para>Ganeti 1.2 only supports a limited set of calls, all of them
29 read-only. The next major version will have support for write
35 <title>Protocol</title>
37 <para>The protocol used is <ulink url="&JsonLink;">JSON</ulink> over HTTP
38 designed after the <ulink url="&WikipediaRESTLink;">REST</ulink> principle.
43 <title>Usage examples</title>
45 <para>You can access the API using your favorite programming language as long
46 as it supports network connections.</para>
50 <screen>wget -q -O - http://<replaceable>CLUSTERNAME</replaceable>:5080/info</screen>
55 <screen>import urllib2
56 f = urllib2.urlopen('http://<replaceable>CLUSTERNAME</replaceable>:5080/info')
57 print f.read()</screen>
61 <title>JavaScript</title>
63 <para>While it's possible to use JavaScript, it poses several potential
64 problems, including browser blocking request due to non-standard ports
65 or different domain names. Fetching the data on the webserver is
68 <screen>var url = 'http://<replaceable>CLUSTERNAME</replaceable>:5080/info';
71 var xmlreq = new XMLHttpRequest();
72 xmlreq.onreadystatechange = function () {
73 if (xmlreq.readyState != 4) return;
74 if (xmlreq.status == 200) {
75 info = eval("(" + xmlreq.responseText + ")");
78 alert('Error fetching cluster info');
82 xmlreq.open('GET', url, true);
83 xmlreq.send(null);</screen>
89 <title>Resources</title>
90 @INCLUDE_RAPI_RESOURCES@