Document non-standard usage of JSON in RAPI
[ganeti-local] / doc / rapi.rst
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
20 Users and passwords
21 -------------------
22
23 ``ganeti-rapi`` reads users and passwords from a file (usually
24 ``/var/lib/ganeti/rapi_users``) on startup. After modifying the password
25 file, ``ganeti-rapi`` must be restarted.
26
27 Each line consists of two or three fields separated by whitespace. The
28 first two fields are for username and password. The third field is
29 optional and can be used to specify per-user options. Currently,
30 ``write`` is the only option supported and enables the user to execute
31 operations modifying the cluster. Lines starting with the hash sign
32 (``#``) are treated as comments.
33
34 Passwords can either be written in clear text or as a hash. Clear text
35 passwords may not start with an opening brace (``{``) or they must be
36 prefixed with ``{cleartext}``. To use the hashed form, get the MD5 hash
37 of the string ``$username:Ganeti Remote API:$password`` (e.g. ``echo -n
38 'jack:Ganeti Remote API:abc123' | openssl md5``) [#pwhash]_ and prefix
39 it with ``{ha1}``. Using the scheme prefix for all passwords is
40 recommended. Scheme prefixes are not case sensitive.
41
42 Example::
43
44   # Give Jack and Fred read-only access
45   jack abc123
46   fred {cleartext}foo555
47
48   # Give write access to an imaginary instance creation script
49   autocreator xyz789 write
50
51   # Hashed password for Jessica
52   jessica {HA1}7046452df2cbb530877058712cf17bd4 write
53
54
55 .. [#pwhash] Using the MD5 hash of username, realm and password is
56    described in RFC2617_ ("HTTP Authentication"), sections 3.2.2.2 and
57    3.3. The reason for using it over another algorithm is forward
58    compatibility. If ``ganeti-rapi`` were to implement HTTP Digest
59    authentication in the future, the same hash could be used.
60    In the current version ``ganeti-rapi``'s realm, ``Ganeti Remote
61    API``, can only be changed by modifying the source code.
62
63
64 Protocol
65 --------
66
67 The protocol used is JSON_ over HTTP designed after the REST_ principle.
68 HTTP Basic authentication as per RFC2617_ is supported.
69
70 .. _JSON: http://www.json.org/
71 .. _REST: http://en.wikipedia.org/wiki/Representational_State_Transfer
72 .. _RFC2617: http://tools.ietf.org/rfc/rfc2617.txt
73
74
75 A note on JSON as used by RAPI
76 ++++++++++++++++++++++++++++++
77
78 JSON_ as used by Ganeti RAPI does not conform to the specification in
79 :rfc:`4627`. Section 2 defines a JSON text to be either an object
80 (``{"key": "value", …}``) or an array (``[1, 2, 3, …]``). In violation
81 of this RAPI uses plain strings (``"master-candidate"``, ``"1234"``) for
82 some requests or responses. Changing this now would likely break
83 existing clients and cause a lot of trouble.
84
85 .. highlight:: ruby
86
87 Unlike Python's `JSON encoder and decoder
88 <http://docs.python.org/library/json.html>`_, other programming
89 languages or libraries may only provide a strict implementation, not
90 allowing plain values. For those, responses can usually be wrapped in an
91 array whose first element is then used, e.g. the response ``"1234"``
92 becomes ``["1234"]``. This works equally well for more complex values.
93 Example in Ruby::
94
95   require "json"
96
97   # Insert code to get response here
98   response = "\"1234\""
99
100   decoded = JSON.parse("[#{response}]").first
101
102 Short of modifying the encoder to allow encoding to a less strict
103 format, requests will have to be formatted by hand. Newer RAPI requests
104 already use a dictionary as their input data and shouldn't cause any
105 problems.
106
107
108 PUT or POST?
109 ------------
110
111 According to RFC2616 the main difference between PUT and POST is that
112 POST can create new resources but PUT can only create the resource the
113 URI was pointing to on the PUT request.
114
115 Unfortunately, due to historic reasons, the Ganeti RAPI library is not
116 consistent with this usage, so just use the methods as documented below
117 for each resource.
118
119 For more details have a look in the source code at
120 ``lib/rapi/rlib2.py``.
121
122
123 Generic parameter types
124 -----------------------
125
126 A few generic refered parameter types and the values they allow.
127
128 ``bool``
129 ++++++++
130
131 A boolean option will accept ``1`` or ``0`` as numbers but not
132 i.e. ``True`` or ``False``.
133
134 Generic parameters
135 ------------------
136
137 A few parameter mean the same thing across all resources which implement
138 it.
139
140 ``bulk``
141 ++++++++
142
143 Bulk-mode means that for the resources which usually return just a list
144 of child resources (e.g. ``/2/instances`` which returns just instance
145 names), the output will instead contain detailed data for all these
146 subresources. This is more efficient than query-ing the sub-resources
147 themselves.
148
149 ``dry-run``
150 +++++++++++
151
152 The boolean *dry-run* argument, if provided and set, signals to Ganeti
153 that the job should not be executed, only the pre-execution checks will
154 be done.
155
156 This is useful in trying to determine (without guarantees though, as in
157 the meantime the cluster state could have changed) if the operation is
158 likely to succeed or at least start executing.
159
160 ``force``
161 +++++++++++
162
163 Force operation to continue even if it will cause the cluster to become
164 inconsistent (e.g. because there are not enough master candidates).
165
166 Usage examples
167 --------------
168
169 You can access the API using your favorite programming language as long
170 as it supports network connections.
171
172 Ganeti RAPI client
173 ++++++++++++++++++
174
175 Ganeti includes a standalone RAPI client, ``lib/rapi/client.py``.
176
177 Shell
178 +++++
179
180 .. highlight:: sh
181
182 Using wget::
183
184    wget -q -O - https://CLUSTERNAME:5080/2/info
185
186 or curl::
187
188   curl https://CLUSTERNAME:5080/2/info
189
190
191 Python
192 ++++++
193
194 .. highlight:: python
195
196 ::
197
198   import urllib2
199   f = urllib2.urlopen('https://CLUSTERNAME:5080/2/info')
200   print f.read()
201
202
203 JavaScript
204 ++++++++++
205
206 .. warning:: While it's possible to use JavaScript, it poses several
207    potential problems, including browser blocking request due to
208    non-standard ports or different domain names. Fetching the data on
209    the webserver is easier.
210
211 .. highlight:: javascript
212
213 ::
214
215   var url = 'https://CLUSTERNAME:5080/2/info';
216   var info;
217   var xmlreq = new XMLHttpRequest();
218   xmlreq.onreadystatechange = function () {
219     if (xmlreq.readyState != 4) return;
220     if (xmlreq.status == 200) {
221       info = eval("(" + xmlreq.responseText + ")");
222       alert(info);
223     } else {
224       alert('Error fetching cluster info');
225     }
226     xmlreq = null;
227   };
228   xmlreq.open('GET', url, true);
229   xmlreq.send(null);
230
231 Resources
232 ---------
233
234 .. highlight:: javascript
235
236 ``/``
237 +++++
238
239 The root resource.
240
241 It supports the following commands: ``GET``.
242
243 ``GET``
244 ~~~~~~~
245
246 Shows the list of mapped resources.
247
248 Returns: a dictionary with 'name' and 'uri' keys for each of them.
249
250 ``/2``
251 ++++++
252
253 The ``/2`` resource, the root of the version 2 API.
254
255 It supports the following commands: ``GET``.
256
257 ``GET``
258 ~~~~~~~
259
260 Show the list of mapped resources.
261
262 Returns: a dictionary with ``name`` and ``uri`` keys for each of them.
263
264 ``/2/info``
265 +++++++++++
266
267 Cluster information resource.
268
269 It supports the following commands: ``GET``.
270
271 ``GET``
272 ~~~~~~~
273
274 Returns cluster information.
275
276 Example::
277
278   {
279     "config_version": 2000000,
280     "name": "cluster",
281     "software_version": "2.0.0~beta2",
282     "os_api_version": 10,
283     "export_version": 0,
284     "candidate_pool_size": 10,
285     "enabled_hypervisors": [
286       "fake"
287     ],
288     "hvparams": {
289       "fake": {}
290      },
291     "default_hypervisor": "fake",
292     "master": "node1.example.com",
293     "architecture": [
294       "64bit",
295       "x86_64"
296     ],
297     "protocol_version": 20,
298     "beparams": {
299       "default": {
300         "auto_balance": true,
301         "vcpus": 1,
302         "memory": 128
303        }
304       }
305     }
306
307
308 ``/2/redistribute-config``
309 ++++++++++++++++++++++++++
310
311 Redistribute configuration to all nodes.
312
313 It supports the following commands: ``PUT``.
314
315 ``PUT``
316 ~~~~~~~
317
318 Redistribute configuration to all nodes. The result will be a job id.
319
320
321 ``/2/features``
322 +++++++++++++++
323
324 ``GET``
325 ~~~~~~~
326
327 Returns a list of features supported by the RAPI server. Available
328 features:
329
330 ``instance-create-reqv1``
331   Instance creation request data version 1 supported.
332
333
334 ``/2/instances``
335 ++++++++++++++++
336
337 The instances resource.
338
339 It supports the following commands: ``GET``, ``POST``.
340
341 ``GET``
342 ~~~~~~~
343
344 Returns a list of all available instances.
345
346 Example::
347
348     [
349       {
350         "name": "web.example.com",
351         "uri": "\/instances\/web.example.com"
352       },
353       {
354         "name": "mail.example.com",
355         "uri": "\/instances\/mail.example.com"
356       }
357     ]
358
359 If the optional bool *bulk* argument is provided and set to a true value
360 (i.e ``?bulk=1``), the output contains detailed information about
361 instances as a list.
362
363 Example::
364
365     [
366       {
367          "status": "running",
368          "disk_usage": 20480,
369          "nic.bridges": [
370            "xen-br0"
371           ],
372          "name": "web.example.com",
373          "tags": ["tag1", "tag2"],
374          "beparams": {
375            "vcpus": 2,
376            "memory": 512
377          },
378          "disk.sizes": [
379              20480
380          ],
381          "pnode": "node1.example.com",
382          "nic.macs": ["01:23:45:67:89:01"],
383          "snodes": ["node2.example.com"],
384          "disk_template": "drbd",
385          "admin_state": true,
386          "os": "debian-etch",
387          "oper_state": true
388       },
389       ...
390     ]
391
392
393 ``POST``
394 ~~~~~~~~
395
396 Creates an instance.
397
398 If the optional bool *dry-run* argument is provided, the job will not be
399 actually executed, only the pre-execution checks will be done. Query-ing
400 the job result will return, in both dry-run and normal case, the list of
401 nodes selected for the instance.
402
403 Returns: a job ID that can be used later for polling.
404
405 Body parameters:
406
407 ``__version__`` (int, required)
408   Must be ``1`` (older Ganeti versions used a different format for
409   instance creation requests, version ``0``, but that format is not
410   documented).
411 ``mode`` (string, required)
412   Instance creation mode.
413 ``name`` (string, required)
414   Instance name.
415 ``disk_template`` (string, required)
416   Disk template for instance.
417 ``disks`` (list, required)
418   List of disk definitions. Example: ``[{"size": 100}, {"size": 5}]``.
419   Each disk definition must contain a ``size`` value and can contain an
420   optional ``mode`` value denoting the disk access mode (``ro`` or
421   ``rw``).
422 ``nics`` (list, required)
423   List of NIC (network interface) definitions. Example: ``[{}, {},
424   {"ip": "198.51.100.4"}]``. Each NIC definition can contain the
425   optional values ``ip``, ``mode``, ``link`` and ``bridge``.
426 ``os`` (string, required)
427   Instance operating system.
428 ``osparams`` (dictionary)
429   Dictionary with OS parameters. If not valid for the given OS, the job
430   will fail.
431 ``force_variant`` (bool)
432   Whether to force an unknown variant.
433 ``pnode`` (string)
434   Primary node.
435 ``snode`` (string)
436   Secondary node.
437 ``src_node`` (string)
438   Source node for import.
439 ``src_path`` (string)
440   Source directory for import.
441 ``start`` (bool)
442   Whether to start instance after creation.
443 ``ip_check`` (bool)
444   Whether to ensure instance's IP address is inactive.
445 ``name_check`` (bool)
446   Whether to ensure instance's name is resolvable.
447 ``file_storage_dir`` (string)
448   File storage directory.
449 ``file_driver`` (string)
450   File storage driver.
451 ``iallocator`` (string)
452   Instance allocator name.
453 ``source_handshake`` (list)
454   Signed handshake from source (remote import only).
455 ``source_x509_ca`` (string)
456   Source X509 CA in PEM format (remote import only).
457 ``source_instance_name`` (string)
458   Source instance name (remote import only).
459 ``hypervisor`` (string)
460   Hypervisor name.
461 ``hvparams`` (dict)
462   Hypervisor parameters, hypervisor-dependent.
463 ``beparams`` (dict)
464   Backend parameters.
465
466
467 ``/2/instances/[instance_name]``
468 ++++++++++++++++++++++++++++++++
469
470 Instance-specific resource.
471
472 It supports the following commands: ``GET``, ``DELETE``.
473
474 ``GET``
475 ~~~~~~~
476
477 Returns information about an instance, similar to the bulk output from
478 the instance list.
479
480 ``DELETE``
481 ~~~~~~~~~~
482
483 Deletes an instance.
484
485 It supports the ``dry-run`` argument.
486
487
488 ``/2/instances/[instance_name]/info``
489 +++++++++++++++++++++++++++++++++++++++
490
491 It supports the following commands: ``GET``.
492
493 ``GET``
494 ~~~~~~~
495
496 Requests detailed information about the instance. An optional parameter,
497 ``static`` (bool), can be set to return only static information from the
498 configuration without querying the instance's nodes. The result will be
499 a job id.
500
501
502 ``/2/instances/[instance_name]/reboot``
503 +++++++++++++++++++++++++++++++++++++++
504
505 Reboots URI for an instance.
506
507 It supports the following commands: ``POST``.
508
509 ``POST``
510 ~~~~~~~~
511
512 Reboots the instance.
513
514 The URI takes optional ``type=soft|hard|full`` and
515 ``ignore_secondaries=0|1`` parameters.
516
517 ``type`` defines the reboot type. ``soft`` is just a normal reboot,
518 without terminating the hypervisor. ``hard`` means full shutdown
519 (including terminating the hypervisor process) and startup again.
520 ``full`` is like ``hard`` but also recreates the configuration from
521 ground up as if you would have done a ``gnt-instance shutdown`` and
522 ``gnt-instance start`` on it.
523
524 ``ignore_secondaries`` is a bool argument indicating if we start the
525 instance even if secondary disks are failing.
526
527 It supports the ``dry-run`` argument.
528
529
530 ``/2/instances/[instance_name]/shutdown``
531 +++++++++++++++++++++++++++++++++++++++++
532
533 Instance shutdown URI.
534
535 It supports the following commands: ``PUT``.
536
537 ``PUT``
538 ~~~~~~~
539
540 Shutdowns an instance.
541
542 It supports the ``dry-run`` argument.
543
544
545 ``/2/instances/[instance_name]/startup``
546 ++++++++++++++++++++++++++++++++++++++++
547
548 Instance startup URI.
549
550 It supports the following commands: ``PUT``.
551
552 ``PUT``
553 ~~~~~~~
554
555 Startup an instance.
556
557 The URI takes an optional ``force=1|0`` parameter to start the
558 instance even if secondary disks are failing.
559
560 It supports the ``dry-run`` argument.
561
562 ``/2/instances/[instance_name]/reinstall``
563 ++++++++++++++++++++++++++++++++++++++++++++++
564
565 Installs the operating system again.
566
567 It supports the following commands: ``POST``.
568
569 ``POST``
570 ~~~~~~~~
571
572 Takes the parameters ``os`` (OS template name) and ``nostartup`` (bool).
573
574
575 ``/2/instances/[instance_name]/replace-disks``
576 ++++++++++++++++++++++++++++++++++++++++++++++
577
578 Replaces disks on an instance.
579
580 It supports the following commands: ``POST``.
581
582 ``POST``
583 ~~~~~~~~
584
585 Takes the parameters ``mode`` (one of ``replace_on_primary``,
586 ``replace_on_secondary``, ``replace_new_secondary`` or
587 ``replace_auto``), ``disks`` (comma separated list of disk indexes),
588 ``remote_node`` and ``iallocator``.
589
590 Either ``remote_node`` or ``iallocator`` needs to be defined when using
591 ``mode=replace_new_secondary``.
592
593 ``mode`` is a mandatory parameter. ``replace_auto`` tries to determine
594 the broken disk(s) on its own and replacing it.
595
596
597 ``/2/instances/[instance_name]/activate-disks``
598 +++++++++++++++++++++++++++++++++++++++++++++++
599
600 Activate disks on an instance.
601
602 It supports the following commands: ``PUT``.
603
604 ``PUT``
605 ~~~~~~~
606
607 Takes the bool parameter ``ignore_size``. When set ignore the recorded
608 size (useful for forcing activation when recorded size is wrong).
609
610
611 ``/2/instances/[instance_name]/deactivate-disks``
612 +++++++++++++++++++++++++++++++++++++++++++++++++
613
614 Deactivate disks on an instance.
615
616 It supports the following commands: ``PUT``.
617
618 ``PUT``
619 ~~~~~~~
620
621 Takes no parameters.
622
623
624 ``/2/instances/[instance_name]/prepare-export``
625 +++++++++++++++++++++++++++++++++++++++++++++++++
626
627 Prepares an export of an instance.
628
629 It supports the following commands: ``PUT``.
630
631 ``PUT``
632 ~~~~~~~
633
634 Takes one parameter, ``mode``, for the export mode. Returns a job ID.
635
636
637 ``/2/instances/[instance_name]/export``
638 +++++++++++++++++++++++++++++++++++++++++++++++++
639
640 Exports an instance.
641
642 It supports the following commands: ``PUT``.
643
644 ``PUT``
645 ~~~~~~~
646
647 Returns a job ID.
648
649 Body parameters:
650
651 ``mode`` (string)
652   Export mode.
653 ``destination`` (required)
654   Destination information, depends on export mode.
655 ``shutdown`` (bool, required)
656   Whether to shutdown instance before export.
657 ``remove_instance`` (bool)
658   Whether to remove instance after export.
659 ``x509_key_name``
660   Name of X509 key (remote export only).
661 ``destination_x509_ca``
662   Destination X509 CA (remote export only).
663
664
665 ``/2/instances/[instance_name]/migrate``
666 ++++++++++++++++++++++++++++++++++++++++
667
668 Migrates an instance.
669
670 Supports the following commands: ``PUT``.
671
672 ``PUT``
673 ~~~~~~~
674
675 Returns a job ID.
676
677 Body parameters:
678
679 ``mode`` (string)
680   Migration mode.
681 ``cleanup`` (bool)
682   Whether a previously failed migration should be cleaned up.
683
684
685 ``/2/instances/[instance_name]/rename``
686 ++++++++++++++++++++++++++++++++++++++++
687
688 Renames an instance.
689
690 Supports the following commands: ``PUT``.
691
692 ``PUT``
693 ~~~~~~~
694
695 Returns a job ID.
696
697 Body parameters:
698
699 ``new_name`` (string, required)
700   New instance name.
701 ``ip_check`` (bool)
702   Whether to ensure instance's IP address is inactive.
703 ``name_check`` (bool)
704   Whether to ensure instance's name is resolvable.
705
706
707 ``/2/instances/[instance_name]/modify``
708 ++++++++++++++++++++++++++++++++++++++++
709
710 Modifies an instance.
711
712 Supports the following commands: ``PUT``.
713
714 ``PUT``
715 ~~~~~~~
716
717 Returns a job ID.
718
719 Body parameters:
720
721 ``osparams`` (dict)
722   Dictionary with OS parameters.
723 ``hvparams`` (dict)
724   Hypervisor parameters, hypervisor-dependent.
725 ``beparams`` (dict)
726   Backend parameters.
727 ``force`` (bool)
728   Whether to force the operation.
729 ``nics`` (list)
730   List of NIC changes. Each item is of the form ``(op, settings)``.
731   ``op`` can be ``add`` to add a new NIC with the specified settings,
732   ``remove`` to remove the last NIC or a number to modify the settings
733   of the NIC with that index.
734 ``disks`` (list)
735   List of disk changes. See ``nics``.
736 ``disk_template`` (string)
737   Disk template for instance.
738 ``remote_node`` (string)
739   Secondary node (used when changing disk template).
740 ``os_name`` (string)
741   Change instance's OS name. Does not reinstall the instance.
742 ``force_variant`` (bool)
743   Whether to force an unknown variant.
744
745
746 ``/2/instances/[instance_name]/tags``
747 +++++++++++++++++++++++++++++++++++++
748
749 Manages per-instance tags.
750
751 It supports the following commands: ``GET``, ``PUT``, ``DELETE``.
752
753 ``GET``
754 ~~~~~~~
755
756 Returns a list of tags.
757
758 Example::
759
760     ["tag1", "tag2", "tag3"]
761
762 ``PUT``
763 ~~~~~~~
764
765 Add a set of tags.
766
767 The request as a list of strings should be ``PUT`` to this URI. The
768 result will be a job id.
769
770 It supports the ``dry-run`` argument.
771
772
773 ``DELETE``
774 ~~~~~~~~~~
775
776 Delete a tag.
777
778 In order to delete a set of tags, the DELETE request should be addressed
779 to URI like::
780
781     /tags?tag=[tag]&tag=[tag]
782
783 It supports the ``dry-run`` argument.
784
785
786 ``/2/jobs``
787 +++++++++++
788
789 The ``/2/jobs`` resource.
790
791 It supports the following commands: ``GET``.
792
793 ``GET``
794 ~~~~~~~
795
796 Returns a dictionary of jobs.
797
798 Returns: a dictionary with jobs id and uri.
799
800 ``/2/jobs/[job_id]``
801 ++++++++++++++++++++
802
803
804 Individual job URI.
805
806 It supports the following commands: ``GET``, ``DELETE``.
807
808 ``GET``
809 ~~~~~~~
810
811 Returns a job status.
812
813 Returns: a dictionary with job parameters.
814
815 The result includes:
816
817 - id: job ID as a number
818 - status: current job status as a string
819 - ops: involved OpCodes as a list of dictionaries for each opcodes in
820   the job
821 - opstatus: OpCodes status as a list
822 - opresult: OpCodes results as a list
823
824 For a successful opcode, the ``opresult`` field corresponding to it will
825 contain the raw result from its :term:`LogicalUnit`. In case an opcode
826 has failed, its element in the opresult list will be a list of two
827 elements:
828
829 - first element the error type (the Ganeti internal error name)
830 - second element a list of either one or two elements:
831
832   - the first element is the textual error description
833   - the second element, if any, will hold an error classification
834
835 The error classification is most useful for the ``OpPrereqError``
836 error type - these errors happen before the OpCode has started
837 executing, so it's possible to retry the OpCode without side
838 effects. But whether it make sense to retry depends on the error
839 classification:
840
841 ``resolver_error``
842   Resolver errors. This usually means that a name doesn't exist in DNS,
843   so if it's a case of slow DNS propagation the operation can be retried
844   later.
845
846 ``insufficient_resources``
847   Not enough resources (iallocator failure, disk space, memory,
848   etc.). If the resources on the cluster increase, the operation might
849   succeed.
850
851 ``wrong_input``
852   Wrong arguments (at syntax level). The operation will not ever be
853   accepted unless the arguments change.
854
855 ``wrong_state``
856   Wrong entity state. For example, live migration has been requested for
857   a down instance, or instance creation on an offline node. The
858   operation can be retried once the resource has changed state.
859
860 ``unknown_entity``
861   Entity not found. For example, information has been requested for an
862   unknown instance.
863
864 ``already_exists``
865   Entity already exists. For example, instance creation has been
866   requested for an already-existing instance.
867
868 ``resource_not_unique``
869   Resource not unique (e.g. MAC or IP duplication).
870
871 ``internal_error``
872   Internal cluster error. For example, a node is unreachable but not set
873   offline, or the ganeti node daemons are not working, etc. A
874   ``gnt-cluster verify`` should be run.
875
876 ``environment_error``
877   Environment error (e.g. node disk error). A ``gnt-cluster verify``
878   should be run.
879
880 Note that in the above list, by entity we refer to a node or instance,
881 while by a resource we refer to an instance's disk, or NIC, etc.
882
883
884 ``DELETE``
885 ~~~~~~~~~~
886
887 Cancel a not-yet-started job.
888
889
890 ``/2/jobs/[job_id]/wait``
891 +++++++++++++++++++++++++
892
893 ``GET``
894 ~~~~~~~
895
896 Waits for changes on a job. Takes the following body parameters in a
897 dict:
898
899 ``fields``
900   The job fields on which to watch for changes.
901
902 ``previous_job_info``
903   Previously received field values or None if not yet available.
904
905 ``previous_log_serial``
906   Highest log serial number received so far or None if not yet
907   available.
908
909 Returns None if no changes have been detected and a dict with two keys,
910 ``job_info`` and ``log_entries`` otherwise.
911
912
913 ``/2/nodes``
914 ++++++++++++
915
916 Nodes resource.
917
918 It supports the following commands: ``GET``.
919
920 ``GET``
921 ~~~~~~~
922
923 Returns a list of all nodes.
924
925 Example::
926
927     [
928       {
929         "id": "node1.example.com",
930         "uri": "\/nodes\/node1.example.com"
931       },
932       {
933         "id": "node2.example.com",
934         "uri": "\/nodes\/node2.example.com"
935       }
936     ]
937
938 If the optional 'bulk' argument is provided and set to 'true' value (i.e
939 '?bulk=1'), the output contains detailed information about nodes as a
940 list.
941
942 Example::
943
944     [
945       {
946         "pinst_cnt": 1,
947         "mfree": 31280,
948         "mtotal": 32763,
949         "name": "www.example.com",
950         "tags": [],
951         "mnode": 512,
952         "dtotal": 5246208,
953         "sinst_cnt": 2,
954         "dfree": 5171712,
955         "offline": false
956       },
957       ...
958     ]
959
960 ``/2/nodes/[node_name]``
961 +++++++++++++++++++++++++++++++++
962
963 Returns information about a node.
964
965 It supports the following commands: ``GET``.
966
967 ``/2/nodes/[node_name]/evacuate``
968 +++++++++++++++++++++++++++++++++
969
970 Evacuates all secondary instances off a node.
971
972 It supports the following commands: ``POST``.
973
974 ``POST``
975 ~~~~~~~~
976
977 To evacuate a node, either one of the ``iallocator`` or ``remote_node``
978 parameters must be passed::
979
980     evacuate?iallocator=[iallocator]
981     evacuate?remote_node=[nodeX.example.com]
982
983 The result value will be a list, each element being a triple of the job
984 id (for this specific evacuation), the instance which is being evacuated
985 by this job, and the node to which it is being relocated. In case the
986 node is already empty, the result will be an empty list (without any
987 jobs being submitted).
988
989 And additional parameter ``early_release`` signifies whether to try to
990 parallelize the evacuations, at the risk of increasing I/O contention
991 and increasing the chances of data loss, if the primary node of any of
992 the instances being evacuated is not fully healthy.
993
994 If the dry-run parameter was specified, then the evacuation jobs were
995 not actually submitted, and the job IDs will be null.
996
997
998 ``/2/nodes/[node_name]/migrate``
999 +++++++++++++++++++++++++++++++++
1000
1001 Migrates all primary instances from a node.
1002
1003 It supports the following commands: ``POST``.
1004
1005 ``POST``
1006 ~~~~~~~~
1007
1008 No parameters are required, but the bool parameter ``live`` can be set
1009 to use live migration (if available).
1010
1011     migrate?live=[0|1]
1012
1013 ``/2/nodes/[node_name]/role``
1014 +++++++++++++++++++++++++++++
1015
1016 Manages node role.
1017
1018 It supports the following commands: ``GET``, ``PUT``.
1019
1020 The role is always one of the following:
1021
1022   - drained
1023   - master
1024   - master-candidate
1025   - offline
1026   - regular
1027
1028 ``GET``
1029 ~~~~~~~
1030
1031 Returns the current node role.
1032
1033 Example::
1034
1035     "master-candidate"
1036
1037 ``PUT``
1038 ~~~~~~~
1039
1040 Change the node role.
1041
1042 The request is a string which should be PUT to this URI. The result will
1043 be a job id.
1044
1045 It supports the bool ``force`` argument.
1046
1047 ``/2/nodes/[node_name]/storage``
1048 ++++++++++++++++++++++++++++++++
1049
1050 Manages storage units on the node.
1051
1052 ``GET``
1053 ~~~~~~~
1054
1055 Requests a list of storage units on a node. Requires the parameters
1056 ``storage_type`` (one of ``file``, ``lvm-pv`` or ``lvm-vg``) and
1057 ``output_fields``. The result will be a job id, using which the result
1058 can be retrieved.
1059
1060 ``/2/nodes/[node_name]/storage/modify``
1061 +++++++++++++++++++++++++++++++++++++++
1062
1063 Modifies storage units on the node.
1064
1065 ``PUT``
1066 ~~~~~~~
1067
1068 Modifies parameters of storage units on the node. Requires the
1069 parameters ``storage_type`` (one of ``file``, ``lvm-pv`` or ``lvm-vg``)
1070 and ``name`` (name of the storage unit).  Parameters can be passed
1071 additionally. Currently only ``allocatable`` (bool) is supported. The
1072 result will be a job id.
1073
1074 ``/2/nodes/[node_name]/storage/repair``
1075 +++++++++++++++++++++++++++++++++++++++
1076
1077 Repairs a storage unit on the node.
1078
1079 ``PUT``
1080 ~~~~~~~
1081
1082 Repairs a storage unit on the node. Requires the parameters
1083 ``storage_type`` (currently only ``lvm-vg`` can be repaired) and
1084 ``name`` (name of the storage unit). The result will be a job id.
1085
1086 ``/2/nodes/[node_name]/tags``
1087 +++++++++++++++++++++++++++++
1088
1089 Manages per-node tags.
1090
1091 It supports the following commands: ``GET``, ``PUT``, ``DELETE``.
1092
1093 ``GET``
1094 ~~~~~~~
1095
1096 Returns a list of tags.
1097
1098 Example::
1099
1100     ["tag1", "tag2", "tag3"]
1101
1102 ``PUT``
1103 ~~~~~~~
1104
1105 Add a set of tags.
1106
1107 The request as a list of strings should be PUT to this URI. The result
1108 will be a job id.
1109
1110 It supports the ``dry-run`` argument.
1111
1112 ``DELETE``
1113 ~~~~~~~~~~
1114
1115 Deletes tags.
1116
1117 In order to delete a set of tags, the DELETE request should be addressed
1118 to URI like::
1119
1120     /tags?tag=[tag]&tag=[tag]
1121
1122 It supports the ``dry-run`` argument.
1123
1124
1125 ``/2/os``
1126 +++++++++
1127
1128 OS resource.
1129
1130 It supports the following commands: ``GET``.
1131
1132 ``GET``
1133 ~~~~~~~
1134
1135 Return a list of all OSes.
1136
1137 Can return error 500 in case of a problem. Since this is a costly
1138 operation for Ganeti 2.0, it is not recommended to execute it too often.
1139
1140 Example::
1141
1142     ["debian-etch"]
1143
1144 ``/2/tags``
1145 +++++++++++
1146
1147 Manages cluster tags.
1148
1149 It supports the following commands: ``GET``, ``PUT``, ``DELETE``.
1150
1151 ``GET``
1152 ~~~~~~~
1153
1154 Returns the cluster tags.
1155
1156 Example::
1157
1158     ["tag1", "tag2", "tag3"]
1159
1160 ``PUT``
1161 ~~~~~~~
1162
1163 Adds a set of tags.
1164
1165 The request as a list of strings should be PUT to this URI. The result
1166 will be a job id.
1167
1168 It supports the ``dry-run`` argument.
1169
1170
1171 ``DELETE``
1172 ~~~~~~~~~~
1173
1174 Deletes tags.
1175
1176 In order to delete a set of tags, the DELETE request should be addressed
1177 to URI like::
1178
1179     /tags?tag=[tag]&tag=[tag]
1180
1181 It supports the ``dry-run`` argument.
1182
1183
1184 ``/version``
1185 ++++++++++++
1186
1187 The version resource.
1188
1189 This resource should be used to determine the remote API version and to
1190 adapt clients accordingly.
1191
1192 It supports the following commands: ``GET``.
1193
1194 ``GET``
1195 ~~~~~~~
1196
1197 Returns the remote API version. Ganeti 1.2 returned ``1`` and Ganeti 2.0
1198 returns ``2``.
1199
1200 .. vim: set textwidth=72 :
1201 .. Local Variables:
1202 .. mode: rst
1203 .. fill-column: 72
1204 .. End: