root / doc / rapi.rst @ f72542cc
History | View | Annotate | Download (13.9 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 |
``/2/instances`` |
194 |
++++++++++++++++ |
195 |
|
196 |
The instances resource. |
197 |
|
198 |
It supports the following commands: ``GET``, ``POST``. |
199 |
|
200 |
``GET`` |
201 |
~~~~~~~ |
202 |
|
203 |
Returns a list of all available instances. |
204 |
|
205 |
Example:: |
206 |
|
207 |
[ |
208 |
{ |
209 |
"name": "web.example.com", |
210 |
"uri": "\/instances\/web.example.com" |
211 |
}, |
212 |
{ |
213 |
"name": "mail.example.com", |
214 |
"uri": "\/instances\/mail.example.com" |
215 |
} |
216 |
] |
217 |
|
218 |
If the optional *bulk* argument is provided and set to a true value |
219 |
(i.e ``?bulk=1``), the output contains detailed information about |
220 |
instances as a list. |
221 |
|
222 |
Example:: |
223 |
|
224 |
[ |
225 |
{ |
226 |
"status": "running", |
227 |
"disk_usage": 20480, |
228 |
"nic.bridges": [ |
229 |
"xen-br0" |
230 |
], |
231 |
"name": "web.example.com", |
232 |
"tags": ["tag1", "tag2"], |
233 |
"beparams": { |
234 |
"vcpus": 2, |
235 |
"memory": 512 |
236 |
}, |
237 |
"disk.sizes": [ |
238 |
20480 |
239 |
], |
240 |
"pnode": "node1.example.com", |
241 |
"nic.macs": ["01:23:45:67:89:01"], |
242 |
"snodes": ["node2.example.com"], |
243 |
"disk_template": "drbd", |
244 |
"admin_state": true, |
245 |
"os": "debian-etch", |
246 |
"oper_state": true |
247 |
}, |
248 |
... |
249 |
] |
250 |
|
251 |
|
252 |
``POST`` |
253 |
~~~~~~~~ |
254 |
|
255 |
Creates an instance. |
256 |
|
257 |
If the optional *dry-run* argument is provided and set to a positive |
258 |
integer valu (e.g. ``?dry-run=1``), the job will not be actually |
259 |
executed, only the pre-execution checks will be done. Query-ing the |
260 |
job result will return, in both dry-run and normal case, the list of |
261 |
nodes selected for the instance. |
262 |
|
263 |
Returns: a job ID that can be used later for polling. |
264 |
|
265 |
``/2/instances/[instance_name]`` |
266 |
++++++++++++++++++++++++++++++++ |
267 |
|
268 |
Instance-specific resource. |
269 |
|
270 |
It supports the following commands: ``GET``, ``DELETE``. |
271 |
|
272 |
``GET`` |
273 |
~~~~~~~ |
274 |
|
275 |
Returns information about an instance, similar to the bulk output from |
276 |
the instance list. |
277 |
|
278 |
``DELETE`` |
279 |
~~~~~~~~~~ |
280 |
|
281 |
Deletes an instance. |
282 |
|
283 |
It supports the ``dry-run`` argument. |
284 |
|
285 |
|
286 |
``/2/instances/[instance_name]/info`` |
287 |
+++++++++++++++++++++++++++++++++++++++ |
288 |
|
289 |
It supports the following commands: ``GET``. |
290 |
|
291 |
``GET`` |
292 |
~~~~~~~ |
293 |
|
294 |
Requests detailed information about the instance. An optional parameter, |
295 |
``static`` (bool), can be set to return only static information from the |
296 |
configuration without querying the instance's nodes. The result will be a job |
297 |
id. |
298 |
|
299 |
|
300 |
``/2/instances/[instance_name]/reboot`` |
301 |
+++++++++++++++++++++++++++++++++++++++ |
302 |
|
303 |
Reboots URI for an instance. |
304 |
|
305 |
It supports the following commands: ``POST``. |
306 |
|
307 |
``POST`` |
308 |
~~~~~~~~ |
309 |
|
310 |
Reboots the instance. |
311 |
|
312 |
The URI takes optional ``type=hard|soft|full`` and |
313 |
``ignore_secondaries=False|True`` parameters. |
314 |
|
315 |
It supports the ``dry-run`` argument. |
316 |
|
317 |
|
318 |
``/2/instances/[instance_name]/shutdown`` |
319 |
+++++++++++++++++++++++++++++++++++++++++ |
320 |
|
321 |
Instance shutdown URI. |
322 |
|
323 |
It supports the following commands: ``PUT``. |
324 |
|
325 |
``PUT`` |
326 |
~~~~~~~ |
327 |
|
328 |
Shutdowns an instance. |
329 |
|
330 |
It supports the ``dry-run`` argument. |
331 |
|
332 |
|
333 |
``/2/instances/[instance_name]/startup`` |
334 |
++++++++++++++++++++++++++++++++++++++++ |
335 |
|
336 |
Instance startup URI. |
337 |
|
338 |
It supports the following commands: ``PUT``. |
339 |
|
340 |
``PUT`` |
341 |
~~~~~~~ |
342 |
|
343 |
Startup an instance. |
344 |
|
345 |
The URI takes an optional ``force=False|True`` parameter to start the |
346 |
instance if even if secondary disks are failing. |
347 |
|
348 |
It supports the ``dry-run`` argument. |
349 |
|
350 |
``/2/instances/[instance_name]/reinstall`` |
351 |
++++++++++++++++++++++++++++++++++++++++++++++ |
352 |
|
353 |
Installs the operating system again. |
354 |
|
355 |
It supports the following commands: ``POST``. |
356 |
|
357 |
``POST`` |
358 |
~~~~~~~~ |
359 |
|
360 |
Takes the parameters ``os`` (OS template name) and ``nostartup`` (bool). |
361 |
|
362 |
|
363 |
``/2/instances/[instance_name]/replace-disks`` |
364 |
++++++++++++++++++++++++++++++++++++++++++++++ |
365 |
|
366 |
Replaces disks on an instance. |
367 |
|
368 |
It supports the following commands: ``POST``. |
369 |
|
370 |
``POST`` |
371 |
~~~~~~~~ |
372 |
|
373 |
Takes the parameters ``mode`` (one of ``replace_on_primary``, |
374 |
``replace_on_secondary``, ``replace_new_secondary`` or ``replace_auto``), |
375 |
``disks`` (comma separated list of disk indexes), ``remote_node`` and |
376 |
``iallocator``. |
377 |
|
378 |
|
379 |
``/2/instances/[instance_name]/tags`` |
380 |
+++++++++++++++++++++++++++++++++++++ |
381 |
|
382 |
Manages per-instance tags. |
383 |
|
384 |
It supports the following commands: ``GET``, ``PUT``, ``DELETE``. |
385 |
|
386 |
``GET`` |
387 |
~~~~~~~ |
388 |
|
389 |
Returns a list of tags. |
390 |
|
391 |
Example:: |
392 |
|
393 |
["tag1", "tag2", "tag3"] |
394 |
|
395 |
``PUT`` |
396 |
~~~~~~~ |
397 |
|
398 |
Add a set of tags. |
399 |
|
400 |
The request as a list of strings should be ``PUT`` to this URI. The |
401 |
result willl be a job id. |
402 |
|
403 |
It supports the ``dry-run`` argument. |
404 |
|
405 |
|
406 |
``DELETE`` |
407 |
~~~~~~~~~~ |
408 |
|
409 |
Delete a tag. |
410 |
|
411 |
In order to delete a set of tags, the DELETE request should be |
412 |
addressed to URI like:: |
413 |
|
414 |
/tags?tag=[tag]&tag=[tag] |
415 |
|
416 |
It supports the ``dry-run`` argument. |
417 |
|
418 |
|
419 |
``/2/jobs`` |
420 |
+++++++++++ |
421 |
|
422 |
The ``/2/jobs`` resource. |
423 |
|
424 |
It supports the following commands: ``GET``. |
425 |
|
426 |
``GET`` |
427 |
~~~~~~~ |
428 |
|
429 |
Returns a dictionary of jobs. |
430 |
|
431 |
Returns: a dictionary with jobs id and uri. |
432 |
|
433 |
``/2/jobs/[job_id]`` |
434 |
++++++++++++++++++++ |
435 |
|
436 |
|
437 |
Individual job URI. |
438 |
|
439 |
It supports the following commands: ``GET``, ``DELETE``. |
440 |
|
441 |
``GET`` |
442 |
~~~~~~~ |
443 |
|
444 |
Returns a job status. |
445 |
|
446 |
Returns: a dictionary with job parameters. |
447 |
|
448 |
The result includes: |
449 |
|
450 |
- id: job ID as a number |
451 |
- status: current job status as a string |
452 |
- ops: involved OpCodes as a list of dictionaries for each |
453 |
opcodes in the job |
454 |
- opstatus: OpCodes status as a list |
455 |
- opresult: OpCodes results as a list of lists |
456 |
|
457 |
``DELETE`` |
458 |
~~~~~~~~~~ |
459 |
|
460 |
Cancel a not-yet-started job. |
461 |
|
462 |
``/2/nodes`` |
463 |
++++++++++++ |
464 |
|
465 |
Nodes resource. |
466 |
|
467 |
It supports the following commands: ``GET``. |
468 |
|
469 |
``GET`` |
470 |
~~~~~~~ |
471 |
|
472 |
Returns a list of all nodes. |
473 |
|
474 |
Example:: |
475 |
|
476 |
[ |
477 |
{ |
478 |
"id": "node1.example.com", |
479 |
"uri": "\/instances\/node1.example.com" |
480 |
}, |
481 |
{ |
482 |
"id": "node2.example.com", |
483 |
"uri": "\/instances\/node2.example.com" |
484 |
} |
485 |
] |
486 |
|
487 |
If the optional 'bulk' argument is provided and set to 'true' value |
488 |
(i.e '?bulk=1'), the output contains detailed information about nodes |
489 |
as a list. |
490 |
|
491 |
Example:: |
492 |
|
493 |
[ |
494 |
{ |
495 |
"pinst_cnt": 1, |
496 |
"mfree": 31280, |
497 |
"mtotal": 32763, |
498 |
"name": "www.example.com", |
499 |
"tags": [], |
500 |
"mnode": 512, |
501 |
"dtotal": 5246208, |
502 |
"sinst_cnt": 2, |
503 |
"dfree": 5171712, |
504 |
"offline": false |
505 |
}, |
506 |
... |
507 |
] |
508 |
|
509 |
``/2/nodes/[node_name]`` |
510 |
+++++++++++++++++++++++++++++++++ |
511 |
|
512 |
Returns information about a node. |
513 |
|
514 |
It supports the following commands: ``GET``. |
515 |
|
516 |
``/2/nodes/[node_name]/evacuate`` |
517 |
+++++++++++++++++++++++++++++++++ |
518 |
|
519 |
Evacuates all secondary instances off a node. |
520 |
|
521 |
It supports the following commands: ``POST``. |
522 |
|
523 |
``POST`` |
524 |
~~~~~~~~ |
525 |
|
526 |
To evacuate a node, either one of the ``iallocator`` or ``remote_node`` |
527 |
parameters must be passed: |
528 |
|
529 |
evacuate?iallocator=[iallocator] |
530 |
evacuate?remote_node=[nodeX.example.com] |
531 |
|
532 |
``/2/nodes/[node_name]/migrate`` |
533 |
+++++++++++++++++++++++++++++++++ |
534 |
|
535 |
Migrates all primary instances from a node. |
536 |
|
537 |
It supports the following commands: ``POST``. |
538 |
|
539 |
``POST`` |
540 |
~~~~~~~~ |
541 |
|
542 |
No parameters are required, but ``live`` can be set to a boolean value. |
543 |
|
544 |
migrate?live=[0|1] |
545 |
|
546 |
``/2/nodes/[node_name]/role`` |
547 |
+++++++++++++++++++++++++++++ |
548 |
|
549 |
Manages node role. |
550 |
|
551 |
It supports the following commands: ``GET``, ``PUT``. |
552 |
|
553 |
The role is always one of the following: |
554 |
|
555 |
- drained |
556 |
- master |
557 |
- master-candidate |
558 |
- offline |
559 |
- regular |
560 |
|
561 |
``GET`` |
562 |
~~~~~~~ |
563 |
|
564 |
Returns the current node role. |
565 |
|
566 |
Example:: |
567 |
|
568 |
"master-candidate" |
569 |
|
570 |
``PUT`` |
571 |
~~~~~~~ |
572 |
|
573 |
Change the node role. |
574 |
|
575 |
The request is a string which should be PUT to this URI. The result will be a |
576 |
job id. |
577 |
|
578 |
It supports the ``force`` argument. |
579 |
|
580 |
``/2/nodes/[node_name]/storage`` |
581 |
++++++++++++++++++++++++++++++++ |
582 |
|
583 |
Manages storage units on the node. |
584 |
|
585 |
``GET`` |
586 |
~~~~~~~ |
587 |
|
588 |
Requests a list of storage units on a node. Requires the parameters |
589 |
``storage_type`` (one of ``file``, ``lvm-pv`` or ``lvm-vg``) and |
590 |
``output_fields``. The result will be a job id, using which the result can be |
591 |
retrieved. |
592 |
|
593 |
``/2/nodes/[node_name]/storage/modify`` |
594 |
+++++++++++++++++++++++++++++++++++++++ |
595 |
|
596 |
Modifies storage units on the node. |
597 |
|
598 |
``PUT`` |
599 |
~~~~~~~ |
600 |
|
601 |
Modifies parameters of storage units on the node. Requires the parameters |
602 |
``storage_type`` (one of ``file``, ``lvm-pv`` or ``lvm-vg``) and ``name`` (name |
603 |
of the storage unit). Parameters can be passed additionally. Currently only |
604 |
``allocatable`` (bool) is supported. The result will be a job id. |
605 |
|
606 |
``/2/nodes/[node_name]/storage/repair`` |
607 |
+++++++++++++++++++++++++++++++++++++++ |
608 |
|
609 |
Repairs a storage unit on the node. |
610 |
|
611 |
``PUT`` |
612 |
~~~~~~~ |
613 |
|
614 |
Repairs a storage unit on the node. Requires the parameters ``storage_type`` |
615 |
(currently only ``lvm-vg`` can be repaired) and ``name`` (name of the storage |
616 |
unit). The result will be a job id. |
617 |
|
618 |
``/2/nodes/[node_name]/tags`` |
619 |
+++++++++++++++++++++++++++++ |
620 |
|
621 |
Manages per-node tags. |
622 |
|
623 |
It supports the following commands: ``GET``, ``PUT``, ``DELETE``. |
624 |
|
625 |
``GET`` |
626 |
~~~~~~~ |
627 |
|
628 |
Returns a list of tags. |
629 |
|
630 |
Example:: |
631 |
|
632 |
["tag1", "tag2", "tag3"] |
633 |
|
634 |
``PUT`` |
635 |
~~~~~~~ |
636 |
|
637 |
Add a set of tags. |
638 |
|
639 |
The request as a list of strings should be PUT to this URI. The result |
640 |
will be a job id. |
641 |
|
642 |
It supports the ``dry-run`` argument. |
643 |
|
644 |
``DELETE`` |
645 |
~~~~~~~~~~ |
646 |
|
647 |
Deletes tags. |
648 |
|
649 |
In order to delete a set of tags, the DELETE request should be |
650 |
addressed to URI like:: |
651 |
|
652 |
/tags?tag=[tag]&tag=[tag] |
653 |
|
654 |
It supports the ``dry-run`` argument. |
655 |
|
656 |
|
657 |
``/2/os`` |
658 |
+++++++++ |
659 |
|
660 |
OS resource. |
661 |
|
662 |
It supports the following commands: ``GET``. |
663 |
|
664 |
``GET`` |
665 |
~~~~~~~ |
666 |
|
667 |
Return a list of all OSes. |
668 |
|
669 |
Can return error 500 in case of a problem. Since this is a costly |
670 |
operation for Ganeti 2.0, it is not recommended to execute it too |
671 |
often. |
672 |
|
673 |
Example:: |
674 |
|
675 |
["debian-etch"] |
676 |
|
677 |
``/2/tags`` |
678 |
+++++++++++ |
679 |
|
680 |
Manages cluster tags. |
681 |
|
682 |
It supports the following commands: ``GET``, ``PUT``, ``DELETE``. |
683 |
|
684 |
``GET`` |
685 |
~~~~~~~ |
686 |
|
687 |
Returns the cluster tags. |
688 |
|
689 |
Example:: |
690 |
|
691 |
["tag1", "tag2", "tag3"] |
692 |
|
693 |
``PUT`` |
694 |
~~~~~~~ |
695 |
|
696 |
Adds a set of tags. |
697 |
|
698 |
The request as a list of strings should be PUT to this URI. The result |
699 |
will be a job id. |
700 |
|
701 |
It supports the ``dry-run`` argument. |
702 |
|
703 |
|
704 |
``DELETE`` |
705 |
~~~~~~~~~~ |
706 |
|
707 |
Deletes tags. |
708 |
|
709 |
In order to delete a set of tags, the DELETE request should be |
710 |
addressed to URI like:: |
711 |
|
712 |
/tags?tag=[tag]&tag=[tag] |
713 |
|
714 |
It supports the ``dry-run`` argument. |
715 |
|
716 |
|
717 |
``/version`` |
718 |
++++++++++++ |
719 |
|
720 |
The version resource. |
721 |
|
722 |
This resource should be used to determine the remote API version and |
723 |
to adapt clients accordingly. |
724 |
|
725 |
It supports the following commands: ``GET``. |
726 |
|
727 |
``GET`` |
728 |
~~~~~~~ |
729 |
|
730 |
Returns the remote API version. Ganeti 1.2 returned ``1`` and Ganeti |
731 |
2.0 returns ``2``. |