Statistics
| Branch: | Tag: | Revision:

root / doc / rapi.rst @ 18e2b6e4

History | View | Annotate | Download (27.4 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

    
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. Changes to the file will be
25
read automatically.
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 :rfc:`2617` ("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 :rfc:`2617` is supported.
69

    
70
.. _JSON: http://www.json.org/
71
.. _REST: http://en.wikipedia.org/wiki/Representational_State_Transfer
72

    
73

    
74
A note on JSON as used by RAPI
75
++++++++++++++++++++++++++++++
76

    
77
JSON_ as used by Ganeti RAPI does not conform to the specification in
78
:rfc:`4627`. Section 2 defines a JSON text to be either an object
79
(``{"key": "value", …}``) or an array (``[1, 2, 3, …]``). In violation
80
of this RAPI uses plain strings (``"master-candidate"``, ``"1234"``) for
81
some requests or responses. Changing this now would likely break
82
existing clients and cause a lot of trouble.
83

    
84
.. highlight:: ruby
85

    
86
Unlike Python's `JSON encoder and decoder
87
<http://docs.python.org/library/json.html>`_, other programming
88
languages or libraries may only provide a strict implementation, not
89
allowing plain values. For those, responses can usually be wrapped in an
90
array whose first element is then used, e.g. the response ``"1234"``
91
becomes ``["1234"]``. This works equally well for more complex values.
92
Example in Ruby::
93

    
94
  require "json"
95

    
96
  # Insert code to get response here
97
  response = "\"1234\""
98

    
99
  decoded = JSON.parse("[#{response}]").first
100

    
101
Short of modifying the encoder to allow encoding to a less strict
102
format, requests will have to be formatted by hand. Newer RAPI requests
103
already use a dictionary as their input data and shouldn't cause any
104
problems.
105

    
106

    
107
PUT or POST?
108
------------
109

    
110
According to :rfc:`2616` the main difference between PUT and POST is
111
that POST can create new resources but PUT can only create the resource
112
the URI was pointing to on the PUT request.
113

    
114
Unfortunately, due to historic reasons, the Ganeti RAPI library is not
115
consistent with this usage, so just use the methods as documented below
116
for each resource.
117

    
118
For more details have a look in the source code at
119
``lib/rapi/rlib2.py``.
120

    
121

    
122
Generic parameter types
123
-----------------------
124

    
125
A few generic refered parameter types and the values they allow.
126

    
127
``bool``
128
++++++++
129

    
130
A boolean option will accept ``1`` or ``0`` as numbers but not
131
i.e. ``True`` or ``False``.
132

    
133
Generic parameters
134
------------------
135

    
136
A few parameter mean the same thing across all resources which implement
137
it.
138

    
139
``bulk``
140
++++++++
141

    
142
Bulk-mode means that for the resources which usually return just a list
143
of child resources (e.g. ``/2/instances`` which returns just instance
144
names), the output will instead contain detailed data for all these
145
subresources. This is more efficient than query-ing the sub-resources
146
themselves.
147

    
148
``dry-run``
149
+++++++++++
150

    
151
The boolean *dry-run* argument, if provided and set, signals to Ganeti
152
that the job should not be executed, only the pre-execution checks will
153
be done.
154

    
155
This is useful in trying to determine (without guarantees though, as in
156
the meantime the cluster state could have changed) if the operation is
157
likely to succeed or at least start executing.
158

    
159
``force``
160
+++++++++++
161

    
162
Force operation to continue even if it will cause the cluster to become
163
inconsistent (e.g. because there are not enough master candidates).
164

    
165
Usage examples
166
--------------
167

    
168
You can access the API using your favorite programming language as long
169
as it supports network connections.
170

    
171
Ganeti RAPI client
172
++++++++++++++++++
173

    
174
Ganeti includes a standalone RAPI client, ``lib/rapi/client.py``.
175

    
176
Shell
177
+++++
178

    
179
.. highlight:: sh
180

    
181
Using wget::
182

    
183
   wget -q -O - https://CLUSTERNAME:5080/2/info
184

    
185
or curl::
186

    
187
  curl https://CLUSTERNAME:5080/2/info
188

    
189

    
190
Python
191
++++++
192

    
193
.. highlight:: python
194

    
195
::
196

    
197
  import urllib2
198
  f = urllib2.urlopen('https://CLUSTERNAME:5080/2/info')
199
  print f.read()
200

    
201

    
202
JavaScript
203
++++++++++
204

    
205
.. warning:: While it's possible to use JavaScript, it poses several
206
   potential problems, including browser blocking request due to
207
   non-standard ports or different domain names. Fetching the data on
208
   the webserver is easier.
209

    
210
.. highlight:: javascript
211

    
212
::
213

    
214
  var url = 'https://CLUSTERNAME:5080/2/info';
215
  var info;
216
  var xmlreq = new XMLHttpRequest();
217
  xmlreq.onreadystatechange = function () {
218
    if (xmlreq.readyState != 4) return;
219
    if (xmlreq.status == 200) {
220
      info = eval("(" + xmlreq.responseText + ")");
221
      alert(info);
222
    } else {
223
      alert('Error fetching cluster info');
224
    }
225
    xmlreq = null;
226
  };
227
  xmlreq.open('GET', url, true);
228
  xmlreq.send(null);
229

    
230
Resources
231
---------
232

    
233
.. highlight:: javascript
234

    
235
``/``
236
+++++
237

    
238
The root resource.
239

    
240
It supports the following commands: ``GET``.
241

    
242
``GET``
243
~~~~~~~
244

    
245
Shows the list of mapped resources.
246

    
247
Returns: a dictionary with 'name' and 'uri' keys for each of them.
248

    
249
``/2``
250
++++++
251

    
252
The ``/2`` resource, the root of the version 2 API.
253

    
254
It supports the following commands: ``GET``.
255

    
256
``GET``
257
~~~~~~~
258

    
259
Show the list of mapped resources.
260

    
261
Returns: a dictionary with ``name`` and ``uri`` keys for each of them.
262

    
263
``/2/info``
264
+++++++++++
265

    
266
Cluster information resource.
267

    
268
It supports the following commands: ``GET``.
269

    
270
``GET``
271
~~~~~~~
272

    
273
Returns cluster information.
274

    
275
Example::
276

    
277
  {
278
    "config_version": 2000000,
279
    "name": "cluster",
280
    "software_version": "2.0.0~beta2",
281
    "os_api_version": 10,
282
    "export_version": 0,
283
    "candidate_pool_size": 10,
284
    "enabled_hypervisors": [
285
      "fake"
286
    ],
287
    "hvparams": {
288
      "fake": {}
289
     },
290
    "default_hypervisor": "fake",
291
    "master": "node1.example.com",
292
    "architecture": [
293
      "64bit",
294
      "x86_64"
295
    ],
296
    "protocol_version": 20,
297
    "beparams": {
298
      "default": {
299
        "auto_balance": true,
300
        "vcpus": 1,
301
        "memory": 128
302
       }
303
      }
304
    }
305

    
306

    
307
``/2/redistribute-config``
308
++++++++++++++++++++++++++
309

    
310
Redistribute configuration to all nodes.
311

    
312
It supports the following commands: ``PUT``.
313

    
314
``PUT``
315
~~~~~~~
316

    
317
Redistribute configuration to all nodes. The result will be a job id.
318

    
319

    
320
``/2/features``
321
+++++++++++++++
322

    
323
``GET``
324
~~~~~~~
325

    
326
Returns a list of features supported by the RAPI server. Available
327
features:
328

    
329
``instance-create-reqv1``
330
  Instance creation request data version 1 supported.
331

    
332

    
333
``/2/instances``
334
++++++++++++++++
335

    
336
The instances resource.
337

    
338
It supports the following commands: ``GET``, ``POST``.
339

    
340
``GET``
341
~~~~~~~
342

    
343
Returns a list of all available instances.
344

    
345
Example::
346

    
347
    [
348
      {
349
        "name": "web.example.com",
350
        "uri": "\/instances\/web.example.com"
351
      },
352
      {
353
        "name": "mail.example.com",
354
        "uri": "\/instances\/mail.example.com"
355
      }
356
    ]
357

    
358
If the optional bool *bulk* argument is provided and set to a true value
359
(i.e ``?bulk=1``), the output contains detailed information about
360
instances as a list.
361

    
362
Example::
363

    
364
    [
365
      {
366
         "status": "running",
367
         "disk_usage": 20480,
368
         "nic.bridges": [
369
           "xen-br0"
370
          ],
371
         "name": "web.example.com",
372
         "tags": ["tag1", "tag2"],
373
         "beparams": {
374
           "vcpus": 2,
375
           "memory": 512
376
         },
377
         "disk.sizes": [
378
             20480
379
         ],
380
         "pnode": "node1.example.com",
381
         "nic.macs": ["01:23:45:67:89:01"],
382
         "snodes": ["node2.example.com"],
383
         "disk_template": "drbd",
384
         "admin_state": true,
385
         "os": "debian-etch",
386
         "oper_state": true
387
      },
388
      ...
389
    ]
390

    
391

    
392
``POST``
393
~~~~~~~~
394

    
395
Creates an instance.
396

    
397
If the optional bool *dry-run* argument is provided, the job will not be
398
actually executed, only the pre-execution checks will be done. Query-ing
399
the job result will return, in both dry-run and normal case, the list of
400
nodes selected for the instance.
401

    
402
Returns: a job ID that can be used later for polling.
403

    
404
Body parameters:
405

    
406
``__version__`` (int, required)
407
  Must be ``1`` (older Ganeti versions used a different format for
408
  instance creation requests, version ``0``, but that format is not
409
  documented).
410
``mode`` (string, required)
411
  Instance creation mode.
412
``name`` (string, required)
413
  Instance name.
414
``disk_template`` (string, required)
415
  Disk template for instance.
416
``disks`` (list, required)
417
  List of disk definitions. Example: ``[{"size": 100}, {"size": 5}]``.
418
  Each disk definition must contain a ``size`` value and can contain an
419
  optional ``mode`` value denoting the disk access mode (``ro`` or
420
  ``rw``).
421
``nics`` (list, required)
422
  List of NIC (network interface) definitions. Example: ``[{}, {},
423
  {"ip": "198.51.100.4"}]``. Each NIC definition can contain the
424
  optional values ``ip``, ``mode``, ``link`` and ``bridge``.
425
``os`` (string, required)
426
  Instance operating system.
427
``osparams`` (dictionary)
428
  Dictionary with OS parameters. If not valid for the given OS, the job
429
  will fail.
430
``force_variant`` (bool)
431
  Whether to force an unknown variant.
432
``pnode`` (string)
433
  Primary node.
434
``snode`` (string)
435
  Secondary node.
436
``src_node`` (string)
437
  Source node for import.
438
``src_path`` (string)
439
  Source directory for import.
440
``start`` (bool)
441
  Whether to start instance after creation.
442
``ip_check`` (bool)
443
  Whether to ensure instance's IP address is inactive.
444
``name_check`` (bool)
445
  Whether to ensure instance's name is resolvable.
446
``file_storage_dir`` (string)
447
  File storage directory.
448
``file_driver`` (string)
449
  File storage driver.
450
``iallocator`` (string)
451
  Instance allocator name.
452
``source_handshake`` (list)
453
  Signed handshake from source (remote import only).
454
``source_x509_ca`` (string)
455
  Source X509 CA in PEM format (remote import only).
456
``source_instance_name`` (string)
457
  Source instance name (remote import only).
458
``hypervisor`` (string)
459
  Hypervisor name.
460
``hvparams`` (dict)
461
  Hypervisor parameters, hypervisor-dependent.
462
``beparams`` (dict)
463
  Backend parameters.
464

    
465

    
466
``/2/instances/[instance_name]``
467
++++++++++++++++++++++++++++++++
468

    
469
Instance-specific resource.
470

    
471
It supports the following commands: ``GET``, ``DELETE``.
472

    
473
``GET``
474
~~~~~~~
475

    
476
Returns information about an instance, similar to the bulk output from
477
the instance list.
478

    
479
``DELETE``
480
~~~~~~~~~~
481

    
482
Deletes an instance.
483

    
484
It supports the ``dry-run`` argument.
485

    
486

    
487
``/2/instances/[instance_name]/info``
488
+++++++++++++++++++++++++++++++++++++++
489

    
490
It supports the following commands: ``GET``.
491

    
492
``GET``
493
~~~~~~~
494

    
495
Requests detailed information about the instance. An optional parameter,
496
``static`` (bool), can be set to return only static information from the
497
configuration without querying the instance's nodes. The result will be
498
a job id.
499

    
500

    
501
``/2/instances/[instance_name]/reboot``
502
+++++++++++++++++++++++++++++++++++++++
503

    
504
Reboots URI for an instance.
505

    
506
It supports the following commands: ``POST``.
507

    
508
``POST``
509
~~~~~~~~
510

    
511
Reboots the instance.
512

    
513
The URI takes optional ``type=soft|hard|full`` and
514
``ignore_secondaries=0|1`` parameters.
515

    
516
``type`` defines the reboot type. ``soft`` is just a normal reboot,
517
without terminating the hypervisor. ``hard`` means full shutdown
518
(including terminating the hypervisor process) and startup again.
519
``full`` is like ``hard`` but also recreates the configuration from
520
ground up as if you would have done a ``gnt-instance shutdown`` and
521
``gnt-instance start`` on it.
522

    
523
``ignore_secondaries`` is a bool argument indicating if we start the
524
instance even if secondary disks are failing.
525

    
526
It supports the ``dry-run`` argument.
527

    
528

    
529
``/2/instances/[instance_name]/shutdown``
530
+++++++++++++++++++++++++++++++++++++++++
531

    
532
Instance shutdown URI.
533

    
534
It supports the following commands: ``PUT``.
535

    
536
``PUT``
537
~~~~~~~
538

    
539
Shutdowns an instance.
540

    
541
It supports the ``dry-run`` argument.
542

    
543

    
544
``/2/instances/[instance_name]/startup``
545
++++++++++++++++++++++++++++++++++++++++
546

    
547
Instance startup URI.
548

    
549
It supports the following commands: ``PUT``.
550

    
551
``PUT``
552
~~~~~~~
553

    
554
Startup an instance.
555

    
556
The URI takes an optional ``force=1|0`` parameter to start the
557
instance even if secondary disks are failing.
558

    
559
It supports the ``dry-run`` argument.
560

    
561
``/2/instances/[instance_name]/reinstall``
562
++++++++++++++++++++++++++++++++++++++++++++++
563

    
564
Installs the operating system again.
565

    
566
It supports the following commands: ``POST``.
567

    
568
``POST``
569
~~~~~~~~
570

    
571
Takes the parameters ``os`` (OS template name) and ``nostartup`` (bool).
572

    
573

    
574
``/2/instances/[instance_name]/replace-disks``
575
++++++++++++++++++++++++++++++++++++++++++++++
576

    
577
Replaces disks on an instance.
578

    
579
It supports the following commands: ``POST``.
580

    
581
``POST``
582
~~~~~~~~
583

    
584
Takes the parameters ``mode`` (one of ``replace_on_primary``,
585
``replace_on_secondary``, ``replace_new_secondary`` or
586
``replace_auto``), ``disks`` (comma separated list of disk indexes),
587
``remote_node`` and ``iallocator``.
588

    
589
Either ``remote_node`` or ``iallocator`` needs to be defined when using
590
``mode=replace_new_secondary``.
591

    
592
``mode`` is a mandatory parameter. ``replace_auto`` tries to determine
593
the broken disk(s) on its own and replacing it.
594

    
595

    
596
``/2/instances/[instance_name]/activate-disks``
597
+++++++++++++++++++++++++++++++++++++++++++++++
598

    
599
Activate disks on an instance.
600

    
601
It supports the following commands: ``PUT``.
602

    
603
``PUT``
604
~~~~~~~
605

    
606
Takes the bool parameter ``ignore_size``. When set ignore the recorded
607
size (useful for forcing activation when recorded size is wrong).
608

    
609

    
610
``/2/instances/[instance_name]/deactivate-disks``
611
+++++++++++++++++++++++++++++++++++++++++++++++++
612

    
613
Deactivate disks on an instance.
614

    
615
It supports the following commands: ``PUT``.
616

    
617
``PUT``
618
~~~~~~~
619

    
620
Takes no parameters.
621

    
622

    
623
``/2/instances/[instance_name]/prepare-export``
624
+++++++++++++++++++++++++++++++++++++++++++++++++
625

    
626
Prepares an export of an instance.
627

    
628
It supports the following commands: ``PUT``.
629

    
630
``PUT``
631
~~~~~~~
632

    
633
Takes one parameter, ``mode``, for the export mode. Returns a job ID.
634

    
635

    
636
``/2/instances/[instance_name]/export``
637
+++++++++++++++++++++++++++++++++++++++++++++++++
638

    
639
Exports an instance.
640

    
641
It supports the following commands: ``PUT``.
642

    
643
``PUT``
644
~~~~~~~
645

    
646
Returns a job ID.
647

    
648
Body parameters:
649

    
650
``mode`` (string)
651
  Export mode.
652
``destination`` (required)
653
  Destination information, depends on export mode.
654
``shutdown`` (bool, required)
655
  Whether to shutdown instance before export.
656
``remove_instance`` (bool)
657
  Whether to remove instance after export.
658
``x509_key_name``
659
  Name of X509 key (remote export only).
660
``destination_x509_ca``
661
  Destination X509 CA (remote export only).
662

    
663

    
664
``/2/instances/[instance_name]/migrate``
665
++++++++++++++++++++++++++++++++++++++++
666

    
667
Migrates an instance.
668

    
669
Supports the following commands: ``PUT``.
670

    
671
``PUT``
672
~~~~~~~
673

    
674
Returns a job ID.
675

    
676
Body parameters:
677

    
678
``mode`` (string)
679
  Migration mode.
680
``cleanup`` (bool)
681
  Whether a previously failed migration should be cleaned up.
682

    
683

    
684
``/2/instances/[instance_name]/rename``
685
++++++++++++++++++++++++++++++++++++++++
686

    
687
Renames an instance.
688

    
689
Supports the following commands: ``PUT``.
690

    
691
``PUT``
692
~~~~~~~
693

    
694
Returns a job ID.
695

    
696
Body parameters:
697

    
698
``new_name`` (string, required)
699
  New instance name.
700
``ip_check`` (bool)
701
  Whether to ensure instance's IP address is inactive.
702
``name_check`` (bool)
703
  Whether to ensure instance's name is resolvable.
704

    
705

    
706
``/2/instances/[instance_name]/modify``
707
++++++++++++++++++++++++++++++++++++++++
708

    
709
Modifies an instance.
710

    
711
Supports the following commands: ``PUT``.
712

    
713
``PUT``
714
~~~~~~~
715

    
716
Returns a job ID.
717

    
718
Body parameters:
719

    
720
``osparams`` (dict)
721
  Dictionary with OS parameters.
722
``hvparams`` (dict)
723
  Hypervisor parameters, hypervisor-dependent.
724
``beparams`` (dict)
725
  Backend parameters.
726
``force`` (bool)
727
  Whether to force the operation.
728
``nics`` (list)
729
  List of NIC changes. Each item is of the form ``(op, settings)``.
730
  ``op`` can be ``add`` to add a new NIC with the specified settings,
731
  ``remove`` to remove the last NIC or a number to modify the settings
732
  of the NIC with that index.
733
``disks`` (list)
734
  List of disk changes. See ``nics``.
735
``disk_template`` (string)
736
  Disk template for instance.
737
``remote_node`` (string)
738
  Secondary node (used when changing disk template).
739
``os_name`` (string)
740
  Change instance's OS name. Does not reinstall the instance.
741
``force_variant`` (bool)
742
  Whether to force an unknown variant.
743

    
744

    
745
``/2/instances/[instance_name]/tags``
746
+++++++++++++++++++++++++++++++++++++
747

    
748
Manages per-instance tags.
749

    
750
It supports the following commands: ``GET``, ``PUT``, ``DELETE``.
751

    
752
``GET``
753
~~~~~~~
754

    
755
Returns a list of tags.
756

    
757
Example::
758

    
759
    ["tag1", "tag2", "tag3"]
760

    
761
``PUT``
762
~~~~~~~
763

    
764
Add a set of tags.
765

    
766
The request as a list of strings should be ``PUT`` to this URI. The
767
result will be a job id.
768

    
769
It supports the ``dry-run`` argument.
770

    
771

    
772
``DELETE``
773
~~~~~~~~~~
774

    
775
Delete a tag.
776

    
777
In order to delete a set of tags, the DELETE request should be addressed
778
to URI like::
779

    
780
    /tags?tag=[tag]&tag=[tag]
781

    
782
It supports the ``dry-run`` argument.
783

    
784

    
785
``/2/jobs``
786
+++++++++++
787

    
788
The ``/2/jobs`` resource.
789

    
790
It supports the following commands: ``GET``.
791

    
792
``GET``
793
~~~~~~~
794

    
795
Returns a dictionary of jobs.
796

    
797
Returns: a dictionary with jobs id and uri.
798

    
799
``/2/jobs/[job_id]``
800
++++++++++++++++++++
801

    
802

    
803
Individual job URI.
804

    
805
It supports the following commands: ``GET``, ``DELETE``.
806

    
807
``GET``
808
~~~~~~~
809

    
810
Returns a job status.
811

    
812
Returns: a dictionary with job parameters.
813

    
814
The result includes:
815

    
816
- id: job ID as a number
817
- status: current job status as a string
818
- ops: involved OpCodes as a list of dictionaries for each opcodes in
819
  the job
820
- opstatus: OpCodes status as a list
821
- opresult: OpCodes results as a list
822

    
823
For a successful opcode, the ``opresult`` field corresponding to it will
824
contain the raw result from its :term:`LogicalUnit`. In case an opcode
825
has failed, its element in the opresult list will be a list of two
826
elements:
827

    
828
- first element the error type (the Ganeti internal error name)
829
- second element a list of either one or two elements:
830

    
831
  - the first element is the textual error description
832
  - the second element, if any, will hold an error classification
833

    
834
The error classification is most useful for the ``OpPrereqError``
835
error type - these errors happen before the OpCode has started
836
executing, so it's possible to retry the OpCode without side
837
effects. But whether it make sense to retry depends on the error
838
classification:
839

    
840
``resolver_error``
841
  Resolver errors. This usually means that a name doesn't exist in DNS,
842
  so if it's a case of slow DNS propagation the operation can be retried
843
  later.
844

    
845
``insufficient_resources``
846
  Not enough resources (iallocator failure, disk space, memory,
847
  etc.). If the resources on the cluster increase, the operation might
848
  succeed.
849

    
850
``wrong_input``
851
  Wrong arguments (at syntax level). The operation will not ever be
852
  accepted unless the arguments change.
853

    
854
``wrong_state``
855
  Wrong entity state. For example, live migration has been requested for
856
  a down instance, or instance creation on an offline node. The
857
  operation can be retried once the resource has changed state.
858

    
859
``unknown_entity``
860
  Entity not found. For example, information has been requested for an
861
  unknown instance.
862

    
863
``already_exists``
864
  Entity already exists. For example, instance creation has been
865
  requested for an already-existing instance.
866

    
867
``resource_not_unique``
868
  Resource not unique (e.g. MAC or IP duplication).
869

    
870
``internal_error``
871
  Internal cluster error. For example, a node is unreachable but not set
872
  offline, or the ganeti node daemons are not working, etc. A
873
  ``gnt-cluster verify`` should be run.
874

    
875
``environment_error``
876
  Environment error (e.g. node disk error). A ``gnt-cluster verify``
877
  should be run.
878

    
879
Note that in the above list, by entity we refer to a node or instance,
880
while by a resource we refer to an instance's disk, or NIC, etc.
881

    
882

    
883
``DELETE``
884
~~~~~~~~~~
885

    
886
Cancel a not-yet-started job.
887

    
888

    
889
``/2/jobs/[job_id]/wait``
890
+++++++++++++++++++++++++
891

    
892
``GET``
893
~~~~~~~
894

    
895
Waits for changes on a job. Takes the following body parameters in a
896
dict:
897

    
898
``fields``
899
  The job fields on which to watch for changes.
900

    
901
``previous_job_info``
902
  Previously received field values or None if not yet available.
903

    
904
``previous_log_serial``
905
  Highest log serial number received so far or None if not yet
906
  available.
907

    
908
Returns None if no changes have been detected and a dict with two keys,
909
``job_info`` and ``log_entries`` otherwise.
910

    
911

    
912
``/2/nodes``
913
++++++++++++
914

    
915
Nodes resource.
916

    
917
It supports the following commands: ``GET``.
918

    
919
``GET``
920
~~~~~~~
921

    
922
Returns a list of all nodes.
923

    
924
Example::
925

    
926
    [
927
      {
928
        "id": "node1.example.com",
929
        "uri": "\/nodes\/node1.example.com"
930
      },
931
      {
932
        "id": "node2.example.com",
933
        "uri": "\/nodes\/node2.example.com"
934
      }
935
    ]
936

    
937
If the optional 'bulk' argument is provided and set to 'true' value (i.e
938
'?bulk=1'), the output contains detailed information about nodes as a
939
list.
940

    
941
Example::
942

    
943
    [
944
      {
945
        "pinst_cnt": 1,
946
        "mfree": 31280,
947
        "mtotal": 32763,
948
        "name": "www.example.com",
949
        "tags": [],
950
        "mnode": 512,
951
        "dtotal": 5246208,
952
        "sinst_cnt": 2,
953
        "dfree": 5171712,
954
        "offline": false
955
      },
956
      ...
957
    ]
958

    
959
``/2/nodes/[node_name]``
960
+++++++++++++++++++++++++++++++++
961

    
962
Returns information about a node.
963

    
964
It supports the following commands: ``GET``.
965

    
966
``/2/nodes/[node_name]/evacuate``
967
+++++++++++++++++++++++++++++++++
968

    
969
Evacuates all secondary instances off a node.
970

    
971
It supports the following commands: ``POST``.
972

    
973
``POST``
974
~~~~~~~~
975

    
976
To evacuate a node, either one of the ``iallocator`` or ``remote_node``
977
parameters must be passed::
978

    
979
    evacuate?iallocator=[iallocator]
980
    evacuate?remote_node=[nodeX.example.com]
981

    
982
The result value will be a list, each element being a triple of the job
983
id (for this specific evacuation), the instance which is being evacuated
984
by this job, and the node to which it is being relocated. In case the
985
node is already empty, the result will be an empty list (without any
986
jobs being submitted).
987

    
988
And additional parameter ``early_release`` signifies whether to try to
989
parallelize the evacuations, at the risk of increasing I/O contention
990
and increasing the chances of data loss, if the primary node of any of
991
the instances being evacuated is not fully healthy.
992

    
993
If the dry-run parameter was specified, then the evacuation jobs were
994
not actually submitted, and the job IDs will be null.
995

    
996

    
997
``/2/nodes/[node_name]/migrate``
998
+++++++++++++++++++++++++++++++++
999

    
1000
Migrates all primary instances from a node.
1001

    
1002
It supports the following commands: ``POST``.
1003

    
1004
``POST``
1005
~~~~~~~~
1006

    
1007
If no mode is explicitly specified, each instances' hypervisor default
1008
migration mode will be used. Query parameters:
1009

    
1010
``live`` (bool)
1011
  If set, use live migration if available.
1012
``mode`` (string)
1013
  Sets migration mode, ``live`` for live migration and ``non-live`` for
1014
  non-live migration. Supported by Ganeti 2.2 and above.
1015

    
1016

    
1017
``/2/nodes/[node_name]/role``
1018
+++++++++++++++++++++++++++++
1019

    
1020
Manages node role.
1021

    
1022
It supports the following commands: ``GET``, ``PUT``.
1023

    
1024
The role is always one of the following:
1025

    
1026
  - drained
1027
  - master
1028
  - master-candidate
1029
  - offline
1030
  - regular
1031

    
1032
``GET``
1033
~~~~~~~
1034

    
1035
Returns the current node role.
1036

    
1037
Example::
1038

    
1039
    "master-candidate"
1040

    
1041
``PUT``
1042
~~~~~~~
1043

    
1044
Change the node role.
1045

    
1046
The request is a string which should be PUT to this URI. The result will
1047
be a job id.
1048

    
1049
It supports the bool ``force`` argument.
1050

    
1051
``/2/nodes/[node_name]/storage``
1052
++++++++++++++++++++++++++++++++
1053

    
1054
Manages storage units on the node.
1055

    
1056
``GET``
1057
~~~~~~~
1058

    
1059
Requests a list of storage units on a node. Requires the parameters
1060
``storage_type`` (one of ``file``, ``lvm-pv`` or ``lvm-vg``) and
1061
``output_fields``. The result will be a job id, using which the result
1062
can be retrieved.
1063

    
1064
``/2/nodes/[node_name]/storage/modify``
1065
+++++++++++++++++++++++++++++++++++++++
1066

    
1067
Modifies storage units on the node.
1068

    
1069
``PUT``
1070
~~~~~~~
1071

    
1072
Modifies parameters of storage units on the node. Requires the
1073
parameters ``storage_type`` (one of ``file``, ``lvm-pv`` or ``lvm-vg``)
1074
and ``name`` (name of the storage unit).  Parameters can be passed
1075
additionally. Currently only ``allocatable`` (bool) is supported. The
1076
result will be a job id.
1077

    
1078
``/2/nodes/[node_name]/storage/repair``
1079
+++++++++++++++++++++++++++++++++++++++
1080

    
1081
Repairs a storage unit on the node.
1082

    
1083
``PUT``
1084
~~~~~~~
1085

    
1086
Repairs a storage unit on the node. Requires the parameters
1087
``storage_type`` (currently only ``lvm-vg`` can be repaired) and
1088
``name`` (name of the storage unit). The result will be a job id.
1089

    
1090
``/2/nodes/[node_name]/tags``
1091
+++++++++++++++++++++++++++++
1092

    
1093
Manages per-node tags.
1094

    
1095
It supports the following commands: ``GET``, ``PUT``, ``DELETE``.
1096

    
1097
``GET``
1098
~~~~~~~
1099

    
1100
Returns a list of tags.
1101

    
1102
Example::
1103

    
1104
    ["tag1", "tag2", "tag3"]
1105

    
1106
``PUT``
1107
~~~~~~~
1108

    
1109
Add a set of tags.
1110

    
1111
The request as a list of strings should be PUT to this URI. The result
1112
will be a job id.
1113

    
1114
It supports the ``dry-run`` argument.
1115

    
1116
``DELETE``
1117
~~~~~~~~~~
1118

    
1119
Deletes tags.
1120

    
1121
In order to delete a set of tags, the DELETE request should be addressed
1122
to URI like::
1123

    
1124
    /tags?tag=[tag]&tag=[tag]
1125

    
1126
It supports the ``dry-run`` argument.
1127

    
1128

    
1129
``/2/os``
1130
+++++++++
1131

    
1132
OS resource.
1133

    
1134
It supports the following commands: ``GET``.
1135

    
1136
``GET``
1137
~~~~~~~
1138

    
1139
Return a list of all OSes.
1140

    
1141
Can return error 500 in case of a problem. Since this is a costly
1142
operation for Ganeti 2.0, it is not recommended to execute it too often.
1143

    
1144
Example::
1145

    
1146
    ["debian-etch"]
1147

    
1148
``/2/tags``
1149
+++++++++++
1150

    
1151
Manages cluster tags.
1152

    
1153
It supports the following commands: ``GET``, ``PUT``, ``DELETE``.
1154

    
1155
``GET``
1156
~~~~~~~
1157

    
1158
Returns the cluster tags.
1159

    
1160
Example::
1161

    
1162
    ["tag1", "tag2", "tag3"]
1163

    
1164
``PUT``
1165
~~~~~~~
1166

    
1167
Adds a set of tags.
1168

    
1169
The request as a list of strings should be PUT to this URI. The result
1170
will be a job id.
1171

    
1172
It supports the ``dry-run`` argument.
1173

    
1174

    
1175
``DELETE``
1176
~~~~~~~~~~
1177

    
1178
Deletes tags.
1179

    
1180
In order to delete a set of tags, the DELETE request should be addressed
1181
to URI like::
1182

    
1183
    /tags?tag=[tag]&tag=[tag]
1184

    
1185
It supports the ``dry-run`` argument.
1186

    
1187

    
1188
``/version``
1189
++++++++++++
1190

    
1191
The version resource.
1192

    
1193
This resource should be used to determine the remote API version and to
1194
adapt clients accordingly.
1195

    
1196
It supports the following commands: ``GET``.
1197

    
1198
``GET``
1199
~~~~~~~
1200

    
1201
Returns the remote API version. Ganeti 1.2 returned ``1`` and Ganeti 2.0
1202
returns ``2``.
1203

    
1204
.. vim: set textwidth=72 :
1205
.. Local Variables:
1206
.. mode: rst
1207
.. fill-column: 72
1208
.. End: