Statistics
| Branch: | Tag: | Revision:

root / doc / rapi.rst @ 3882937a

History | View | Annotate | Download (26 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. 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
PUT or POST?
76
------------
77

    
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.
81

    
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
84
for each resource.
85

    
86
For more details have a look in the source code at
87
``lib/rapi/rlib2.py``.
88

    
89

    
90
Generic parameter types
91
-----------------------
92

    
93
A few generic refered parameter types and the values they allow.
94

    
95
``bool``
96
++++++++
97

    
98
A boolean option will accept ``1`` or ``0`` as numbers but not
99
i.e. ``True`` or ``False``.
100

    
101
Generic parameters
102
------------------
103

    
104
A few parameter mean the same thing across all resources which implement
105
it.
106

    
107
``bulk``
108
++++++++
109

    
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
114
themselves.
115

    
116
``dry-run``
117
+++++++++++
118

    
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
121
be done.
122

    
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.
126

    
127
``force``
128
+++++++++++
129

    
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).
132

    
133
Usage examples
134
--------------
135

    
136
You can access the API using your favorite programming language as long
137
as it supports network connections.
138

    
139
Ganeti RAPI client
140
++++++++++++++++++
141

    
142
Ganeti includes a standalone RAPI client, ``lib/rapi/client.py``.
143

    
144
Shell
145
+++++
146

    
147
.. highlight:: sh
148

    
149
Using wget::
150

    
151
   wget -q -O - https://CLUSTERNAME:5080/2/info
152

    
153
or curl::
154

    
155
  curl https://CLUSTERNAME:5080/2/info
156

    
157

    
158
Python
159
++++++
160

    
161
.. highlight:: python
162

    
163
::
164

    
165
  import urllib2
166
  f = urllib2.urlopen('https://CLUSTERNAME:5080/2/info')
167
  print f.read()
168

    
169

    
170
JavaScript
171
++++++++++
172

    
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.
177

    
178
.. highlight:: javascript
179

    
180
::
181

    
182
  var url = 'https://CLUSTERNAME:5080/2/info';
183
  var 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 + ")");
189
      alert(info);
190
    } else {
191
      alert('Error fetching cluster info');
192
    }
193
    xmlreq = null;
194
  };
195
  xmlreq.open('GET', url, true);
196
  xmlreq.send(null);
197

    
198
Resources
199
---------
200

    
201
.. highlight:: javascript
202

    
203
``/``
204
+++++
205

    
206
The root resource.
207

    
208
It supports the following commands: ``GET``.
209

    
210
``GET``
211
~~~~~~~
212

    
213
Shows the list of mapped resources.
214

    
215
Returns: a dictionary with 'name' and 'uri' keys for each of them.
216

    
217
``/2``
218
++++++
219

    
220
The ``/2`` resource, the root of the version 2 API.
221

    
222
It supports the following commands: ``GET``.
223

    
224
``GET``
225
~~~~~~~
226

    
227
Show the list of mapped resources.
228

    
229
Returns: a dictionary with ``name`` and ``uri`` keys for each of them.
230

    
231
``/2/info``
232
+++++++++++
233

    
234
Cluster information resource.
235

    
236
It supports the following commands: ``GET``.
237

    
238
``GET``
239
~~~~~~~
240

    
241
Returns cluster information.
242

    
243
Example::
244

    
245
  {
246
    "config_version": 2000000,
247
    "name": "cluster",
248
    "software_version": "2.0.0~beta2",
249
    "os_api_version": 10,
250
    "export_version": 0,
251
    "candidate_pool_size": 10,
252
    "enabled_hypervisors": [
253
      "fake"
254
    ],
255
    "hvparams": {
256
      "fake": {}
257
     },
258
    "default_hypervisor": "fake",
259
    "master": "node1.example.com",
260
    "architecture": [
261
      "64bit",
262
      "x86_64"
263
    ],
264
    "protocol_version": 20,
265
    "beparams": {
266
      "default": {
267
        "auto_balance": true,
268
        "vcpus": 1,
269
        "memory": 128
270
       }
271
      }
272
    }
273

    
274

    
275
``/2/redistribute-config``
276
++++++++++++++++++++++++++
277

    
278
Redistribute configuration to all nodes.
279

    
280
It supports the following commands: ``PUT``.
281

    
282
``PUT``
283
~~~~~~~
284

    
285
Redistribute configuration to all nodes. The result will be a job id.
286

    
287

    
288
``/2/features``
289
+++++++++++++++
290

    
291
``GET``
292
~~~~~~~
293

    
294
Returns a list of features supported by the RAPI server. Available
295
features:
296

    
297
``instance-create-reqv1``
298
  Instance creation request data version 1 supported.
299

    
300

    
301
``/2/instances``
302
++++++++++++++++
303

    
304
The instances resource.
305

    
306
It supports the following commands: ``GET``, ``POST``.
307

    
308
``GET``
309
~~~~~~~
310

    
311
Returns a list of all available instances.
312

    
313
Example::
314

    
315
    [
316
      {
317
        "name": "web.example.com",
318
        "uri": "\/instances\/web.example.com"
319
      },
320
      {
321
        "name": "mail.example.com",
322
        "uri": "\/instances\/mail.example.com"
323
      }
324
    ]
325

    
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
328
instances as a list.
329

    
330
Example::
331

    
332
    [
333
      {
334
         "status": "running",
335
         "disk_usage": 20480,
336
         "nic.bridges": [
337
           "xen-br0"
338
          ],
339
         "name": "web.example.com",
340
         "tags": ["tag1", "tag2"],
341
         "beparams": {
342
           "vcpus": 2,
343
           "memory": 512
344
         },
345
         "disk.sizes": [
346
             20480
347
         ],
348
         "pnode": "node1.example.com",
349
         "nic.macs": ["01:23:45:67:89:01"],
350
         "snodes": ["node2.example.com"],
351
         "disk_template": "drbd",
352
         "admin_state": true,
353
         "os": "debian-etch",
354
         "oper_state": true
355
      },
356
      ...
357
    ]
358

    
359

    
360
``POST``
361
~~~~~~~~
362

    
363
Creates an instance.
364

    
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.
369

    
370
Returns: a job ID that can be used later for polling.
371

    
372
Body parameters:
373

    
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
377
  documented).
378
``mode`` (string, required)
379
  Instance creation mode.
380
``name`` (string, required)
381
  Instance name.
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
388
  ``rw``).
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
397
  will fail.
398
``force_variant`` (bool)
399
  Whether to force an unknown variant.
400
``pnode`` (string)
401
  Primary node.
402
``snode`` (string)
403
  Secondary node.
404
``src_node`` (string)
405
  Source node for import.
406
``src_path`` (string)
407
  Source directory for import.
408
``start`` (bool)
409
  Whether to start instance after creation.
410
``ip_check`` (bool)
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)
417
  File storage driver.
418
``iallocator`` (string)
419
  Instance allocator name.
420
``source_handshake`` (list)
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)
427
  Hypervisor name.
428
``hvparams`` (dict)
429
  Hypervisor parameters, hypervisor-dependent.
430
``beparams`` (dict)
431
  Backend parameters.
432

    
433

    
434
``/2/instances/[instance_name]``
435
++++++++++++++++++++++++++++++++
436

    
437
Instance-specific resource.
438

    
439
It supports the following commands: ``GET``, ``DELETE``.
440

    
441
``GET``
442
~~~~~~~
443

    
444
Returns information about an instance, similar to the bulk output from
445
the instance list.
446

    
447
``DELETE``
448
~~~~~~~~~~
449

    
450
Deletes an instance.
451

    
452
It supports the ``dry-run`` argument.
453

    
454

    
455
``/2/instances/[instance_name]/info``
456
+++++++++++++++++++++++++++++++++++++++
457

    
458
It supports the following commands: ``GET``.
459

    
460
``GET``
461
~~~~~~~
462

    
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
466
a job id.
467

    
468

    
469
``/2/instances/[instance_name]/reboot``
470
+++++++++++++++++++++++++++++++++++++++
471

    
472
Reboots URI for an instance.
473

    
474
It supports the following commands: ``POST``.
475

    
476
``POST``
477
~~~~~~~~
478

    
479
Reboots the instance.
480

    
481
The URI takes optional ``type=soft|hard|full`` and
482
``ignore_secondaries=0|1`` parameters.
483

    
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.
490

    
491
``ignore_secondaries`` is a bool argument indicating if we start the
492
instance even if secondary disks are failing.
493

    
494
It supports the ``dry-run`` argument.
495

    
496

    
497
``/2/instances/[instance_name]/shutdown``
498
+++++++++++++++++++++++++++++++++++++++++
499

    
500
Instance shutdown URI.
501

    
502
It supports the following commands: ``PUT``.
503

    
504
``PUT``
505
~~~~~~~
506

    
507
Shutdowns an instance.
508

    
509
It supports the ``dry-run`` argument.
510

    
511

    
512
``/2/instances/[instance_name]/startup``
513
++++++++++++++++++++++++++++++++++++++++
514

    
515
Instance startup URI.
516

    
517
It supports the following commands: ``PUT``.
518

    
519
``PUT``
520
~~~~~~~
521

    
522
Startup an instance.
523

    
524
The URI takes an optional ``force=1|0`` parameter to start the
525
instance even if secondary disks are failing.
526

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

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

    
532
Installs the operating system again.
533

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

    
536
``POST``
537
~~~~~~~~
538

    
539
Takes the parameters ``os`` (OS template name) and ``nostartup`` (bool).
540

    
541

    
542
``/2/instances/[instance_name]/replace-disks``
543
++++++++++++++++++++++++++++++++++++++++++++++
544

    
545
Replaces disks on an instance.
546

    
547
It supports the following commands: ``POST``.
548

    
549
``POST``
550
~~~~~~~~
551

    
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``.
556

    
557
Either ``remote_node`` or ``iallocator`` needs to be defined when using
558
``mode=replace_new_secondary``.
559

    
560
``mode`` is a mandatory parameter. ``replace_auto`` tries to determine
561
the broken disk(s) on its own and replacing it.
562

    
563

    
564
``/2/instances/[instance_name]/activate-disks``
565
+++++++++++++++++++++++++++++++++++++++++++++++
566

    
567
Activate disks on an instance.
568

    
569
It supports the following commands: ``PUT``.
570

    
571
``PUT``
572
~~~~~~~
573

    
574
Takes the bool parameter ``ignore_size``. When set ignore the recorded
575
size (useful for forcing activation when recorded size is wrong).
576

    
577

    
578
``/2/instances/[instance_name]/deactivate-disks``
579
+++++++++++++++++++++++++++++++++++++++++++++++++
580

    
581
Deactivate disks on an instance.
582

    
583
It supports the following commands: ``PUT``.
584

    
585
``PUT``
586
~~~~~~~
587

    
588
Takes no parameters.
589

    
590

    
591
``/2/instances/[instance_name]/prepare-export``
592
+++++++++++++++++++++++++++++++++++++++++++++++++
593

    
594
Prepares an export of an instance.
595

    
596
It supports the following commands: ``PUT``.
597

    
598
``PUT``
599
~~~~~~~
600

    
601
Takes one parameter, ``mode``, for the export mode. Returns a job ID.
602

    
603

    
604
``/2/instances/[instance_name]/export``
605
+++++++++++++++++++++++++++++++++++++++++++++++++
606

    
607
Exports an instance.
608

    
609
It supports the following commands: ``PUT``.
610

    
611
``PUT``
612
~~~~~~~
613

    
614
Returns a job ID.
615

    
616
Body parameters:
617

    
618
``mode`` (string)
619
  Export mode.
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.
626
``x509_key_name``
627
  Name of X509 key (remote export only).
628
``destination_x509_ca``
629
  Destination X509 CA (remote export only).
630

    
631

    
632
``/2/instances/[instance_name]/migrate``
633
++++++++++++++++++++++++++++++++++++++++
634

    
635
Migrates an instance.
636

    
637
Supports the following commands: ``PUT``.
638

    
639
``PUT``
640
~~~~~~~
641

    
642
Returns a job ID.
643

    
644
Body parameters:
645

    
646
``mode`` (string)
647
  Migration mode.
648
``cleanup`` (bool)
649
  Whether a previously failed migration should be cleaned up.
650

    
651

    
652
``/2/instances/[instance_name]/rename``
653
++++++++++++++++++++++++++++++++++++++++
654

    
655
Renames an instance.
656

    
657
Supports the following commands: ``PUT``.
658

    
659
``PUT``
660
~~~~~~~
661

    
662
Returns a job ID.
663

    
664
Body parameters:
665

    
666
``new_name`` (string, required)
667
  New instance name.
668
``ip_check`` (bool)
669
  Whether to ensure instance's IP address is inactive.
670
``name_check`` (bool)
671
  Whether to ensure instance's name is resolvable.
672

    
673

    
674
``/2/instances/[instance_name]/modify``
675
++++++++++++++++++++++++++++++++++++++++
676

    
677
Modifies an instance.
678

    
679
Supports the following commands: ``PUT``.
680

    
681
``PUT``
682
~~~~~~~
683

    
684
Returns a job ID.
685

    
686
Body parameters:
687

    
688
``osparams`` (dict)
689
  Dictionary with OS parameters.
690
``hvparams`` (dict)
691
  Hypervisor parameters, hypervisor-dependent.
692
``beparams`` (dict)
693
  Backend parameters.
694
``force`` (bool)
695
  Whether to force the operation.
696
``nics`` (list)
697
  List of NIC changes. Each item is of the form ``(op, settings)``.
698
  ``op`` can be ``add`` to add a new NIC with the specified settings,
699
  ``remove`` to remove the last NIC or a number to modify the settings
700
  of the NIC with that index.
701
``disks`` (list)
702
  List of disk changes. See ``nics``.
703
``disk_template`` (string)
704
  Disk template for instance.
705
``remote_node`` (string)
706
  Secondary node (used when changing disk template).
707
``os_name`` (string)
708
  Change instance's OS name. Does not reinstall the instance.
709
``force_variant`` (bool)
710
  Whether to force an unknown variant.
711

    
712

    
713
``/2/instances/[instance_name]/tags``
714
+++++++++++++++++++++++++++++++++++++
715

    
716
Manages per-instance tags.
717

    
718
It supports the following commands: ``GET``, ``PUT``, ``DELETE``.
719

    
720
``GET``
721
~~~~~~~
722

    
723
Returns a list of tags.
724

    
725
Example::
726

    
727
    ["tag1", "tag2", "tag3"]
728

    
729
``PUT``
730
~~~~~~~
731

    
732
Add a set of tags.
733

    
734
The request as a list of strings should be ``PUT`` to this URI. The
735
result will be a job id.
736

    
737
It supports the ``dry-run`` argument.
738

    
739

    
740
``DELETE``
741
~~~~~~~~~~
742

    
743
Delete a tag.
744

    
745
In order to delete a set of tags, the DELETE request should be addressed
746
to URI like::
747

    
748
    /tags?tag=[tag]&tag=[tag]
749

    
750
It supports the ``dry-run`` argument.
751

    
752

    
753
``/2/jobs``
754
+++++++++++
755

    
756
The ``/2/jobs`` resource.
757

    
758
It supports the following commands: ``GET``.
759

    
760
``GET``
761
~~~~~~~
762

    
763
Returns a dictionary of jobs.
764

    
765
Returns: a dictionary with jobs id and uri.
766

    
767
``/2/jobs/[job_id]``
768
++++++++++++++++++++
769

    
770

    
771
Individual job URI.
772

    
773
It supports the following commands: ``GET``, ``DELETE``.
774

    
775
``GET``
776
~~~~~~~
777

    
778
Returns a job status.
779

    
780
Returns: a dictionary with job parameters.
781

    
782
The result includes:
783

    
784
- id: job ID as a number
785
- status: current job status as a string
786
- ops: involved OpCodes as a list of dictionaries for each opcodes in
787
  the job
788
- opstatus: OpCodes status as a list
789
- opresult: OpCodes results as a list
790

    
791
For a successful opcode, the ``opresult`` field corresponding to it will
792
contain the raw result from its :term:`LogicalUnit`. In case an opcode
793
has failed, its element in the opresult list will be a list of two
794
elements:
795

    
796
- first element the error type (the Ganeti internal error name)
797
- second element a list of either one or two elements:
798

    
799
  - the first element is the textual error description
800
  - the second element, if any, will hold an error classification
801

    
802
The error classification is most useful for the ``OpPrereqError``
803
error type - these errors happen before the OpCode has started
804
executing, so it's possible to retry the OpCode without side
805
effects. But whether it make sense to retry depends on the error
806
classification:
807

    
808
``resolver_error``
809
  Resolver errors. This usually means that a name doesn't exist in DNS,
810
  so if it's a case of slow DNS propagation the operation can be retried
811
  later.
812

    
813
``insufficient_resources``
814
  Not enough resources (iallocator failure, disk space, memory,
815
  etc.). If the resources on the cluster increase, the operation might
816
  succeed.
817

    
818
``wrong_input``
819
  Wrong arguments (at syntax level). The operation will not ever be
820
  accepted unless the arguments change.
821

    
822
``wrong_state``
823
  Wrong entity state. For example, live migration has been requested for
824
  a down instance, or instance creation on an offline node. The
825
  operation can be retried once the resource has changed state.
826

    
827
``unknown_entity``
828
  Entity not found. For example, information has been requested for an
829
  unknown instance.
830

    
831
``already_exists``
832
  Entity already exists. For example, instance creation has been
833
  requested for an already-existing instance.
834

    
835
``resource_not_unique``
836
  Resource not unique (e.g. MAC or IP duplication).
837

    
838
``internal_error``
839
  Internal cluster error. For example, a node is unreachable but not set
840
  offline, or the ganeti node daemons are not working, etc. A
841
  ``gnt-cluster verify`` should be run.
842

    
843
``environment_error``
844
  Environment error (e.g. node disk error). A ``gnt-cluster verify``
845
  should be run.
846

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

    
850

    
851
``DELETE``
852
~~~~~~~~~~
853

    
854
Cancel a not-yet-started job.
855

    
856

    
857
``/2/jobs/[job_id]/wait``
858
+++++++++++++++++++++++++
859

    
860
``GET``
861
~~~~~~~
862

    
863
Waits for changes on a job. Takes the following body parameters in a
864
dict:
865

    
866
``fields``
867
  The job fields on which to watch for changes.
868

    
869
``previous_job_info``
870
  Previously received field values or None if not yet available.
871

    
872
``previous_log_serial``
873
  Highest log serial number received so far or None if not yet
874
  available.
875

    
876
Returns None if no changes have been detected and a dict with two keys,
877
``job_info`` and ``log_entries`` otherwise.
878

    
879

    
880
``/2/nodes``
881
++++++++++++
882

    
883
Nodes resource.
884

    
885
It supports the following commands: ``GET``.
886

    
887
``GET``
888
~~~~~~~
889

    
890
Returns a list of all nodes.
891

    
892
Example::
893

    
894
    [
895
      {
896
        "id": "node1.example.com",
897
        "uri": "\/nodes\/node1.example.com"
898
      },
899
      {
900
        "id": "node2.example.com",
901
        "uri": "\/nodes\/node2.example.com"
902
      }
903
    ]
904

    
905
If the optional 'bulk' argument is provided and set to 'true' value (i.e
906
'?bulk=1'), the output contains detailed information about nodes as a
907
list.
908

    
909
Example::
910

    
911
    [
912
      {
913
        "pinst_cnt": 1,
914
        "mfree": 31280,
915
        "mtotal": 32763,
916
        "name": "www.example.com",
917
        "tags": [],
918
        "mnode": 512,
919
        "dtotal": 5246208,
920
        "sinst_cnt": 2,
921
        "dfree": 5171712,
922
        "offline": false
923
      },
924
      ...
925
    ]
926

    
927
``/2/nodes/[node_name]``
928
+++++++++++++++++++++++++++++++++
929

    
930
Returns information about a node.
931

    
932
It supports the following commands: ``GET``.
933

    
934
``/2/nodes/[node_name]/evacuate``
935
+++++++++++++++++++++++++++++++++
936

    
937
Evacuates all secondary instances off a node.
938

    
939
It supports the following commands: ``POST``.
940

    
941
``POST``
942
~~~~~~~~
943

    
944
To evacuate a node, either one of the ``iallocator`` or ``remote_node``
945
parameters must be passed::
946

    
947
    evacuate?iallocator=[iallocator]
948
    evacuate?remote_node=[nodeX.example.com]
949

    
950
The result value will be a list, each element being a triple of the job
951
id (for this specific evacuation), the instance which is being evacuated
952
by this job, and the node to which it is being relocated. In case the
953
node is already empty, the result will be an empty list (without any
954
jobs being submitted).
955

    
956
And additional parameter ``early_release`` signifies whether to try to
957
parallelize the evacuations, at the risk of increasing I/O contention
958
and increasing the chances of data loss, if the primary node of any of
959
the instances being evacuated is not fully healthy.
960

    
961
If the dry-run parameter was specified, then the evacuation jobs were
962
not actually submitted, and the job IDs will be null.
963

    
964

    
965
``/2/nodes/[node_name]/migrate``
966
+++++++++++++++++++++++++++++++++
967

    
968
Migrates all primary instances from a node.
969

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

    
972
``POST``
973
~~~~~~~~
974

    
975
No parameters are required, but the bool parameter ``live`` can be set
976
to use live migration (if available).
977

    
978
    migrate?live=[0|1]
979

    
980
``/2/nodes/[node_name]/role``
981
+++++++++++++++++++++++++++++
982

    
983
Manages node role.
984

    
985
It supports the following commands: ``GET``, ``PUT``.
986

    
987
The role is always one of the following:
988

    
989
  - drained
990
  - master
991
  - master-candidate
992
  - offline
993
  - regular
994

    
995
``GET``
996
~~~~~~~
997

    
998
Returns the current node role.
999

    
1000
Example::
1001

    
1002
    "master-candidate"
1003

    
1004
``PUT``
1005
~~~~~~~
1006

    
1007
Change the node role.
1008

    
1009
The request is a string which should be PUT to this URI. The result will
1010
be a job id.
1011

    
1012
It supports the bool ``force`` argument.
1013

    
1014
``/2/nodes/[node_name]/storage``
1015
++++++++++++++++++++++++++++++++
1016

    
1017
Manages storage units on the node.
1018

    
1019
``GET``
1020
~~~~~~~
1021

    
1022
Requests a list of storage units on a node. Requires the parameters
1023
``storage_type`` (one of ``file``, ``lvm-pv`` or ``lvm-vg``) and
1024
``output_fields``. The result will be a job id, using which the result
1025
can be retrieved.
1026

    
1027
``/2/nodes/[node_name]/storage/modify``
1028
+++++++++++++++++++++++++++++++++++++++
1029

    
1030
Modifies storage units on the node.
1031

    
1032
``PUT``
1033
~~~~~~~
1034

    
1035
Modifies parameters of storage units on the node. Requires the
1036
parameters ``storage_type`` (one of ``file``, ``lvm-pv`` or ``lvm-vg``)
1037
and ``name`` (name of the storage unit).  Parameters can be passed
1038
additionally. Currently only ``allocatable`` (bool) is supported. The
1039
result will be a job id.
1040

    
1041
``/2/nodes/[node_name]/storage/repair``
1042
+++++++++++++++++++++++++++++++++++++++
1043

    
1044
Repairs a storage unit on the node.
1045

    
1046
``PUT``
1047
~~~~~~~
1048

    
1049
Repairs a storage unit on the node. Requires the parameters
1050
``storage_type`` (currently only ``lvm-vg`` can be repaired) and
1051
``name`` (name of the storage unit). The result will be a job id.
1052

    
1053
``/2/nodes/[node_name]/tags``
1054
+++++++++++++++++++++++++++++
1055

    
1056
Manages per-node tags.
1057

    
1058
It supports the following commands: ``GET``, ``PUT``, ``DELETE``.
1059

    
1060
``GET``
1061
~~~~~~~
1062

    
1063
Returns a list of tags.
1064

    
1065
Example::
1066

    
1067
    ["tag1", "tag2", "tag3"]
1068

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

    
1072
Add a set of tags.
1073

    
1074
The request as a list of strings should be PUT to this URI. The result
1075
will be a job id.
1076

    
1077
It supports the ``dry-run`` argument.
1078

    
1079
``DELETE``
1080
~~~~~~~~~~
1081

    
1082
Deletes tags.
1083

    
1084
In order to delete a set of tags, the DELETE request should be addressed
1085
to URI like::
1086

    
1087
    /tags?tag=[tag]&tag=[tag]
1088

    
1089
It supports the ``dry-run`` argument.
1090

    
1091

    
1092
``/2/os``
1093
+++++++++
1094

    
1095
OS resource.
1096

    
1097
It supports the following commands: ``GET``.
1098

    
1099
``GET``
1100
~~~~~~~
1101

    
1102
Return a list of all OSes.
1103

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

    
1107
Example::
1108

    
1109
    ["debian-etch"]
1110

    
1111
``/2/tags``
1112
+++++++++++
1113

    
1114
Manages cluster tags.
1115

    
1116
It supports the following commands: ``GET``, ``PUT``, ``DELETE``.
1117

    
1118
``GET``
1119
~~~~~~~
1120

    
1121
Returns the cluster tags.
1122

    
1123
Example::
1124

    
1125
    ["tag1", "tag2", "tag3"]
1126

    
1127
``PUT``
1128
~~~~~~~
1129

    
1130
Adds a set of tags.
1131

    
1132
The request as a list of strings should be PUT to this URI. The result
1133
will be a job id.
1134

    
1135
It supports the ``dry-run`` argument.
1136

    
1137

    
1138
``DELETE``
1139
~~~~~~~~~~
1140

    
1141
Deletes tags.
1142

    
1143
In order to delete a set of tags, the DELETE request should be addressed
1144
to URI like::
1145

    
1146
    /tags?tag=[tag]&tag=[tag]
1147

    
1148
It supports the ``dry-run`` argument.
1149

    
1150

    
1151
``/version``
1152
++++++++++++
1153

    
1154
The version resource.
1155

    
1156
This resource should be used to determine the remote API version and to
1157
adapt clients accordingly.
1158

    
1159
It supports the following commands: ``GET``.
1160

    
1161
``GET``
1162
~~~~~~~
1163

    
1164
Returns the remote API version. Ganeti 1.2 returned ``1`` and Ganeti 2.0
1165
returns ``2``.
1166

    
1167
.. vim: set textwidth=72 :
1168
.. Local Variables:
1169
.. mode: rst
1170
.. fill-column: 72
1171
.. End: