4 Documents Ganeti version |version|
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
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.
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.
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.
44 # Give Jack and Fred read-only access
46 fred {cleartext}foo555
48 # Give write access to an imaginary instance creation script
49 autocreator xyz789 write
51 # Hashed password for Jessica
52 jessica {HA1}7046452df2cbb530877058712cf17bd4 write
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.
67 The protocol used is JSON_ over HTTP designed after the REST_ principle.
68 HTTP Basic authentication as per RFC2617_ is supported.
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
78 According to RFC2616 the main difference between PUT and POST is that
79 POST can create new resources but PUT can only create the resource the
80 URI was pointing to on the PUT request.
82 Unfortunately, due to historic reasons, the Ganeti RAPI library is not
83 consistent with this usage, so just use the methods as documented below
86 For more details have a look in the source code at
87 ``lib/rapi/rlib2.py``.
90 Generic parameter types
91 -----------------------
93 A few generic refered parameter types and the values they allow.
98 A boolean option will accept ``1`` or ``0`` as numbers but not
99 i.e. ``True`` or ``False``.
104 A few parameter mean the same thing across all resources which implement
110 Bulk-mode means that for the resources which usually return just a list
111 of child resources (e.g. ``/2/instances`` which returns just instance
112 names), the output will instead contain detailed data for all these
113 subresources. This is more efficient than query-ing the sub-resources
119 The boolean *dry-run* argument, if provided and set, signals to Ganeti
120 that the job should not be executed, only the pre-execution checks will
123 This is useful in trying to determine (without guarantees though, as in
124 the meantime the cluster state could have changed) if the operation is
125 likely to succeed or at least start executing.
130 Force operation to continue even if it will cause the cluster to become
131 inconsistent (e.g. because there are not enough master candidates).
136 You can access the API using your favorite programming language as long
137 as it supports network connections.
142 Ganeti includes a standalone RAPI client, ``lib/rapi/client.py``.
151 wget -q -O - https://CLUSTERNAME:5080/2/info
155 curl https://CLUSTERNAME:5080/2/info
161 .. highlight:: python
166 f = urllib2.urlopen('https://CLUSTERNAME:5080/2/info')
173 .. warning:: While it's possible to use JavaScript, it poses several
174 potential problems, including browser blocking request due to
175 non-standard ports or different domain names. Fetching the data on
176 the webserver is easier.
178 .. highlight:: javascript
182 var url = 'https://CLUSTERNAME:5080/2/info';
184 var xmlreq = new XMLHttpRequest();
185 xmlreq.onreadystatechange = function () {
186 if (xmlreq.readyState != 4) return;
187 if (xmlreq.status == 200) {
188 info = eval("(" + xmlreq.responseText + ")");
191 alert('Error fetching cluster info');
195 xmlreq.open('GET', url, true);
201 .. highlight:: javascript
208 It supports the following commands: ``GET``.
213 Shows the list of mapped resources.
215 Returns: a dictionary with 'name' and 'uri' keys for each of them.
220 The ``/2`` resource, the root of the version 2 API.
222 It supports the following commands: ``GET``.
227 Show the list of mapped resources.
229 Returns: a dictionary with ``name`` and ``uri`` keys for each of them.
234 Cluster information resource.
236 It supports the following commands: ``GET``.
241 Returns cluster information.
246 "config_version": 2000000,
248 "software_version": "2.0.0~beta2",
249 "os_api_version": 10,
251 "candidate_pool_size": 10,
252 "enabled_hypervisors": [
258 "default_hypervisor": "fake",
259 "master": "node1.example.com",
264 "protocol_version": 20,
267 "auto_balance": true,
275 ``/2/redistribute-config``
276 ++++++++++++++++++++++++++
278 Redistribute configuration to all nodes.
280 It supports the following commands: ``PUT``.
285 Redistribute configuration to all nodes. The result will be a job id.
294 Returns a list of features supported by the RAPI server. Available
297 ``instance-create-reqv1``
298 Instance creation request data version 1 supported.
304 The instances resource.
306 It supports the following commands: ``GET``, ``POST``.
311 Returns a list of all available instances.
317 "name": "web.example.com",
318 "uri": "\/instances\/web.example.com"
321 "name": "mail.example.com",
322 "uri": "\/instances\/mail.example.com"
326 If the optional bool *bulk* argument is provided and set to a true value
327 (i.e ``?bulk=1``), the output contains detailed information about
339 "name": "web.example.com",
340 "tags": ["tag1", "tag2"],
348 "pnode": "node1.example.com",
349 "nic.macs": ["01:23:45:67:89:01"],
350 "snodes": ["node2.example.com"],
351 "disk_template": "drbd",
365 If the optional bool *dry-run* argument is provided, the job will not be
366 actually executed, only the pre-execution checks will be done. Query-ing
367 the job result will return, in both dry-run and normal case, the list of
368 nodes selected for the instance.
370 Returns: a job ID that can be used later for polling.
374 ``__version__`` (int, required)
375 Must be ``1`` (older Ganeti versions used a different format for
376 instance creation requests, version ``0``, but that format is not
379 Instance creation mode (string, required).
380 ``name`` (string, required)
382 ``disk_template`` (string, required)
383 Disk template for instance
384 ``disks`` (list, required)
385 List of disk definitions. Example: ``[{"size": 100}, {"size": 5}]``.
386 Each disk definition must contain a ``size`` value and can contain an
387 optional ``mode`` value denoting the disk access mode (``ro`` or
389 ``nics`` (list, required)
390 List of NIC (network interface) definitions. Example: ``[{}, {},
391 {"ip": "198.51.100.4"}]``. Each NIC definition can contain the
392 optional values ``ip``, ``mode``, ``link`` and ``bridge``.
393 ``os`` (string, required)
394 Instance operating system.
395 ``osparams`` (dictionary)
396 Dictionary with OS parameters. If not valid for the given OS, the job
398 ``force_variant`` (bool)
399 Whether to force an unknown variant.
404 ``src_node`` (string)
405 Source node for import.
406 ``src_path`` (string)
407 Source directory for import.
409 Whether to start instance after creation.
411 Whether to ensure instance's IP address is inactive.
412 ``name_check`` (bool)
413 Whether to ensure instance's name is resolvable.
414 ``file_storage_dir`` (string)
415 File storage directory.
416 ``file_driver`` (string)
418 ``iallocator`` (string)
419 Instance allocator name.
421 Signed handshake from source (remote import only).
422 ``source_x509_ca`` (string)
423 Source X509 CA in PEM format (remote import only).
424 ``source_instance_name`` (string)
425 Source instance name (remote import only).
426 ``hypervisor`` (string)
429 Hypervisor parameters, hypervisor-dependent.
434 ``/2/instances/[instance_name]``
435 ++++++++++++++++++++++++++++++++
437 Instance-specific resource.
439 It supports the following commands: ``GET``, ``DELETE``.
444 Returns information about an instance, similar to the bulk output from
452 It supports the ``dry-run`` argument.
455 ``/2/instances/[instance_name]/info``
456 +++++++++++++++++++++++++++++++++++++++
458 It supports the following commands: ``GET``.
463 Requests detailed information about the instance. An optional parameter,
464 ``static`` (bool), can be set to return only static information from the
465 configuration without querying the instance's nodes. The result will be
469 ``/2/instances/[instance_name]/reboot``
470 +++++++++++++++++++++++++++++++++++++++
472 Reboots URI for an instance.
474 It supports the following commands: ``POST``.
479 Reboots the instance.
481 The URI takes optional ``type=soft|hard|full`` and
482 ``ignore_secondaries=0|1`` parameters.
484 ``type`` defines the reboot type. ``soft`` is just a normal reboot,
485 without terminating the hypervisor. ``hard`` means full shutdown
486 (including terminating the hypervisor process) and startup again.
487 ``full`` is like ``hard`` but also recreates the configuration from
488 ground up as if you would have done a ``gnt-instance shutdown`` and
489 ``gnt-instance start`` on it.
491 ``ignore_secondaries`` is a bool argument indicating if we start the
492 instance even if secondary disks are failing.
494 It supports the ``dry-run`` argument.
497 ``/2/instances/[instance_name]/shutdown``
498 +++++++++++++++++++++++++++++++++++++++++
500 Instance shutdown URI.
502 It supports the following commands: ``PUT``.
507 Shutdowns an instance.
509 It supports the ``dry-run`` argument.
512 ``/2/instances/[instance_name]/startup``
513 ++++++++++++++++++++++++++++++++++++++++
515 Instance startup URI.
517 It supports the following commands: ``PUT``.
524 The URI takes an optional ``force=1|0`` parameter to start the
525 instance even if secondary disks are failing.
527 It supports the ``dry-run`` argument.
529 ``/2/instances/[instance_name]/reinstall``
530 ++++++++++++++++++++++++++++++++++++++++++++++
532 Installs the operating system again.
534 It supports the following commands: ``POST``.
539 Takes the parameters ``os`` (OS template name) and ``nostartup`` (bool).
542 ``/2/instances/[instance_name]/replace-disks``
543 ++++++++++++++++++++++++++++++++++++++++++++++
545 Replaces disks on an instance.
547 It supports the following commands: ``POST``.
552 Takes the parameters ``mode`` (one of ``replace_on_primary``,
553 ``replace_on_secondary``, ``replace_new_secondary`` or
554 ``replace_auto``), ``disks`` (comma separated list of disk indexes),
555 ``remote_node`` and ``iallocator``.
557 Either ``remote_node`` or ``iallocator`` needs to be defined when using
558 ``mode=replace_new_secondary``.
560 ``mode`` is a mandatory parameter. ``replace_auto`` tries to determine
561 the broken disk(s) on its own and replacing it.
564 ``/2/instances/[instance_name]/activate-disks``
565 +++++++++++++++++++++++++++++++++++++++++++++++
567 Activate disks on an instance.
569 It supports the following commands: ``PUT``.
574 Takes the bool parameter ``ignore_size``. When set ignore the recorded
575 size (useful for forcing activation when recorded size is wrong).
578 ``/2/instances/[instance_name]/deactivate-disks``
579 +++++++++++++++++++++++++++++++++++++++++++++++++
581 Deactivate disks on an instance.
583 It supports the following commands: ``PUT``.
591 ``/2/instances/[instance_name]/prepare-export``
592 +++++++++++++++++++++++++++++++++++++++++++++++++
594 Prepares an export of an instance.
596 It supports the following commands: ``PUT``.
601 Takes one parameter, ``mode``, for the export mode. Returns a job ID.
604 ``/2/instances/[instance_name]/export``
605 +++++++++++++++++++++++++++++++++++++++++++++++++
609 It supports the following commands: ``PUT``.
620 ``destination`` (required)
621 Destination information, depends on export mode.
622 ``shutdown`` (bool, required)
623 Whether to shutdown instance before export.
624 ``remove_instance`` (bool)
625 Whether to remove instance after export.
627 Name of X509 key (remote export only).
628 ``destination_x509_ca``
629 Destination X509 CA (remote export only).
632 ``/2/instances/[instance_name]/migrate``
633 ++++++++++++++++++++++++++++++++++++++++
635 Migrates an instance.
637 Supports the following commands: ``PUT``.
649 Whether a previously failed migration should be cleaned up.
652 ``/2/instances/[instance_name]/rename``
653 ++++++++++++++++++++++++++++++++++++++++
657 Supports the following commands: ``PUT``.
666 ``new_name`` (string, required)
669 Whether to ensure instance's IP address is inactive.
670 ``name_check`` (bool)
671 Whether to ensure instance's name is resolvable.
674 ``/2/instances/[instance_name]/tags``
675 +++++++++++++++++++++++++++++++++++++
677 Manages per-instance tags.
679 It supports the following commands: ``GET``, ``PUT``, ``DELETE``.
684 Returns a list of tags.
688 ["tag1", "tag2", "tag3"]
695 The request as a list of strings should be ``PUT`` to this URI. The
696 result will be a job id.
698 It supports the ``dry-run`` argument.
706 In order to delete a set of tags, the DELETE request should be addressed
709 /tags?tag=[tag]&tag=[tag]
711 It supports the ``dry-run`` argument.
717 The ``/2/jobs`` resource.
719 It supports the following commands: ``GET``.
724 Returns a dictionary of jobs.
726 Returns: a dictionary with jobs id and uri.
734 It supports the following commands: ``GET``, ``DELETE``.
739 Returns a job status.
741 Returns: a dictionary with job parameters.
745 - id: job ID as a number
746 - status: current job status as a string
747 - ops: involved OpCodes as a list of dictionaries for each opcodes in
749 - opstatus: OpCodes status as a list
750 - opresult: OpCodes results as a list
752 For a successful opcode, the ``opresult`` field corresponding to it will
753 contain the raw result from its :term:`LogicalUnit`. In case an opcode
754 has failed, its element in the opresult list will be a list of two
757 - first element the error type (the Ganeti internal error name)
758 - second element a list of either one or two elements:
760 - the first element is the textual error description
761 - the second element, if any, will hold an error classification
763 The error classification is most useful for the ``OpPrereqError``
764 error type - these errors happen before the OpCode has started
765 executing, so it's possible to retry the OpCode without side
766 effects. But whether it make sense to retry depends on the error
770 Resolver errors. This usually means that a name doesn't exist in DNS,
771 so if it's a case of slow DNS propagation the operation can be retried
774 ``insufficient_resources``
775 Not enough resources (iallocator failure, disk space, memory,
776 etc.). If the resources on the cluster increase, the operation might
780 Wrong arguments (at syntax level). The operation will not ever be
781 accepted unless the arguments change.
784 Wrong entity state. For example, live migration has been requested for
785 a down instance, or instance creation on an offline node. The
786 operation can be retried once the resource has changed state.
789 Entity not found. For example, information has been requested for an
793 Entity already exists. For example, instance creation has been
794 requested for an already-existing instance.
796 ``resource_not_unique``
797 Resource not unique (e.g. MAC or IP duplication).
800 Internal cluster error. For example, a node is unreachable but not set
801 offline, or the ganeti node daemons are not working, etc. A
802 ``gnt-cluster verify`` should be run.
804 ``environment_error``
805 Environment error (e.g. node disk error). A ``gnt-cluster verify``
808 Note that in the above list, by entity we refer to a node or instance,
809 while by a resource we refer to an instance's disk, or NIC, etc.
815 Cancel a not-yet-started job.
818 ``/2/jobs/[job_id]/wait``
819 +++++++++++++++++++++++++
824 Waits for changes on a job. Takes the following body parameters in a
828 The job fields on which to watch for changes.
830 ``previous_job_info``
831 Previously received field values or None if not yet available.
833 ``previous_log_serial``
834 Highest log serial number received so far or None if not yet
837 Returns None if no changes have been detected and a dict with two keys,
838 ``job_info`` and ``log_entries`` otherwise.
846 It supports the following commands: ``GET``.
851 Returns a list of all nodes.
857 "id": "node1.example.com",
858 "uri": "\/nodes\/node1.example.com"
861 "id": "node2.example.com",
862 "uri": "\/nodes\/node2.example.com"
866 If the optional 'bulk' argument is provided and set to 'true' value (i.e
867 '?bulk=1'), the output contains detailed information about nodes as a
877 "name": "www.example.com",
888 ``/2/nodes/[node_name]``
889 +++++++++++++++++++++++++++++++++
891 Returns information about a node.
893 It supports the following commands: ``GET``.
895 ``/2/nodes/[node_name]/evacuate``
896 +++++++++++++++++++++++++++++++++
898 Evacuates all secondary instances off a node.
900 It supports the following commands: ``POST``.
905 To evacuate a node, either one of the ``iallocator`` or ``remote_node``
906 parameters must be passed::
908 evacuate?iallocator=[iallocator]
909 evacuate?remote_node=[nodeX.example.com]
911 The result value will be a list, each element being a triple of the job
912 id (for this specific evacuation), the instance which is being evacuated
913 by this job, and the node to which it is being relocated. In case the
914 node is already empty, the result will be an empty list (without any
915 jobs being submitted).
917 And additional parameter ``early_release`` signifies whether to try to
918 parallelize the evacuations, at the risk of increasing I/O contention
919 and increasing the chances of data loss, if the primary node of any of
920 the instances being evacuated is not fully healthy.
922 If the dry-run parameter was specified, then the evacuation jobs were
923 not actually submitted, and the job IDs will be null.
926 ``/2/nodes/[node_name]/migrate``
927 +++++++++++++++++++++++++++++++++
929 Migrates all primary instances from a node.
931 It supports the following commands: ``POST``.
936 No parameters are required, but the bool parameter ``live`` can be set
937 to use live migration (if available).
941 ``/2/nodes/[node_name]/role``
942 +++++++++++++++++++++++++++++
946 It supports the following commands: ``GET``, ``PUT``.
948 The role is always one of the following:
959 Returns the current node role.
968 Change the node role.
970 The request is a string which should be PUT to this URI. The result will
973 It supports the bool ``force`` argument.
975 ``/2/nodes/[node_name]/storage``
976 ++++++++++++++++++++++++++++++++
978 Manages storage units on the node.
983 Requests a list of storage units on a node. Requires the parameters
984 ``storage_type`` (one of ``file``, ``lvm-pv`` or ``lvm-vg``) and
985 ``output_fields``. The result will be a job id, using which the result
988 ``/2/nodes/[node_name]/storage/modify``
989 +++++++++++++++++++++++++++++++++++++++
991 Modifies storage units on the node.
996 Modifies parameters of storage units on the node. Requires the
997 parameters ``storage_type`` (one of ``file``, ``lvm-pv`` or ``lvm-vg``)
998 and ``name`` (name of the storage unit). Parameters can be passed
999 additionally. Currently only ``allocatable`` (bool) is supported. The
1000 result will be a job id.
1002 ``/2/nodes/[node_name]/storage/repair``
1003 +++++++++++++++++++++++++++++++++++++++
1005 Repairs a storage unit on the node.
1010 Repairs a storage unit on the node. Requires the parameters
1011 ``storage_type`` (currently only ``lvm-vg`` can be repaired) and
1012 ``name`` (name of the storage unit). The result will be a job id.
1014 ``/2/nodes/[node_name]/tags``
1015 +++++++++++++++++++++++++++++
1017 Manages per-node tags.
1019 It supports the following commands: ``GET``, ``PUT``, ``DELETE``.
1024 Returns a list of tags.
1028 ["tag1", "tag2", "tag3"]
1035 The request as a list of strings should be PUT to this URI. The result
1038 It supports the ``dry-run`` argument.
1045 In order to delete a set of tags, the DELETE request should be addressed
1048 /tags?tag=[tag]&tag=[tag]
1050 It supports the ``dry-run`` argument.
1058 It supports the following commands: ``GET``.
1063 Return a list of all OSes.
1065 Can return error 500 in case of a problem. Since this is a costly
1066 operation for Ganeti 2.0, it is not recommended to execute it too often.
1075 Manages cluster tags.
1077 It supports the following commands: ``GET``, ``PUT``, ``DELETE``.
1082 Returns the cluster tags.
1086 ["tag1", "tag2", "tag3"]
1093 The request as a list of strings should be PUT to this URI. The result
1096 It supports the ``dry-run`` argument.
1104 In order to delete a set of tags, the DELETE request should be addressed
1107 /tags?tag=[tag]&tag=[tag]
1109 It supports the ``dry-run`` argument.
1115 The version resource.
1117 This resource should be used to determine the remote API version and to
1118 adapt clients accordingly.
1120 It supports the following commands: ``GET``.
1125 Returns the remote API version. Ganeti 1.2 returned ``1`` and Ganeti 2.0
1128 .. vim: set textwidth=72 :