root / doc / rapi.rst @ 508e9b20
History | View | Annotate | Download (14.2 kB)
1 |
Ganeti remote API |
---|---|
2 |
================= |
3 |
|
4 |
Documents Ganeti version |version| |
5 |
|
6 |
.. contents:: |
7 |
|
8 |
Introduction |
9 |
------------ |
10 |
|
11 |
Ganeti supports a remote API for enable external tools to easily |
12 |
retrieve information about a cluster's state. The remote API daemon, |
13 |
*ganeti-rapi*, is automatically started on the master node. By default |
14 |
it runs on TCP port 5080, but this can be changed either in |
15 |
``.../constants.py`` or via the command line parameter *-p*. SSL mode, |
16 |
which is used by default, can also be disabled by passing command line |
17 |
parameters. |
18 |
|
19 |
Protocol |
20 |
-------- |
21 |
|
22 |
The protocol used is JSON_ over HTTP designed after the REST_ |
23 |
principle. |
24 |
|
25 |
.. _JSON: http://www.json.org/ |
26 |
.. _REST: http://en.wikipedia.org/wiki/Representational_State_Transfer |
27 |
|
28 |
Generic parameters |
29 |
------------------ |
30 |
|
31 |
A few parameter mean the same thing across all resources which implement it. |
32 |
|
33 |
``bulk`` |
34 |
++++++++ |
35 |
|
36 |
Bulk-mode means that for the resources which usually return just a |
37 |
list of child resources (e.g. ``/2/instances`` which returns just |
38 |
instance names), the output will instead contain detailed data for all |
39 |
these subresources. This is more efficient than query-ing the |
40 |
sub-resources themselves. |
41 |
|
42 |
``dry-run`` |
43 |
+++++++++++ |
44 |
|
45 |
The optional *dry-run* argument, if provided and set to a positive |
46 |
integer value (e.g. ``?dry-run=1``), signals to Ganeti that the job |
47 |
should not be executed, only the pre-execution checks will be done. |
48 |
|
49 |
This is useful in trying to determine (without guarantees though, as |
50 |
in the meantime the cluster state could have changed) if the operation |
51 |
is likely to succeed or at least start executing. |
52 |
|
53 |
``force`` |
54 |
+++++++++++ |
55 |
|
56 |
Force operation to continue even if it will cause the cluster to become |
57 |
inconsistent (e.g. because there are not enough master candidates). |
58 |
|
59 |
Usage examples |
60 |
-------------- |
61 |
|
62 |
You can access the API using your favorite programming language as |
63 |
long as it supports network connections. |
64 |
|
65 |
Shell |
66 |
+++++ |
67 |
|
68 |
.. highlight:: sh |
69 |
|
70 |
Using wget:: |
71 |
|
72 |
wget -q -O - https://CLUSTERNAME:5080/2/info |
73 |
|
74 |
or curl:: |
75 |
|
76 |
curl https://CLUSTERNAME:5080/2/info |
77 |
|
78 |
|
79 |
Python |
80 |
++++++ |
81 |
|
82 |
.. highlight: python |
83 |
|
84 |
import urllib2 |
85 |
f = urllib2.urlopen('https://CLUSTERNAME:5080/2/info') |
86 |
print f.read() |
87 |
|
88 |
|
89 |
JavaScript |
90 |
++++++++++ |
91 |
|
92 |
.. warning:: While it's possible to use JavaScript, it poses several |
93 |
potential problems, including browser blocking request due to |
94 |
non-standard ports or different domain names. Fetching the data on |
95 |
the webserver is easier. |
96 |
|
97 |
.. highlight:: javascript |
98 |
|
99 |
:: |
100 |
|
101 |
var url = 'https://CLUSTERNAME:5080/2/info'; |
102 |
var info; |
103 |
var xmlreq = new XMLHttpRequest(); |
104 |
xmlreq.onreadystatechange = function () { |
105 |
if (xmlreq.readyState != 4) return; |
106 |
if (xmlreq.status == 200) { |
107 |
info = eval("(" + xmlreq.responseText + ")"); |
108 |
alert(info); |
109 |
} else { |
110 |
alert('Error fetching cluster info'); |
111 |
} |
112 |
xmlreq = null; |
113 |
}; |
114 |
xmlreq.open('GET', url, true); |
115 |
xmlreq.send(null); |
116 |
|
117 |
Resources |
118 |
--------- |
119 |
|
120 |
.. highlight:: javascript |
121 |
|
122 |
``/`` |
123 |
+++++ |
124 |
|
125 |
The root resource. |
126 |
|
127 |
It supports the following commands: ``GET``. |
128 |
|
129 |
``GET`` |
130 |
~~~~~~~ |
131 |
|
132 |
Shows the list of mapped resources. |
133 |
|
134 |
Returns: a dictionary with 'name' and 'uri' keys for each of them. |
135 |
|
136 |
``/2`` |
137 |
++++++ |
138 |
|
139 |
The ``/2`` resource, the root of the version 2 API. |
140 |
|
141 |
It supports the following commands: ``GET``. |
142 |
|
143 |
``GET`` |
144 |
~~~~~~~ |
145 |
|
146 |
Show the list of mapped resources. |
147 |
|
148 |
Returns: a dictionary with ``name`` and ``uri`` keys for each of them. |
149 |
|
150 |
``/2/info`` |
151 |
+++++++++++ |
152 |
|
153 |
Cluster information resource. |
154 |
|
155 |
It supports the following commands: ``GET``. |
156 |
|
157 |
``GET`` |
158 |
~~~~~~~ |
159 |
|
160 |
Returns cluster information. |
161 |
|
162 |
Example:: |
163 |
|
164 |
{ |
165 |
"config_version": 2000000, |
166 |
"name": "cluster", |
167 |
"software_version": "2.0.0~beta2", |
168 |
"os_api_version": 10, |
169 |
"export_version": 0, |
170 |
"candidate_pool_size": 10, |
171 |
"enabled_hypervisors": [ |
172 |
"fake" |
173 |
], |
174 |
"hvparams": { |
175 |
"fake": {} |
176 |
}, |
177 |
"default_hypervisor": "fake", |
178 |
"master": "node1.example.com", |
179 |
"architecture": [ |
180 |
"64bit", |
181 |
"x86_64" |
182 |
], |
183 |
"protocol_version": 20, |
184 |
"beparams": { |
185 |
"default": { |
186 |
"auto_balance": true, |
187 |
"vcpus": 1, |
188 |
"memory": 128 |
189 |
} |
190 |
} |
191 |
} |
192 |
|
193 |
|
194 |
``/2/redistribute-config`` |
195 |
++++++++++++++++++++++++++ |
196 |
|
197 |
Redistribute configuration to all nodes. |
198 |
|
199 |
It supports the following commands: ``PUT``. |
200 |
|
201 |
``PUT`` |
202 |
~~~~~~~ |
203 |
|
204 |
Redistribute configuration to all nodes. The result will be a job id. |
205 |
|
206 |
|
207 |
``/2/instances`` |
208 |
++++++++++++++++ |
209 |
|
210 |
The instances resource. |
211 |
|
212 |
It supports the following commands: ``GET``, ``POST``. |
213 |
|
214 |
``GET`` |
215 |
~~~~~~~ |
216 |
|
217 |
Returns a list of all available instances. |
218 |
|
219 |
Example:: |
220 |
|
221 |
[ |
222 |
{ |
223 |
"name": "web.example.com", |
224 |
"uri": "\/instances\/web.example.com" |
225 |
}, |
226 |
{ |
227 |
"name": "mail.example.com", |
228 |
"uri": "\/instances\/mail.example.com" |
229 |
} |
230 |
] |
231 |
|
232 |
If the optional *bulk* argument is provided and set to a true value |
233 |
(i.e ``?bulk=1``), the output contains detailed information about |
234 |
instances as a list. |
235 |
|
236 |
Example:: |
237 |
|
238 |
[ |
239 |
{ |
240 |
"status": "running", |
241 |
"disk_usage": 20480, |
242 |
"nic.bridges": [ |
243 |
"xen-br0" |
244 |
], |
245 |
"name": "web.example.com", |
246 |
"tags": ["tag1", "tag2"], |
247 |
"beparams": { |
248 |
"vcpus": 2, |
249 |
"memory": 512 |
250 |
}, |
251 |
"disk.sizes": [ |
252 |
20480 |
253 |
], |
254 |
"pnode": "node1.example.com", |
255 |
"nic.macs": ["01:23:45:67:89:01"], |
256 |
"snodes": ["node2.example.com"], |
257 |
"disk_template": "drbd", |
258 |
"admin_state": true, |
259 |
"os": "debian-etch", |
260 |
"oper_state": true |
261 |
}, |
262 |
... |
263 |
] |
264 |
|
265 |
|
266 |
``POST`` |
267 |
~~~~~~~~ |
268 |
|
269 |
Creates an instance. |
270 |
|
271 |
If the optional *dry-run* argument is provided and set to a positive |
272 |
integer valu (e.g. ``?dry-run=1``), the job will not be actually |
273 |
executed, only the pre-execution checks will be done. Query-ing the |
274 |
job result will return, in both dry-run and normal case, the list of |
275 |
nodes selected for the instance. |
276 |
|
277 |
Returns: a job ID that can be used later for polling. |
278 |
|
279 |
``/2/instances/[instance_name]`` |
280 |
++++++++++++++++++++++++++++++++ |
281 |
|
282 |
Instance-specific resource. |
283 |
|
284 |
It supports the following commands: ``GET``, ``DELETE``. |
285 |
|
286 |
``GET`` |
287 |
~~~~~~~ |
288 |
|
289 |
Returns information about an instance, similar to the bulk output from |
290 |
the instance list. |
291 |
|
292 |
``DELETE`` |
293 |
~~~~~~~~~~ |
294 |
|
295 |
Deletes an instance. |
296 |
|
297 |
It supports the ``dry-run`` argument. |
298 |
|
299 |
|
300 |
``/2/instances/[instance_name]/info`` |
301 |
+++++++++++++++++++++++++++++++++++++++ |
302 |
|
303 |
It supports the following commands: ``GET``. |
304 |
|
305 |
``GET`` |
306 |
~~~~~~~ |
307 |
|
308 |
Requests detailed information about the instance. An optional parameter, |
309 |
``static`` (bool), can be set to return only static information from the |
310 |
configuration without querying the instance's nodes. The result will be a job |
311 |
id. |
312 |
|
313 |
|
314 |
``/2/instances/[instance_name]/reboot`` |
315 |
+++++++++++++++++++++++++++++++++++++++ |
316 |
|
317 |
Reboots URI for an instance. |
318 |
|
319 |
It supports the following commands: ``POST``. |
320 |
|
321 |
``POST`` |
322 |
~~~~~~~~ |
323 |
|
324 |
Reboots the instance. |
325 |
|
326 |
The URI takes optional ``type=hard|soft|full`` and |
327 |
``ignore_secondaries=False|True`` parameters. |
328 |
|
329 |
It supports the ``dry-run`` argument. |
330 |
|
331 |
|
332 |
``/2/instances/[instance_name]/shutdown`` |
333 |
+++++++++++++++++++++++++++++++++++++++++ |
334 |
|
335 |
Instance shutdown URI. |
336 |
|
337 |
It supports the following commands: ``PUT``. |
338 |
|
339 |
``PUT`` |
340 |
~~~~~~~ |
341 |
|
342 |
Shutdowns an instance. |
343 |
|
344 |
It supports the ``dry-run`` argument. |
345 |
|
346 |
|
347 |
``/2/instances/[instance_name]/startup`` |
348 |
++++++++++++++++++++++++++++++++++++++++ |
349 |
|
350 |
Instance startup URI. |
351 |
|
352 |
It supports the following commands: ``PUT``. |
353 |
|
354 |
``PUT`` |
355 |
~~~~~~~ |
356 |
|
357 |
Startup an instance. |
358 |
|
359 |
The URI takes an optional ``force=False|True`` parameter to start the |
360 |
instance if even if secondary disks are failing. |
361 |
|
362 |
It supports the ``dry-run`` argument. |
363 |
|
364 |
``/2/instances/[instance_name]/reinstall`` |
365 |
++++++++++++++++++++++++++++++++++++++++++++++ |
366 |
|
367 |
Installs the operating system again. |
368 |
|
369 |
It supports the following commands: ``POST``. |
370 |
|
371 |
``POST`` |
372 |
~~~~~~~~ |
373 |
|
374 |
Takes the parameters ``os`` (OS template name) and ``nostartup`` (bool). |
375 |
|
376 |
|
377 |
``/2/instances/[instance_name]/replace-disks`` |
378 |
++++++++++++++++++++++++++++++++++++++++++++++ |
379 |
|
380 |
Replaces disks on an instance. |
381 |
|
382 |
It supports the following commands: ``POST``. |
383 |
|
384 |
``POST`` |
385 |
~~~~~~~~ |
386 |
|
387 |
Takes the parameters ``mode`` (one of ``replace_on_primary``, |
388 |
``replace_on_secondary``, ``replace_new_secondary`` or ``replace_auto``), |
389 |
``disks`` (comma separated list of disk indexes), ``remote_node`` and |
390 |
``iallocator``. |
391 |
|
392 |
|
393 |
``/2/instances/[instance_name]/tags`` |
394 |
+++++++++++++++++++++++++++++++++++++ |
395 |
|
396 |
Manages per-instance tags. |
397 |
|
398 |
It supports the following commands: ``GET``, ``PUT``, ``DELETE``. |
399 |
|
400 |
``GET`` |
401 |
~~~~~~~ |
402 |
|
403 |
Returns a list of tags. |
404 |
|
405 |
Example:: |
406 |
|
407 |
["tag1", "tag2", "tag3"] |
408 |
|
409 |
``PUT`` |
410 |
~~~~~~~ |
411 |
|
412 |
Add a set of tags. |
413 |
|
414 |
The request as a list of strings should be ``PUT`` to this URI. The |
415 |
result will be a job id. |
416 |
|
417 |
It supports the ``dry-run`` argument. |
418 |
|
419 |
|
420 |
``DELETE`` |
421 |
~~~~~~~~~~ |
422 |
|
423 |
Delete a tag. |
424 |
|
425 |
In order to delete a set of tags, the DELETE request should be |
426 |
addressed to URI like:: |
427 |
|
428 |
/tags?tag=[tag]&tag=[tag] |
429 |
|
430 |
It supports the ``dry-run`` argument. |
431 |
|
432 |
|
433 |
``/2/jobs`` |
434 |
+++++++++++ |
435 |
|
436 |
The ``/2/jobs`` resource. |
437 |
|
438 |
It supports the following commands: ``GET``. |
439 |
|
440 |
``GET`` |
441 |
~~~~~~~ |
442 |
|
443 |
Returns a dictionary of jobs. |
444 |
|
445 |
Returns: a dictionary with jobs id and uri. |
446 |
|
447 |
``/2/jobs/[job_id]`` |
448 |
++++++++++++++++++++ |
449 |
|
450 |
|
451 |
Individual job URI. |
452 |
|
453 |
It supports the following commands: ``GET``, ``DELETE``. |
454 |
|
455 |
``GET`` |
456 |
~~~~~~~ |
457 |
|
458 |
Returns a job status. |
459 |
|
460 |
Returns: a dictionary with job parameters. |
461 |
|
462 |
The result includes: |
463 |
|
464 |
- id: job ID as a number |
465 |
- status: current job status as a string |
466 |
- ops: involved OpCodes as a list of dictionaries for each |
467 |
opcodes in the job |
468 |
- opstatus: OpCodes status as a list |
469 |
- opresult: OpCodes results as a list of lists |
470 |
|
471 |
``DELETE`` |
472 |
~~~~~~~~~~ |
473 |
|
474 |
Cancel a not-yet-started job. |
475 |
|
476 |
``/2/nodes`` |
477 |
++++++++++++ |
478 |
|
479 |
Nodes resource. |
480 |
|
481 |
It supports the following commands: ``GET``. |
482 |
|
483 |
``GET`` |
484 |
~~~~~~~ |
485 |
|
486 |
Returns a list of all nodes. |
487 |
|
488 |
Example:: |
489 |
|
490 |
[ |
491 |
{ |
492 |
"id": "node1.example.com", |
493 |
"uri": "\/instances\/node1.example.com" |
494 |
}, |
495 |
{ |
496 |
"id": "node2.example.com", |
497 |
"uri": "\/instances\/node2.example.com" |
498 |
} |
499 |
] |
500 |
|
501 |
If the optional 'bulk' argument is provided and set to 'true' value |
502 |
(i.e '?bulk=1'), the output contains detailed information about nodes |
503 |
as a list. |
504 |
|
505 |
Example:: |
506 |
|
507 |
[ |
508 |
{ |
509 |
"pinst_cnt": 1, |
510 |
"mfree": 31280, |
511 |
"mtotal": 32763, |
512 |
"name": "www.example.com", |
513 |
"tags": [], |
514 |
"mnode": 512, |
515 |
"dtotal": 5246208, |
516 |
"sinst_cnt": 2, |
517 |
"dfree": 5171712, |
518 |
"offline": false |
519 |
}, |
520 |
... |
521 |
] |
522 |
|
523 |
``/2/nodes/[node_name]`` |
524 |
+++++++++++++++++++++++++++++++++ |
525 |
|
526 |
Returns information about a node. |
527 |
|
528 |
It supports the following commands: ``GET``. |
529 |
|
530 |
``/2/nodes/[node_name]/evacuate`` |
531 |
+++++++++++++++++++++++++++++++++ |
532 |
|
533 |
Evacuates all secondary instances off a node. |
534 |
|
535 |
It supports the following commands: ``POST``. |
536 |
|
537 |
``POST`` |
538 |
~~~~~~~~ |
539 |
|
540 |
To evacuate a node, either one of the ``iallocator`` or ``remote_node`` |
541 |
parameters must be passed: |
542 |
|
543 |
evacuate?iallocator=[iallocator] |
544 |
evacuate?remote_node=[nodeX.example.com] |
545 |
|
546 |
``/2/nodes/[node_name]/migrate`` |
547 |
+++++++++++++++++++++++++++++++++ |
548 |
|
549 |
Migrates all primary instances from a node. |
550 |
|
551 |
It supports the following commands: ``POST``. |
552 |
|
553 |
``POST`` |
554 |
~~~~~~~~ |
555 |
|
556 |
No parameters are required, but ``live`` can be set to a boolean value. |
557 |
|
558 |
migrate?live=[0|1] |
559 |
|
560 |
``/2/nodes/[node_name]/role`` |
561 |
+++++++++++++++++++++++++++++ |
562 |
|
563 |
Manages node role. |
564 |
|
565 |
It supports the following commands: ``GET``, ``PUT``. |
566 |
|
567 |
The role is always one of the following: |
568 |
|
569 |
- drained |
570 |
- master |
571 |
- master-candidate |
572 |
- offline |
573 |
- regular |
574 |
|
575 |
``GET`` |
576 |
~~~~~~~ |
577 |
|
578 |
Returns the current node role. |
579 |
|
580 |
Example:: |
581 |
|
582 |
"master-candidate" |
583 |
|
584 |
``PUT`` |
585 |
~~~~~~~ |
586 |
|
587 |
Change the node role. |
588 |
|
589 |
The request is a string which should be PUT to this URI. The result will be a |
590 |
job id. |
591 |
|
592 |
It supports the ``force`` argument. |
593 |
|
594 |
``/2/nodes/[node_name]/storage`` |
595 |
++++++++++++++++++++++++++++++++ |
596 |
|
597 |
Manages storage units on the node. |
598 |
|
599 |
``GET`` |
600 |
~~~~~~~ |
601 |
|
602 |
Requests a list of storage units on a node. Requires the parameters |
603 |
``storage_type`` (one of ``file``, ``lvm-pv`` or ``lvm-vg``) and |
604 |
``output_fields``. The result will be a job id, using which the result can be |
605 |
retrieved. |
606 |
|
607 |
``/2/nodes/[node_name]/storage/modify`` |
608 |
+++++++++++++++++++++++++++++++++++++++ |
609 |
|
610 |
Modifies storage units on the node. |
611 |
|
612 |
``PUT`` |
613 |
~~~~~~~ |
614 |
|
615 |
Modifies parameters of storage units on the node. Requires the parameters |
616 |
``storage_type`` (one of ``file``, ``lvm-pv`` or ``lvm-vg``) and ``name`` (name |
617 |
of the storage unit). Parameters can be passed additionally. Currently only |
618 |
``allocatable`` (bool) is supported. The result will be a job id. |
619 |
|
620 |
``/2/nodes/[node_name]/storage/repair`` |
621 |
+++++++++++++++++++++++++++++++++++++++ |
622 |
|
623 |
Repairs a storage unit on the node. |
624 |
|
625 |
``PUT`` |
626 |
~~~~~~~ |
627 |
|
628 |
Repairs a storage unit on the node. Requires the parameters ``storage_type`` |
629 |
(currently only ``lvm-vg`` can be repaired) and ``name`` (name of the storage |
630 |
unit). The result will be a job id. |
631 |
|
632 |
``/2/nodes/[node_name]/tags`` |
633 |
+++++++++++++++++++++++++++++ |
634 |
|
635 |
Manages per-node tags. |
636 |
|
637 |
It supports the following commands: ``GET``, ``PUT``, ``DELETE``. |
638 |
|
639 |
``GET`` |
640 |
~~~~~~~ |
641 |
|
642 |
Returns a list of tags. |
643 |
|
644 |
Example:: |
645 |
|
646 |
["tag1", "tag2", "tag3"] |
647 |
|
648 |
``PUT`` |
649 |
~~~~~~~ |
650 |
|
651 |
Add a set of tags. |
652 |
|
653 |
The request as a list of strings should be PUT to this URI. The result |
654 |
will be a job id. |
655 |
|
656 |
It supports the ``dry-run`` argument. |
657 |
|
658 |
``DELETE`` |
659 |
~~~~~~~~~~ |
660 |
|
661 |
Deletes tags. |
662 |
|
663 |
In order to delete a set of tags, the DELETE request should be |
664 |
addressed to URI like:: |
665 |
|
666 |
/tags?tag=[tag]&tag=[tag] |
667 |
|
668 |
It supports the ``dry-run`` argument. |
669 |
|
670 |
|
671 |
``/2/os`` |
672 |
+++++++++ |
673 |
|
674 |
OS resource. |
675 |
|
676 |
It supports the following commands: ``GET``. |
677 |
|
678 |
``GET`` |
679 |
~~~~~~~ |
680 |
|
681 |
Return a list of all OSes. |
682 |
|
683 |
Can return error 500 in case of a problem. Since this is a costly |
684 |
operation for Ganeti 2.0, it is not recommended to execute it too |
685 |
often. |
686 |
|
687 |
Example:: |
688 |
|
689 |
["debian-etch"] |
690 |
|
691 |
``/2/tags`` |
692 |
+++++++++++ |
693 |
|
694 |
Manages cluster tags. |
695 |
|
696 |
It supports the following commands: ``GET``, ``PUT``, ``DELETE``. |
697 |
|
698 |
``GET`` |
699 |
~~~~~~~ |
700 |
|
701 |
Returns the cluster tags. |
702 |
|
703 |
Example:: |
704 |
|
705 |
["tag1", "tag2", "tag3"] |
706 |
|
707 |
``PUT`` |
708 |
~~~~~~~ |
709 |
|
710 |
Adds a set of tags. |
711 |
|
712 |
The request as a list of strings should be PUT to this URI. The result |
713 |
will be a job id. |
714 |
|
715 |
It supports the ``dry-run`` argument. |
716 |
|
717 |
|
718 |
``DELETE`` |
719 |
~~~~~~~~~~ |
720 |
|
721 |
Deletes tags. |
722 |
|
723 |
In order to delete a set of tags, the DELETE request should be |
724 |
addressed to URI like:: |
725 |
|
726 |
/tags?tag=[tag]&tag=[tag] |
727 |
|
728 |
It supports the ``dry-run`` argument. |
729 |
|
730 |
|
731 |
``/version`` |
732 |
++++++++++++ |
733 |
|
734 |
The version resource. |
735 |
|
736 |
This resource should be used to determine the remote API version and |
737 |
to adapt clients accordingly. |
738 |
|
739 |
It supports the following commands: ``GET``. |
740 |
|
741 |
``GET`` |
742 |
~~~~~~~ |
743 |
|
744 |
Returns the remote API version. Ganeti 1.2 returned ``1`` and Ganeti |
745 |
2.0 returns ``2``. |