Statistics
| Branch: | Tag: | Revision:

root / doc / rapi.rst @ 0dbaa9ca

History | View | Annotate | Download (29.6 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
``instance-reinstall-reqv1``
332
  Instance reinstall supports body parameters.
333

    
334

    
335
``/2/groups``
336
+++++++++++++
337

    
338
The groups resource.
339

    
340
It supports the following commands: ``GET``, ``POST``.
341

    
342
``GET``
343
~~~~~~~
344

    
345
Returns a list of all existing node groups.
346

    
347
Example::
348

    
349
    [
350
      {
351
        "name": "group1",
352
        "uri": "\/2\/groups\/group1"
353
      },
354
      {
355
        "name": "group2",
356
        "uri": "\/2\/groups\/group2"
357
      }
358
    ]
359

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

    
364
Example::
365

    
366
    [
367
      {
368
        "name": "group1",
369
        "node_cnt": 2,
370
        "node_list": [
371
          "node1.example.com",
372
          "node2.example.com"
373
        ],
374
        "uuid": "0d7d407c-262e-49af-881a-6a430034bf43"
375
      },
376
      {
377
        "name": "group2",
378
        "node_cnt": 1,
379
        "node_list": [
380
          "node3.example.com"
381
        ],
382
        "uuid": "f5a277e7-68f9-44d3-a378-4b25ecb5df5c"
383
      }
384
    ]
385

    
386
``POST``
387
~~~~~~~~
388

    
389
Creates a node group.
390

    
391
If the optional bool *dry-run* argument is provided, the job will not be
392
actually executed, only the pre-execution checks will be done.
393

    
394
Returns: a job ID that can be used later for polling.
395

    
396
Body parameters:
397

    
398
``name`` (string, required)
399
  Node group name.
400

    
401

    
402
``/2/groups/[group_name]``
403
++++++++++++++++++++++++++
404

    
405
Returns information about a node group.
406

    
407
It supports the following commands: ``GET``, ``DELETE``.
408

    
409
``GET``
410
~~~~~~~
411

    
412
Returns information about a node group, similar to the bulk output from
413
the node group list.
414

    
415
``DELETE``
416
~~~~~~~~~~
417

    
418
Deletes a node group.
419

    
420
It supports the ``dry-run`` argument.
421

    
422

    
423
``/2/groups/[group_name]/rename``
424
+++++++++++++++++++++++++++++++++
425

    
426
Renames a node group.
427

    
428
Supports the following commands: ``PUT``.
429

    
430
``PUT``
431
~~~~~~~
432

    
433
Returns a job ID.
434

    
435
Body parameters:
436

    
437
``new_name`` (string, required)
438
  New node group name.
439

    
440

    
441
``/2/instances``
442
++++++++++++++++
443

    
444
The instances resource.
445

    
446
It supports the following commands: ``GET``, ``POST``.
447

    
448
``GET``
449
~~~~~~~
450

    
451
Returns a list of all available instances.
452

    
453
Example::
454

    
455
    [
456
      {
457
        "name": "web.example.com",
458
        "uri": "\/instances\/web.example.com"
459
      },
460
      {
461
        "name": "mail.example.com",
462
        "uri": "\/instances\/mail.example.com"
463
      }
464
    ]
465

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

    
470
Example::
471

    
472
    [
473
      {
474
         "status": "running",
475
         "disk_usage": 20480,
476
         "nic.bridges": [
477
           "xen-br0"
478
          ],
479
         "name": "web.example.com",
480
         "tags": ["tag1", "tag2"],
481
         "beparams": {
482
           "vcpus": 2,
483
           "memory": 512
484
         },
485
         "disk.sizes": [
486
             20480
487
         ],
488
         "pnode": "node1.example.com",
489
         "nic.macs": ["01:23:45:67:89:01"],
490
         "snodes": ["node2.example.com"],
491
         "disk_template": "drbd",
492
         "admin_state": true,
493
         "os": "debian-etch",
494
         "oper_state": true
495
      },
496
      ...
497
    ]
498

    
499

    
500
``POST``
501
~~~~~~~~
502

    
503
Creates an instance.
504

    
505
If the optional bool *dry-run* argument is provided, the job will not be
506
actually executed, only the pre-execution checks will be done. Query-ing
507
the job result will return, in both dry-run and normal case, the list of
508
nodes selected for the instance.
509

    
510
Returns: a job ID that can be used later for polling.
511

    
512
Body parameters:
513

    
514
``__version__`` (int, required)
515
  Must be ``1`` (older Ganeti versions used a different format for
516
  instance creation requests, version ``0``, but that format is not
517
  documented).
518
``mode`` (string, required)
519
  Instance creation mode.
520
``name`` (string, required)
521
  Instance name.
522
``disk_template`` (string, required)
523
  Disk template for instance.
524
``disks`` (list, required)
525
  List of disk definitions. Example: ``[{"size": 100}, {"size": 5}]``.
526
  Each disk definition must contain a ``size`` value and can contain an
527
  optional ``mode`` value denoting the disk access mode (``ro`` or
528
  ``rw``).
529
``nics`` (list, required)
530
  List of NIC (network interface) definitions. Example: ``[{}, {},
531
  {"ip": "198.51.100.4"}]``. Each NIC definition can contain the
532
  optional values ``ip``, ``mode``, ``link`` and ``bridge``.
533
``os`` (string, required)
534
  Instance operating system.
535
``osparams`` (dictionary)
536
  Dictionary with OS parameters. If not valid for the given OS, the job
537
  will fail.
538
``force_variant`` (bool)
539
  Whether to force an unknown variant.
540
``no_install`` (bool)
541
  Do not install the OS (will enable no-start)
542
``pnode`` (string)
543
  Primary node.
544
``snode`` (string)
545
  Secondary node.
546
``src_node`` (string)
547
  Source node for import.
548
``src_path`` (string)
549
  Source directory for import.
550
``start`` (bool)
551
  Whether to start instance after creation.
552
``ip_check`` (bool)
553
  Whether to ensure instance's IP address is inactive.
554
``name_check`` (bool)
555
  Whether to ensure instance's name is resolvable.
556
``file_storage_dir`` (string)
557
  File storage directory.
558
``file_driver`` (string)
559
  File storage driver.
560
``iallocator`` (string)
561
  Instance allocator name.
562
``source_handshake`` (list)
563
  Signed handshake from source (remote import only).
564
``source_x509_ca`` (string)
565
  Source X509 CA in PEM format (remote import only).
566
``source_instance_name`` (string)
567
  Source instance name (remote import only).
568
``hypervisor`` (string)
569
  Hypervisor name.
570
``hvparams`` (dict)
571
  Hypervisor parameters, hypervisor-dependent.
572
``beparams`` (dict)
573
  Backend parameters.
574

    
575

    
576
``/2/instances/[instance_name]``
577
++++++++++++++++++++++++++++++++
578

    
579
Instance-specific resource.
580

    
581
It supports the following commands: ``GET``, ``DELETE``.
582

    
583
``GET``
584
~~~~~~~
585

    
586
Returns information about an instance, similar to the bulk output from
587
the instance list.
588

    
589
``DELETE``
590
~~~~~~~~~~
591

    
592
Deletes an instance.
593

    
594
It supports the ``dry-run`` argument.
595

    
596

    
597
``/2/instances/[instance_name]/info``
598
+++++++++++++++++++++++++++++++++++++++
599

    
600
It supports the following commands: ``GET``.
601

    
602
``GET``
603
~~~~~~~
604

    
605
Requests detailed information about the instance. An optional parameter,
606
``static`` (bool), can be set to return only static information from the
607
configuration without querying the instance's nodes. The result will be
608
a job id.
609

    
610

    
611
``/2/instances/[instance_name]/reboot``
612
+++++++++++++++++++++++++++++++++++++++
613

    
614
Reboots URI for an instance.
615

    
616
It supports the following commands: ``POST``.
617

    
618
``POST``
619
~~~~~~~~
620

    
621
Reboots the instance.
622

    
623
The URI takes optional ``type=soft|hard|full`` and
624
``ignore_secondaries=0|1`` parameters.
625

    
626
``type`` defines the reboot type. ``soft`` is just a normal reboot,
627
without terminating the hypervisor. ``hard`` means full shutdown
628
(including terminating the hypervisor process) and startup again.
629
``full`` is like ``hard`` but also recreates the configuration from
630
ground up as if you would have done a ``gnt-instance shutdown`` and
631
``gnt-instance start`` on it.
632

    
633
``ignore_secondaries`` is a bool argument indicating if we start the
634
instance even if secondary disks are failing.
635

    
636
It supports the ``dry-run`` argument.
637

    
638

    
639
``/2/instances/[instance_name]/shutdown``
640
+++++++++++++++++++++++++++++++++++++++++
641

    
642
Instance shutdown URI.
643

    
644
It supports the following commands: ``PUT``.
645

    
646
``PUT``
647
~~~~~~~
648

    
649
Shutdowns an instance.
650

    
651
It supports the ``dry-run`` argument.
652

    
653

    
654
``/2/instances/[instance_name]/startup``
655
++++++++++++++++++++++++++++++++++++++++
656

    
657
Instance startup URI.
658

    
659
It supports the following commands: ``PUT``.
660

    
661
``PUT``
662
~~~~~~~
663

    
664
Startup an instance.
665

    
666
The URI takes an optional ``force=1|0`` parameter to start the
667
instance even if secondary disks are failing.
668

    
669
It supports the ``dry-run`` argument.
670

    
671
``/2/instances/[instance_name]/reinstall``
672
++++++++++++++++++++++++++++++++++++++++++++++
673

    
674
Installs the operating system again.
675

    
676
It supports the following commands: ``POST``.
677

    
678
``POST``
679
~~~~~~~~
680

    
681
Returns a job ID.
682

    
683
Body parameters:
684

    
685
``os`` (string, required)
686
  Instance operating system.
687
``start`` (bool, defaults to true)
688
  Whether to start instance after reinstallation.
689
``osparams`` (dict)
690
  Dictionary with (temporary) OS parameters.
691

    
692
For backwards compatbility, this resource also takes the query
693
parameters ``os`` (OS template name) and ``nostartup`` (bool). New
694
clients should use the body parameters.
695

    
696

    
697
``/2/instances/[instance_name]/replace-disks``
698
++++++++++++++++++++++++++++++++++++++++++++++
699

    
700
Replaces disks on an instance.
701

    
702
It supports the following commands: ``POST``.
703

    
704
``POST``
705
~~~~~~~~
706

    
707
Takes the parameters ``mode`` (one of ``replace_on_primary``,
708
``replace_on_secondary``, ``replace_new_secondary`` or
709
``replace_auto``), ``disks`` (comma separated list of disk indexes),
710
``remote_node`` and ``iallocator``.
711

    
712
Either ``remote_node`` or ``iallocator`` needs to be defined when using
713
``mode=replace_new_secondary``.
714

    
715
``mode`` is a mandatory parameter. ``replace_auto`` tries to determine
716
the broken disk(s) on its own and replacing it.
717

    
718

    
719
``/2/instances/[instance_name]/activate-disks``
720
+++++++++++++++++++++++++++++++++++++++++++++++
721

    
722
Activate disks on an instance.
723

    
724
It supports the following commands: ``PUT``.
725

    
726
``PUT``
727
~~~~~~~
728

    
729
Takes the bool parameter ``ignore_size``. When set ignore the recorded
730
size (useful for forcing activation when recorded size is wrong).
731

    
732

    
733
``/2/instances/[instance_name]/deactivate-disks``
734
+++++++++++++++++++++++++++++++++++++++++++++++++
735

    
736
Deactivate disks on an instance.
737

    
738
It supports the following commands: ``PUT``.
739

    
740
``PUT``
741
~~~~~~~
742

    
743
Takes no parameters.
744

    
745

    
746
``/2/instances/[instance_name]/prepare-export``
747
+++++++++++++++++++++++++++++++++++++++++++++++++
748

    
749
Prepares an export of an instance.
750

    
751
It supports the following commands: ``PUT``.
752

    
753
``PUT``
754
~~~~~~~
755

    
756
Takes one parameter, ``mode``, for the export mode. Returns a job ID.
757

    
758

    
759
``/2/instances/[instance_name]/export``
760
+++++++++++++++++++++++++++++++++++++++++++++++++
761

    
762
Exports an instance.
763

    
764
It supports the following commands: ``PUT``.
765

    
766
``PUT``
767
~~~~~~~
768

    
769
Returns a job ID.
770

    
771
Body parameters:
772

    
773
``mode`` (string)
774
  Export mode.
775
``destination`` (required)
776
  Destination information, depends on export mode.
777
``shutdown`` (bool, required)
778
  Whether to shutdown instance before export.
779
``remove_instance`` (bool)
780
  Whether to remove instance after export.
781
``x509_key_name``
782
  Name of X509 key (remote export only).
783
``destination_x509_ca``
784
  Destination X509 CA (remote export only).
785

    
786

    
787
``/2/instances/[instance_name]/migrate``
788
++++++++++++++++++++++++++++++++++++++++
789

    
790
Migrates an instance.
791

    
792
Supports the following commands: ``PUT``.
793

    
794
``PUT``
795
~~~~~~~
796

    
797
Returns a job ID.
798

    
799
Body parameters:
800

    
801
``mode`` (string)
802
  Migration mode.
803
``cleanup`` (bool)
804
  Whether a previously failed migration should be cleaned up.
805

    
806

    
807
``/2/instances/[instance_name]/rename``
808
++++++++++++++++++++++++++++++++++++++++
809

    
810
Renames an instance.
811

    
812
Supports the following commands: ``PUT``.
813

    
814
``PUT``
815
~~~~~~~
816

    
817
Returns a job ID.
818

    
819
Body parameters:
820

    
821
``new_name`` (string, required)
822
  New instance name.
823
``ip_check`` (bool)
824
  Whether to ensure instance's IP address is inactive.
825
``name_check`` (bool)
826
  Whether to ensure instance's name is resolvable.
827

    
828

    
829
``/2/instances/[instance_name]/modify``
830
++++++++++++++++++++++++++++++++++++++++
831

    
832
Modifies an instance.
833

    
834
Supports the following commands: ``PUT``.
835

    
836
``PUT``
837
~~~~~~~
838

    
839
Returns a job ID.
840

    
841
Body parameters:
842

    
843
``osparams`` (dict)
844
  Dictionary with OS parameters.
845
``hvparams`` (dict)
846
  Hypervisor parameters, hypervisor-dependent.
847
``beparams`` (dict)
848
  Backend parameters.
849
``force`` (bool)
850
  Whether to force the operation.
851
``nics`` (list)
852
  List of NIC changes. Each item is of the form ``(op, settings)``.
853
  ``op`` can be ``add`` to add a new NIC with the specified settings,
854
  ``remove`` to remove the last NIC or a number to modify the settings
855
  of the NIC with that index.
856
``disks`` (list)
857
  List of disk changes. See ``nics``.
858
``disk_template`` (string)
859
  Disk template for instance.
860
``remote_node`` (string)
861
  Secondary node (used when changing disk template).
862
``os_name`` (string)
863
  Change instance's OS name. Does not reinstall the instance.
864
``force_variant`` (bool)
865
  Whether to force an unknown variant.
866

    
867

    
868
``/2/instances/[instance_name]/tags``
869
+++++++++++++++++++++++++++++++++++++
870

    
871
Manages per-instance tags.
872

    
873
It supports the following commands: ``GET``, ``PUT``, ``DELETE``.
874

    
875
``GET``
876
~~~~~~~
877

    
878
Returns a list of tags.
879

    
880
Example::
881

    
882
    ["tag1", "tag2", "tag3"]
883

    
884
``PUT``
885
~~~~~~~
886

    
887
Add a set of tags.
888

    
889
The request as a list of strings should be ``PUT`` to this URI. The
890
result will be a job id.
891

    
892
It supports the ``dry-run`` argument.
893

    
894

    
895
``DELETE``
896
~~~~~~~~~~
897

    
898
Delete a tag.
899

    
900
In order to delete a set of tags, the DELETE request should be addressed
901
to URI like::
902

    
903
    /tags?tag=[tag]&tag=[tag]
904

    
905
It supports the ``dry-run`` argument.
906

    
907

    
908
``/2/jobs``
909
+++++++++++
910

    
911
The ``/2/jobs`` resource.
912

    
913
It supports the following commands: ``GET``.
914

    
915
``GET``
916
~~~~~~~
917

    
918
Returns a dictionary of jobs.
919

    
920
Returns: a dictionary with jobs id and uri.
921

    
922
``/2/jobs/[job_id]``
923
++++++++++++++++++++
924

    
925

    
926
Individual job URI.
927

    
928
It supports the following commands: ``GET``, ``DELETE``.
929

    
930
``GET``
931
~~~~~~~
932

    
933
Returns a job status.
934

    
935
Returns: a dictionary with job parameters.
936

    
937
The result includes:
938

    
939
- id: job ID as a number
940
- status: current job status as a string
941
- ops: involved OpCodes as a list of dictionaries for each opcodes in
942
  the job
943
- opstatus: OpCodes status as a list
944
- opresult: OpCodes results as a list
945

    
946
For a successful opcode, the ``opresult`` field corresponding to it will
947
contain the raw result from its :term:`LogicalUnit`. In case an opcode
948
has failed, its element in the opresult list will be a list of two
949
elements:
950

    
951
- first element the error type (the Ganeti internal error name)
952
- second element a list of either one or two elements:
953

    
954
  - the first element is the textual error description
955
  - the second element, if any, will hold an error classification
956

    
957
The error classification is most useful for the ``OpPrereqError``
958
error type - these errors happen before the OpCode has started
959
executing, so it's possible to retry the OpCode without side
960
effects. But whether it make sense to retry depends on the error
961
classification:
962

    
963
``resolver_error``
964
  Resolver errors. This usually means that a name doesn't exist in DNS,
965
  so if it's a case of slow DNS propagation the operation can be retried
966
  later.
967

    
968
``insufficient_resources``
969
  Not enough resources (iallocator failure, disk space, memory,
970
  etc.). If the resources on the cluster increase, the operation might
971
  succeed.
972

    
973
``wrong_input``
974
  Wrong arguments (at syntax level). The operation will not ever be
975
  accepted unless the arguments change.
976

    
977
``wrong_state``
978
  Wrong entity state. For example, live migration has been requested for
979
  a down instance, or instance creation on an offline node. The
980
  operation can be retried once the resource has changed state.
981

    
982
``unknown_entity``
983
  Entity not found. For example, information has been requested for an
984
  unknown instance.
985

    
986
``already_exists``
987
  Entity already exists. For example, instance creation has been
988
  requested for an already-existing instance.
989

    
990
``resource_not_unique``
991
  Resource not unique (e.g. MAC or IP duplication).
992

    
993
``internal_error``
994
  Internal cluster error. For example, a node is unreachable but not set
995
  offline, or the ganeti node daemons are not working, etc. A
996
  ``gnt-cluster verify`` should be run.
997

    
998
``environment_error``
999
  Environment error (e.g. node disk error). A ``gnt-cluster verify``
1000
  should be run.
1001

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

    
1005

    
1006
``DELETE``
1007
~~~~~~~~~~
1008

    
1009
Cancel a not-yet-started job.
1010

    
1011

    
1012
``/2/jobs/[job_id]/wait``
1013
+++++++++++++++++++++++++
1014

    
1015
``GET``
1016
~~~~~~~
1017

    
1018
Waits for changes on a job. Takes the following body parameters in a
1019
dict:
1020

    
1021
``fields``
1022
  The job fields on which to watch for changes.
1023

    
1024
``previous_job_info``
1025
  Previously received field values or None if not yet available.
1026

    
1027
``previous_log_serial``
1028
  Highest log serial number received so far or None if not yet
1029
  available.
1030

    
1031
Returns None if no changes have been detected and a dict with two keys,
1032
``job_info`` and ``log_entries`` otherwise.
1033

    
1034

    
1035
``/2/nodes``
1036
++++++++++++
1037

    
1038
Nodes resource.
1039

    
1040
It supports the following commands: ``GET``.
1041

    
1042
``GET``
1043
~~~~~~~
1044

    
1045
Returns a list of all nodes.
1046

    
1047
Example::
1048

    
1049
    [
1050
      {
1051
        "id": "node1.example.com",
1052
        "uri": "\/nodes\/node1.example.com"
1053
      },
1054
      {
1055
        "id": "node2.example.com",
1056
        "uri": "\/nodes\/node2.example.com"
1057
      }
1058
    ]
1059

    
1060
If the optional 'bulk' argument is provided and set to 'true' value (i.e
1061
'?bulk=1'), the output contains detailed information about nodes as a
1062
list.
1063

    
1064
Example::
1065

    
1066
    [
1067
      {
1068
        "pinst_cnt": 1,
1069
        "mfree": 31280,
1070
        "mtotal": 32763,
1071
        "name": "www.example.com",
1072
        "tags": [],
1073
        "mnode": 512,
1074
        "dtotal": 5246208,
1075
        "sinst_cnt": 2,
1076
        "dfree": 5171712,
1077
        "offline": false
1078
      },
1079
      ...
1080
    ]
1081

    
1082
``/2/nodes/[node_name]``
1083
+++++++++++++++++++++++++++++++++
1084

    
1085
Returns information about a node.
1086

    
1087
It supports the following commands: ``GET``.
1088

    
1089
``/2/nodes/[node_name]/evacuate``
1090
+++++++++++++++++++++++++++++++++
1091

    
1092
Evacuates all secondary instances off a node.
1093

    
1094
It supports the following commands: ``POST``.
1095

    
1096
``POST``
1097
~~~~~~~~
1098

    
1099
To evacuate a node, either one of the ``iallocator`` or ``remote_node``
1100
parameters must be passed::
1101

    
1102
    evacuate?iallocator=[iallocator]
1103
    evacuate?remote_node=[nodeX.example.com]
1104

    
1105
The result value will be a list, each element being a triple of the job
1106
id (for this specific evacuation), the instance which is being evacuated
1107
by this job, and the node to which it is being relocated. In case the
1108
node is already empty, the result will be an empty list (without any
1109
jobs being submitted).
1110

    
1111
And additional parameter ``early_release`` signifies whether to try to
1112
parallelize the evacuations, at the risk of increasing I/O contention
1113
and increasing the chances of data loss, if the primary node of any of
1114
the instances being evacuated is not fully healthy.
1115

    
1116
If the dry-run parameter was specified, then the evacuation jobs were
1117
not actually submitted, and the job IDs will be null.
1118

    
1119

    
1120
``/2/nodes/[node_name]/migrate``
1121
+++++++++++++++++++++++++++++++++
1122

    
1123
Migrates all primary instances from a node.
1124

    
1125
It supports the following commands: ``POST``.
1126

    
1127
``POST``
1128
~~~~~~~~
1129

    
1130
If no mode is explicitly specified, each instances' hypervisor default
1131
migration mode will be used. Query parameters:
1132

    
1133
``live`` (bool)
1134
  If set, use live migration if available.
1135
``mode`` (string)
1136
  Sets migration mode, ``live`` for live migration and ``non-live`` for
1137
  non-live migration. Supported by Ganeti 2.2 and above.
1138

    
1139

    
1140
``/2/nodes/[node_name]/role``
1141
+++++++++++++++++++++++++++++
1142

    
1143
Manages node role.
1144

    
1145
It supports the following commands: ``GET``, ``PUT``.
1146

    
1147
The role is always one of the following:
1148

    
1149
  - drained
1150
  - master
1151
  - master-candidate
1152
  - offline
1153
  - regular
1154

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

    
1158
Returns the current node role.
1159

    
1160
Example::
1161

    
1162
    "master-candidate"
1163

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

    
1167
Change the node role.
1168

    
1169
The request is a string which should be PUT to this URI. The result will
1170
be a job id.
1171

    
1172
It supports the bool ``force`` argument.
1173

    
1174
``/2/nodes/[node_name]/storage``
1175
++++++++++++++++++++++++++++++++
1176

    
1177
Manages storage units on the node.
1178

    
1179
``GET``
1180
~~~~~~~
1181

    
1182
Requests a list of storage units on a node. Requires the parameters
1183
``storage_type`` (one of ``file``, ``lvm-pv`` or ``lvm-vg``) and
1184
``output_fields``. The result will be a job id, using which the result
1185
can be retrieved.
1186

    
1187
``/2/nodes/[node_name]/storage/modify``
1188
+++++++++++++++++++++++++++++++++++++++
1189

    
1190
Modifies storage units on the node.
1191

    
1192
``PUT``
1193
~~~~~~~
1194

    
1195
Modifies parameters of storage units on the node. Requires the
1196
parameters ``storage_type`` (one of ``file``, ``lvm-pv`` or ``lvm-vg``)
1197
and ``name`` (name of the storage unit).  Parameters can be passed
1198
additionally. Currently only ``allocatable`` (bool) is supported. The
1199
result will be a job id.
1200

    
1201
``/2/nodes/[node_name]/storage/repair``
1202
+++++++++++++++++++++++++++++++++++++++
1203

    
1204
Repairs a storage unit on the node.
1205

    
1206
``PUT``
1207
~~~~~~~
1208

    
1209
Repairs a storage unit on the node. Requires the parameters
1210
``storage_type`` (currently only ``lvm-vg`` can be repaired) and
1211
``name`` (name of the storage unit). The result will be a job id.
1212

    
1213
``/2/nodes/[node_name]/tags``
1214
+++++++++++++++++++++++++++++
1215

    
1216
Manages per-node tags.
1217

    
1218
It supports the following commands: ``GET``, ``PUT``, ``DELETE``.
1219

    
1220
``GET``
1221
~~~~~~~
1222

    
1223
Returns a list of tags.
1224

    
1225
Example::
1226

    
1227
    ["tag1", "tag2", "tag3"]
1228

    
1229
``PUT``
1230
~~~~~~~
1231

    
1232
Add a set of tags.
1233

    
1234
The request as a list of strings should be PUT to this URI. The result
1235
will be a job id.
1236

    
1237
It supports the ``dry-run`` argument.
1238

    
1239
``DELETE``
1240
~~~~~~~~~~
1241

    
1242
Deletes tags.
1243

    
1244
In order to delete a set of tags, the DELETE request should be addressed
1245
to URI like::
1246

    
1247
    /tags?tag=[tag]&tag=[tag]
1248

    
1249
It supports the ``dry-run`` argument.
1250

    
1251

    
1252
``/2/os``
1253
+++++++++
1254

    
1255
OS resource.
1256

    
1257
It supports the following commands: ``GET``.
1258

    
1259
``GET``
1260
~~~~~~~
1261

    
1262
Return a list of all OSes.
1263

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

    
1267
Example::
1268

    
1269
    ["debian-etch"]
1270

    
1271
``/2/tags``
1272
+++++++++++
1273

    
1274
Manages cluster tags.
1275

    
1276
It supports the following commands: ``GET``, ``PUT``, ``DELETE``.
1277

    
1278
``GET``
1279
~~~~~~~
1280

    
1281
Returns the cluster tags.
1282

    
1283
Example::
1284

    
1285
    ["tag1", "tag2", "tag3"]
1286

    
1287
``PUT``
1288
~~~~~~~
1289

    
1290
Adds a set of tags.
1291

    
1292
The request as a list of strings should be PUT to this URI. The result
1293
will be a job id.
1294

    
1295
It supports the ``dry-run`` argument.
1296

    
1297

    
1298
``DELETE``
1299
~~~~~~~~~~
1300

    
1301
Deletes tags.
1302

    
1303
In order to delete a set of tags, the DELETE request should be addressed
1304
to URI like::
1305

    
1306
    /tags?tag=[tag]&tag=[tag]
1307

    
1308
It supports the ``dry-run`` argument.
1309

    
1310

    
1311
``/version``
1312
++++++++++++
1313

    
1314
The version resource.
1315

    
1316
This resource should be used to determine the remote API version and to
1317
adapt clients accordingly.
1318

    
1319
It supports the following commands: ``GET``.
1320

    
1321
``GET``
1322
~~~~~~~
1323

    
1324
Returns the remote API version. Ganeti 1.2 returned ``1`` and Ganeti 2.0
1325
returns ``2``.
1326

    
1327
.. vim: set textwidth=72 :
1328
.. Local Variables:
1329
.. mode: rst
1330
.. fill-column: 72
1331
.. End: