root / doc / rapi.sgml @ 74aa2478
History | View | Annotate | Download (2.5 kB)
1 | 4cbd4462 | Oleksiy Mishchenko | <!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook V4.2//EN" [ |
---|---|---|---|
2 | 4cbd4462 | Oleksiy Mishchenko | <!ENTITY JsonLink "http://www.json.org/"> |
3 | 4cbd4462 | Oleksiy Mishchenko | <!ENTITY WikipediaRESTLink |
4 | 4cbd4462 | Oleksiy Mishchenko | "http://en.wikipedia.org/wiki/Representational_State_Transfer"> |
5 | 4cbd4462 | Oleksiy Mishchenko | ]> |
6 | 4cbd4462 | Oleksiy Mishchenko | <article class="specification"> |
7 | 4cbd4462 | Oleksiy Mishchenko | <articleinfo> |
8 | 4cbd4462 | Oleksiy Mishchenko | <title>Ganeti remote API</title> |
9 | 4cbd4462 | Oleksiy Mishchenko | </articleinfo> |
10 | 4cbd4462 | Oleksiy Mishchenko | |
11 | bf4a90af | Iustin Pop | <para>Documents Ganeti version 2.0</para> |
12 | 4cbd4462 | Oleksiy Mishchenko | |
13 | 4cbd4462 | Oleksiy Mishchenko | <sect1> |
14 | 4cbd4462 | Oleksiy Mishchenko | <title>Introduction</title> |
15 | 4cbd4462 | Oleksiy Mishchenko | |
16 | bf4a90af | Iustin Pop | <para>Ganeti supports a remote API for enable external tools to |
17 | bf4a90af | Iustin Pop | easily retrieve information about a cluster's state. The remote API |
18 | bf4a90af | Iustin Pop | daemon, <command>ganeti-rapi</command>, is automatically started on |
19 | bf4a90af | Iustin Pop | the master node. By default it runs on TCP port 5080, but this can |
20 | bf4a90af | Iustin Pop | be changed either in <filename>…/constants.py</filename> or |
21 | bf4a90af | Iustin Pop | via the command line parameter <option>-p</option>. SSL support can |
22 | bf4a90af | Iustin Pop | also be enabled by passing command line parameters.</para> |
23 | 4cbd4462 | Oleksiy Mishchenko | |
24 | 4cbd4462 | Oleksiy Mishchenko | </sect1> |
25 | 4cbd4462 | Oleksiy Mishchenko | |
26 | 4cbd4462 | Oleksiy Mishchenko | <sect1> |
27 | bf4a90af | Iustin Pop | <title>Protocol</title> |
28 | 4cbd4462 | Oleksiy Mishchenko | |
29 | 4cbd4462 | Oleksiy Mishchenko | <para>The protocol used is <ulink url="&JsonLink;">JSON</ulink> over HTTP |
30 | 4cbd4462 | Oleksiy Mishchenko | designed after the <ulink url="&WikipediaRESTLink;">REST</ulink> principle. |
31 | 4cbd4462 | Oleksiy Mishchenko | </para> |
32 | 4cbd4462 | Oleksiy Mishchenko | </sect1> |
33 | 4cbd4462 | Oleksiy Mishchenko | |
34 | 4cbd4462 | Oleksiy Mishchenko | <sect1> |
35 | 4cbd4462 | Oleksiy Mishchenko | <title>Usage examples</title> |
36 | 4cbd4462 | Oleksiy Mishchenko | |
37 | 4cbd4462 | Oleksiy Mishchenko | <para>You can access the API using your favorite programming language as long |
38 | 4cbd4462 | Oleksiy Mishchenko | as it supports network connections.</para> |
39 | 4cbd4462 | Oleksiy Mishchenko | |
40 | 4cbd4462 | Oleksiy Mishchenko | <sect2> |
41 | bf4a90af | Iustin Pop | <title>Shell</title> |
42 | bf4a90af | Iustin Pop | <screen>wget -q -O - https://<replaceable>CLUSTERNAME</replaceable>:5080/2/info</screen> |
43 | bf4a90af | Iustin Pop | <para>or</para> |
44 | bf4a90af | Iustin Pop | <screen>curl https://<replaceable>CLUSTERNAME</replaceable>:5080/2/info</screen> |
45 | 4cbd4462 | Oleksiy Mishchenko | </sect2> |
46 | 4cbd4462 | Oleksiy Mishchenko | |
47 | 4cbd4462 | Oleksiy Mishchenko | <sect2> |
48 | 4cbd4462 | Oleksiy Mishchenko | <title>Python</title> |
49 | 4cbd4462 | Oleksiy Mishchenko | <screen>import urllib2 |
50 | bf4a90af | Iustin Pop | f = urllib2.urlopen('https://<replaceable>CLUSTERNAME</replaceable>:5080/info') |
51 | 4cbd4462 | Oleksiy Mishchenko | print f.read()</screen> |
52 | 4cbd4462 | Oleksiy Mishchenko | </sect2> |
53 | 4cbd4462 | Oleksiy Mishchenko | |
54 | 4cbd4462 | Oleksiy Mishchenko | <sect2> |
55 | 4cbd4462 | Oleksiy Mishchenko | <title>JavaScript</title> |
56 | 4cbd4462 | Oleksiy Mishchenko | <note> |
57 | 4cbd4462 | Oleksiy Mishchenko | <para>While it's possible to use JavaScript, it poses several potential |
58 | 4cbd4462 | Oleksiy Mishchenko | problems, including browser blocking request due to non-standard ports |
59 | 4cbd4462 | Oleksiy Mishchenko | or different domain names. Fetching the data on the webserver is |
60 | 4cbd4462 | Oleksiy Mishchenko | easier.</para> |
61 | 4cbd4462 | Oleksiy Mishchenko | </note> |
62 | bf4a90af | Iustin Pop | <screen>var url = 'https://<replaceable>CLUSTERNAME</replaceable>:5080/info'; |
63 | 4cbd4462 | Oleksiy Mishchenko | var info; |
64 | 4cbd4462 | Oleksiy Mishchenko | |
65 | 4cbd4462 | Oleksiy Mishchenko | var xmlreq = new XMLHttpRequest(); |
66 | 4cbd4462 | Oleksiy Mishchenko | xmlreq.onreadystatechange = function () { |
67 | 4cbd4462 | Oleksiy Mishchenko | if (xmlreq.readyState != 4) return; |
68 | 4cbd4462 | Oleksiy Mishchenko | if (xmlreq.status == 200) { |
69 | 4cbd4462 | Oleksiy Mishchenko | info = eval("(" + xmlreq.responseText + ")"); |
70 | 4cbd4462 | Oleksiy Mishchenko | alert(info); |
71 | 4cbd4462 | Oleksiy Mishchenko | } else { |
72 | 4cbd4462 | Oleksiy Mishchenko | alert('Error fetching cluster info'); |
73 | 4cbd4462 | Oleksiy Mishchenko | } |
74 | 4cbd4462 | Oleksiy Mishchenko | xmlreq = null; |
75 | 4cbd4462 | Oleksiy Mishchenko | }; |
76 | 4cbd4462 | Oleksiy Mishchenko | xmlreq.open('GET', url, true); |
77 | 4cbd4462 | Oleksiy Mishchenko | xmlreq.send(null);</screen> |
78 | 4cbd4462 | Oleksiy Mishchenko | </sect2> |
79 | 4cbd4462 | Oleksiy Mishchenko | |
80 | 4cbd4462 | Oleksiy Mishchenko | </sect1> |
81 | 4cbd4462 | Oleksiy Mishchenko | |
82 | 4cbd4462 | Oleksiy Mishchenko | <sect1> |
83 | 4cbd4462 | Oleksiy Mishchenko | <title>Resources</title> |
84 | 081242d8 | Michael Hanselmann | @INCLUDE_RAPI_RESOURCES@ |
85 | 4cbd4462 | Oleksiy Mishchenko | </sect1> |
86 | 4cbd4462 | Oleksiy Mishchenko | |
87 | 4cbd4462 | Oleksiy Mishchenko | </article> |