Statistics
| Branch: | Tag: | Revision:

root / doc / rapi.rst @ c0a146a1

History | View | Annotate | Download (32.3 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
HTTP requests with a body (e.g. ``PUT`` or ``POST``) require the request
74
header ``Content-type`` be set to ``application/json`` (see :rfc:`2616`
75
(HTTP/1.1), section 7.2.1).
76

    
77

    
78
A note on JSON as used by RAPI
79
++++++++++++++++++++++++++++++
80

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

    
88
.. highlight:: ruby
89

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

    
98
  require "json"
99

    
100
  # Insert code to get response here
101
  response = "\"1234\""
102

    
103
  decoded = JSON.parse("[#{response}]").first
104

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

    
110

    
111
PUT or POST?
112
------------
113

    
114
According to :rfc:`2616` the main difference between PUT and POST is
115
that POST can create new resources but PUT can only create the resource
116
the URI was pointing to on the PUT request.
117

    
118
Unfortunately, due to historic reasons, the Ganeti RAPI library is not
119
consistent with this usage, so just use the methods as documented below
120
for each resource.
121

    
122
For more details have a look in the source code at
123
``lib/rapi/rlib2.py``.
124

    
125

    
126
Generic parameter types
127
-----------------------
128

    
129
A few generic refered parameter types and the values they allow.
130

    
131
``bool``
132
++++++++
133

    
134
A boolean option will accept ``1`` or ``0`` as numbers but not
135
i.e. ``True`` or ``False``.
136

    
137
Generic parameters
138
------------------
139

    
140
A few parameter mean the same thing across all resources which implement
141
it.
142

    
143
``bulk``
144
++++++++
145

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

    
152
``dry-run``
153
+++++++++++
154

    
155
The boolean *dry-run* argument, if provided and set, signals to Ganeti
156
that the job should not be executed, only the pre-execution checks will
157
be done.
158

    
159
This is useful in trying to determine (without guarantees though, as in
160
the meantime the cluster state could have changed) if the operation is
161
likely to succeed or at least start executing.
162

    
163
``force``
164
+++++++++++
165

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

    
169
Usage examples
170
--------------
171

    
172
You can access the API using your favorite programming language as long
173
as it supports network connections.
174

    
175
Ganeti RAPI client
176
++++++++++++++++++
177

    
178
Ganeti includes a standalone RAPI client, ``lib/rapi/client.py``.
179

    
180
Shell
181
+++++
182

    
183
.. highlight:: sh
184

    
185
Using wget::
186

    
187
   wget -q -O - https://CLUSTERNAME:5080/2/info
188

    
189
or curl::
190

    
191
  curl https://CLUSTERNAME:5080/2/info
192

    
193

    
194
Python
195
++++++
196

    
197
.. highlight:: python
198

    
199
::
200

    
201
  import urllib2
202
  f = urllib2.urlopen('https://CLUSTERNAME:5080/2/info')
203
  print f.read()
204

    
205

    
206
JavaScript
207
++++++++++
208

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

    
214
.. highlight:: javascript
215

    
216
::
217

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

    
234
Resources
235
---------
236

    
237
.. highlight:: javascript
238

    
239
``/``
240
+++++
241

    
242
The root resource.
243

    
244
It supports the following commands: ``GET``.
245

    
246
``GET``
247
~~~~~~~
248

    
249
Shows the list of mapped resources.
250

    
251
Returns: a dictionary with 'name' and 'uri' keys for each of them.
252

    
253
``/2``
254
++++++
255

    
256
The ``/2`` resource, the root of the version 2 API.
257

    
258
It supports the following commands: ``GET``.
259

    
260
``GET``
261
~~~~~~~
262

    
263
Show the list of mapped resources.
264

    
265
Returns: a dictionary with ``name`` and ``uri`` keys for each of them.
266

    
267
``/2/info``
268
+++++++++++
269

    
270
Cluster information resource.
271

    
272
It supports the following commands: ``GET``.
273

    
274
``GET``
275
~~~~~~~
276

    
277
Returns cluster information.
278

    
279
Example::
280

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

    
310

    
311
``/2/redistribute-config``
312
++++++++++++++++++++++++++
313

    
314
Redistribute configuration to all nodes.
315

    
316
It supports the following commands: ``PUT``.
317

    
318
``PUT``
319
~~~~~~~
320

    
321
Redistribute configuration to all nodes. The result will be a job id.
322

    
323

    
324
``/2/features``
325
+++++++++++++++
326

    
327
``GET``
328
~~~~~~~
329

    
330
Returns a list of features supported by the RAPI server. Available
331
features:
332

    
333
.. pyassert::
334

    
335
  rlib2.ALL_FEATURES == set([rlib2._INST_CREATE_REQV1,
336
                             rlib2._INST_REINSTALL_REQV1,
337
                             rlib2._NODE_MIGRATE_REQV1,
338
                             rlib2._NODE_EVAC_RES1])
339

    
340
:pyeval:`rlib2._INST_CREATE_REQV1`
341
  Instance creation request data version 1 supported.
342
:pyeval:`rlib2._INST_REINSTALL_REQV1`
343
  Instance reinstall supports body parameters.
344
:pyeval:`rlib2._NODE_MIGRATE_REQV1`
345
  Whether migrating a node (``/2/nodes/[node_name]/migrate``) supports
346
  request body parameters.
347
:pyeval:`rlib2._NODE_EVAC_RES1`
348
  Whether evacuating a node (``/2/nodes/[node_name]/evacuate``) returns
349
  a new-style result (see resource description)
350

    
351

    
352
``/2/modify``
353
++++++++++++++++++++++++++++++++++++++++
354

    
355
Modifies cluster parameters.
356

    
357
Supports the following commands: ``PUT``.
358

    
359
``PUT``
360
~~~~~~~
361

    
362
Returns a job ID.
363

    
364
Body parameters:
365

    
366
.. opcode_params:: OP_CLUSTER_SET_PARAMS
367

    
368

    
369
``/2/groups``
370
+++++++++++++
371

    
372
The groups resource.
373

    
374
It supports the following commands: ``GET``, ``POST``.
375

    
376
``GET``
377
~~~~~~~
378

    
379
Returns a list of all existing node groups.
380

    
381
Example::
382

    
383
    [
384
      {
385
        "name": "group1",
386
        "uri": "\/2\/groups\/group1"
387
      },
388
      {
389
        "name": "group2",
390
        "uri": "\/2\/groups\/group2"
391
      }
392
    ]
393

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

    
398
Example::
399

    
400
    [
401
      {
402
        "name": "group1",
403
        "node_cnt": 2,
404
        "node_list": [
405
          "node1.example.com",
406
          "node2.example.com"
407
        ],
408
        "uuid": "0d7d407c-262e-49af-881a-6a430034bf43"
409
      },
410
      {
411
        "name": "group2",
412
        "node_cnt": 1,
413
        "node_list": [
414
          "node3.example.com"
415
        ],
416
        "uuid": "f5a277e7-68f9-44d3-a378-4b25ecb5df5c"
417
      }
418
    ]
419

    
420
``POST``
421
~~~~~~~~
422

    
423
Creates a node group.
424

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

    
428
Returns: a job ID that can be used later for polling.
429

    
430
Body parameters:
431

    
432
.. opcode_params:: OP_GROUP_ADD
433

    
434
Earlier versions used a parameter named ``name`` which, while still
435
supported, has been renamed to ``group_name``.
436

    
437

    
438
``/2/groups/[group_name]``
439
++++++++++++++++++++++++++
440

    
441
Returns information about a node group.
442

    
443
It supports the following commands: ``GET``, ``DELETE``.
444

    
445
``GET``
446
~~~~~~~
447

    
448
Returns information about a node group, similar to the bulk output from
449
the node group list.
450

    
451
``DELETE``
452
~~~~~~~~~~
453

    
454
Deletes a node group.
455

    
456
It supports the ``dry-run`` argument.
457

    
458

    
459
``/2/groups/[group_name]/modify``
460
+++++++++++++++++++++++++++++++++
461

    
462
Modifies the parameters of a node group.
463

    
464
Supports the following commands: ``PUT``.
465

    
466
``PUT``
467
~~~~~~~
468

    
469
Returns a job ID.
470

    
471
Body parameters:
472

    
473
.. opcode_params:: OP_GROUP_SET_PARAMS
474
   :exclude: group_name
475

    
476

    
477
``/2/groups/[group_name]/rename``
478
+++++++++++++++++++++++++++++++++
479

    
480
Renames a node group.
481

    
482
Supports the following commands: ``PUT``.
483

    
484
``PUT``
485
~~~~~~~
486

    
487
Returns a job ID.
488

    
489
Body parameters:
490

    
491
.. opcode_params:: OP_GROUP_RENAME
492
   :exclude: group_name
493

    
494

    
495
``/2/groups/[group_name]/assign-nodes``
496
+++++++++++++++++++++++++++++++++++++++
497

    
498
Assigns nodes to a group.
499

    
500
Supports the following commands: ``PUT``.
501

    
502
``PUT``
503
~~~~~~~
504

    
505
Returns a job ID. It supports the ``dry-run`` and ``force`` arguments.
506

    
507
Body parameters:
508

    
509
.. opcode_params:: OP_GROUP_ASSIGN_NODES
510
   :exclude: group_name, force, dry_run
511

    
512

    
513
``/2/groups/[group_name]/tags``
514
+++++++++++++++++++++++++++++++
515

    
516
Manages per-nodegroup tags.
517

    
518
Supports the following commands: ``GET``, ``PUT``, ``DELETE``.
519

    
520
``GET``
521
~~~~~~~
522

    
523
Returns a list of tags.
524

    
525
Example::
526

    
527
    ["tag1", "tag2", "tag3"]
528

    
529
``PUT``
530
~~~~~~~
531

    
532
Add a set of tags.
533

    
534
The request as a list of strings should be ``PUT`` to this URI. The
535
result will be a job id.
536

    
537
It supports the ``dry-run`` argument.
538

    
539

    
540
``DELETE``
541
~~~~~~~~~~
542

    
543
Delete a tag.
544

    
545
In order to delete a set of tags, the DELETE request should be addressed
546
to URI like::
547

    
548
    /tags?tag=[tag]&tag=[tag]
549

    
550
It supports the ``dry-run`` argument.
551

    
552

    
553
``/2/instances``
554
++++++++++++++++
555

    
556
The instances resource.
557

    
558
It supports the following commands: ``GET``, ``POST``.
559

    
560
``GET``
561
~~~~~~~
562

    
563
Returns a list of all available instances.
564

    
565
Example::
566

    
567
    [
568
      {
569
        "name": "web.example.com",
570
        "uri": "\/instances\/web.example.com"
571
      },
572
      {
573
        "name": "mail.example.com",
574
        "uri": "\/instances\/mail.example.com"
575
      }
576
    ]
577

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

    
582
Example::
583

    
584
    [
585
      {
586
         "status": "running",
587
         "disk_usage": 20480,
588
         "nic.bridges": [
589
           "xen-br0"
590
          ],
591
         "name": "web.example.com",
592
         "tags": ["tag1", "tag2"],
593
         "beparams": {
594
           "vcpus": 2,
595
           "memory": 512
596
         },
597
         "disk.sizes": [
598
             20480
599
         ],
600
         "pnode": "node1.example.com",
601
         "nic.macs": ["01:23:45:67:89:01"],
602
         "snodes": ["node2.example.com"],
603
         "disk_template": "drbd",
604
         "admin_state": true,
605
         "os": "debian-etch",
606
         "oper_state": true
607
      },
608
      ...
609
    ]
610

    
611

    
612
``POST``
613
~~~~~~~~
614

    
615
Creates an instance.
616

    
617
If the optional bool *dry-run* argument is provided, the job will not be
618
actually executed, only the pre-execution checks will be done. Query-ing
619
the job result will return, in both dry-run and normal case, the list of
620
nodes selected for the instance.
621

    
622
Returns: a job ID that can be used later for polling.
623

    
624
Body parameters:
625

    
626
``__version__`` (int, required)
627
  Must be ``1`` (older Ganeti versions used a different format for
628
  instance creation requests, version ``0``, but that format is no
629
  longer supported)
630

    
631
.. opcode_params:: OP_INSTANCE_CREATE
632

    
633
Earlier versions used parameters named ``name`` and ``os``. These have
634
been replaced by ``instance_name`` and ``os_type`` to match the
635
underlying opcode. The old names can still be used.
636

    
637

    
638
``/2/instances/[instance_name]``
639
++++++++++++++++++++++++++++++++
640

    
641
Instance-specific resource.
642

    
643
It supports the following commands: ``GET``, ``DELETE``.
644

    
645
``GET``
646
~~~~~~~
647

    
648
Returns information about an instance, similar to the bulk output from
649
the instance list.
650

    
651
``DELETE``
652
~~~~~~~~~~
653

    
654
Deletes an instance.
655

    
656
It supports the ``dry-run`` argument.
657

    
658

    
659
``/2/instances/[instance_name]/info``
660
+++++++++++++++++++++++++++++++++++++++
661

    
662
It supports the following commands: ``GET``.
663

    
664
``GET``
665
~~~~~~~
666

    
667
Requests detailed information about the instance. An optional parameter,
668
``static`` (bool), can be set to return only static information from the
669
configuration without querying the instance's nodes. The result will be
670
a job id.
671

    
672

    
673
``/2/instances/[instance_name]/reboot``
674
+++++++++++++++++++++++++++++++++++++++
675

    
676
Reboots URI for an instance.
677

    
678
It supports the following commands: ``POST``.
679

    
680
``POST``
681
~~~~~~~~
682

    
683
Reboots the instance.
684

    
685
The URI takes optional ``type=soft|hard|full`` and
686
``ignore_secondaries=0|1`` parameters.
687

    
688
``type`` defines the reboot type. ``soft`` is just a normal reboot,
689
without terminating the hypervisor. ``hard`` means full shutdown
690
(including terminating the hypervisor process) and startup again.
691
``full`` is like ``hard`` but also recreates the configuration from
692
ground up as if you would have done a ``gnt-instance shutdown`` and
693
``gnt-instance start`` on it.
694

    
695
``ignore_secondaries`` is a bool argument indicating if we start the
696
instance even if secondary disks are failing.
697

    
698
It supports the ``dry-run`` argument.
699

    
700

    
701
``/2/instances/[instance_name]/shutdown``
702
+++++++++++++++++++++++++++++++++++++++++
703

    
704
Instance shutdown URI.
705

    
706
It supports the following commands: ``PUT``.
707

    
708
``PUT``
709
~~~~~~~
710

    
711
Shutdowns an instance.
712

    
713
It supports the ``dry-run`` argument.
714

    
715
.. opcode_params:: OP_INSTANCE_SHUTDOWN
716
   :exclude: instance_name, dry_run
717

    
718

    
719
``/2/instances/[instance_name]/startup``
720
++++++++++++++++++++++++++++++++++++++++
721

    
722
Instance startup URI.
723

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

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

    
729
Startup an instance.
730

    
731
The URI takes an optional ``force=1|0`` parameter to start the
732
instance even if secondary disks are failing.
733

    
734
It supports the ``dry-run`` argument.
735

    
736
``/2/instances/[instance_name]/reinstall``
737
++++++++++++++++++++++++++++++++++++++++++++++
738

    
739
Installs the operating system again.
740

    
741
It supports the following commands: ``POST``.
742

    
743
``POST``
744
~~~~~~~~
745

    
746
Returns a job ID.
747

    
748
Body parameters:
749

    
750
``os`` (string, required)
751
  Instance operating system.
752
``start`` (bool, defaults to true)
753
  Whether to start instance after reinstallation.
754
``osparams`` (dict)
755
  Dictionary with (temporary) OS parameters.
756

    
757
For backwards compatbility, this resource also takes the query
758
parameters ``os`` (OS template name) and ``nostartup`` (bool). New
759
clients should use the body parameters.
760

    
761

    
762
``/2/instances/[instance_name]/replace-disks``
763
++++++++++++++++++++++++++++++++++++++++++++++
764

    
765
Replaces disks on an instance.
766

    
767
It supports the following commands: ``POST``.
768

    
769
``POST``
770
~~~~~~~~
771

    
772
Takes the parameters ``mode`` (one of ``replace_on_primary``,
773
``replace_on_secondary``, ``replace_new_secondary`` or
774
``replace_auto``), ``disks`` (comma separated list of disk indexes),
775
``remote_node`` and ``iallocator``.
776

    
777
Either ``remote_node`` or ``iallocator`` needs to be defined when using
778
``mode=replace_new_secondary``.
779

    
780
``mode`` is a mandatory parameter. ``replace_auto`` tries to determine
781
the broken disk(s) on its own and replacing it.
782

    
783

    
784
``/2/instances/[instance_name]/activate-disks``
785
+++++++++++++++++++++++++++++++++++++++++++++++
786

    
787
Activate disks on an instance.
788

    
789
It supports the following commands: ``PUT``.
790

    
791
``PUT``
792
~~~~~~~
793

    
794
Takes the bool parameter ``ignore_size``. When set ignore the recorded
795
size (useful for forcing activation when recorded size is wrong).
796

    
797

    
798
``/2/instances/[instance_name]/deactivate-disks``
799
+++++++++++++++++++++++++++++++++++++++++++++++++
800

    
801
Deactivate disks on an instance.
802

    
803
It supports the following commands: ``PUT``.
804

    
805
``PUT``
806
~~~~~~~
807

    
808
Takes no parameters.
809

    
810

    
811
``/2/instances/[instance_name]/disk/[disk_index]/grow``
812
+++++++++++++++++++++++++++++++++++++++++++++++++++++++
813

    
814
Grows one disk of an instance.
815

    
816
Supports the following commands: ``POST``.
817

    
818
``POST``
819
~~~~~~~~
820

    
821
Returns a job ID.
822

    
823
Body parameters:
824

    
825
.. opcode_params:: OP_INSTANCE_GROW_DISK
826
   :exclude: instance_name, disk
827

    
828

    
829
``/2/instances/[instance_name]/prepare-export``
830
+++++++++++++++++++++++++++++++++++++++++++++++++
831

    
832
Prepares an export of an instance.
833

    
834
It supports the following commands: ``PUT``.
835

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

    
839
Takes one parameter, ``mode``, for the export mode. Returns a job ID.
840

    
841

    
842
``/2/instances/[instance_name]/export``
843
+++++++++++++++++++++++++++++++++++++++++++++++++
844

    
845
Exports an instance.
846

    
847
It supports the following commands: ``PUT``.
848

    
849
``PUT``
850
~~~~~~~
851

    
852
Returns a job ID.
853

    
854
Body parameters:
855

    
856
.. opcode_params:: OP_BACKUP_EXPORT
857
   :exclude: instance_name
858
   :alias: target_node=destination
859

    
860

    
861
``/2/instances/[instance_name]/migrate``
862
++++++++++++++++++++++++++++++++++++++++
863

    
864
Migrates an instance.
865

    
866
Supports the following commands: ``PUT``.
867

    
868
``PUT``
869
~~~~~~~
870

    
871
Returns a job ID.
872

    
873
Body parameters:
874

    
875
.. opcode_params:: OP_INSTANCE_MIGRATE
876
   :exclude: instance_name, live
877

    
878

    
879
``/2/instances/[instance_name]/failover``
880
+++++++++++++++++++++++++++++++++++++++++
881

    
882
Does a failover of an instance.
883

    
884
Supports the following commands: ``PUT``.
885

    
886
``PUT``
887
~~~~~~~
888

    
889
Returns a job ID.
890

    
891
Body parameters:
892

    
893
.. opcode_params:: OP_INSTANCE_FAILOVER
894
   :exclude: instance_name
895

    
896

    
897
``/2/instances/[instance_name]/rename``
898
++++++++++++++++++++++++++++++++++++++++
899

    
900
Renames an instance.
901

    
902
Supports the following commands: ``PUT``.
903

    
904
``PUT``
905
~~~~~~~
906

    
907
Returns a job ID.
908

    
909
Body parameters:
910

    
911
.. opcode_params:: OP_INSTANCE_RENAME
912
   :exclude: instance_name
913

    
914

    
915
``/2/instances/[instance_name]/modify``
916
++++++++++++++++++++++++++++++++++++++++
917

    
918
Modifies an instance.
919

    
920
Supports the following commands: ``PUT``.
921

    
922
``PUT``
923
~~~~~~~
924

    
925
Returns a job ID.
926

    
927
Body parameters:
928

    
929
.. opcode_params:: OP_INSTANCE_SET_PARAMS
930
   :exclude: instance_name
931

    
932

    
933
``/2/instances/[instance_name]/console``
934
++++++++++++++++++++++++++++++++++++++++
935

    
936
Request information for connecting to instance's console.
937

    
938
Supports the following commands: ``GET``.
939

    
940
``GET``
941
~~~~~~~
942

    
943
Returns a dictionary containing information about the instance's
944
console. Contained keys:
945

    
946
``instance``
947
  Instance name.
948
``kind``
949
  Console type, one of ``ssh``, ``vnc`` or ``msg``.
950
``message``
951
  Message to display (``msg`` type only).
952
``host``
953
  Host to connect to (``ssh`` and ``vnc`` only).
954
``port``
955
  TCP port to connect to (``vnc`` only).
956
``user``
957
  Username to use (``ssh`` only).
958
``command``
959
  Command to execute on machine (``ssh`` only)
960
``display``
961
  VNC display number (``vnc`` only).
962

    
963

    
964
``/2/instances/[instance_name]/tags``
965
+++++++++++++++++++++++++++++++++++++
966

    
967
Manages per-instance tags.
968

    
969
It supports the following commands: ``GET``, ``PUT``, ``DELETE``.
970

    
971
``GET``
972
~~~~~~~
973

    
974
Returns a list of tags.
975

    
976
Example::
977

    
978
    ["tag1", "tag2", "tag3"]
979

    
980
``PUT``
981
~~~~~~~
982

    
983
Add a set of tags.
984

    
985
The request as a list of strings should be ``PUT`` to this URI. The
986
result will be a job id.
987

    
988
It supports the ``dry-run`` argument.
989

    
990

    
991
``DELETE``
992
~~~~~~~~~~
993

    
994
Delete a tag.
995

    
996
In order to delete a set of tags, the DELETE request should be addressed
997
to URI like::
998

    
999
    /tags?tag=[tag]&tag=[tag]
1000

    
1001
It supports the ``dry-run`` argument.
1002

    
1003

    
1004
``/2/jobs``
1005
+++++++++++
1006

    
1007
The ``/2/jobs`` resource.
1008

    
1009
It supports the following commands: ``GET``.
1010

    
1011
``GET``
1012
~~~~~~~
1013

    
1014
Returns a dictionary of jobs.
1015

    
1016
Returns: a dictionary with jobs id and uri.
1017

    
1018
``/2/jobs/[job_id]``
1019
++++++++++++++++++++
1020

    
1021

    
1022
Individual job URI.
1023

    
1024
It supports the following commands: ``GET``, ``DELETE``.
1025

    
1026
``GET``
1027
~~~~~~~
1028

    
1029
Returns a job status.
1030

    
1031
Returns: a dictionary with job parameters.
1032

    
1033
The result includes:
1034

    
1035
- id: job ID as a number
1036
- status: current job status as a string
1037
- ops: involved OpCodes as a list of dictionaries for each opcodes in
1038
  the job
1039
- opstatus: OpCodes status as a list
1040
- opresult: OpCodes results as a list
1041

    
1042
For a successful opcode, the ``opresult`` field corresponding to it will
1043
contain the raw result from its :term:`LogicalUnit`. In case an opcode
1044
has failed, its element in the opresult list will be a list of two
1045
elements:
1046

    
1047
- first element the error type (the Ganeti internal error name)
1048
- second element a list of either one or two elements:
1049

    
1050
  - the first element is the textual error description
1051
  - the second element, if any, will hold an error classification
1052

    
1053
The error classification is most useful for the ``OpPrereqError``
1054
error type - these errors happen before the OpCode has started
1055
executing, so it's possible to retry the OpCode without side
1056
effects. But whether it make sense to retry depends on the error
1057
classification:
1058

    
1059
.. pyassert::
1060

    
1061
   errors.ECODE_ALL == set([errors.ECODE_RESOLVER, errors.ECODE_NORES,
1062
     errors.ECODE_INVAL, errors.ECODE_STATE, errors.ECODE_NOENT,
1063
     errors.ECODE_EXISTS, errors.ECODE_NOTUNIQUE, errors.ECODE_FAULT,
1064
     errors.ECODE_ENVIRON])
1065

    
1066
:pyeval:`errors.ECODE_RESOLVER`
1067
  Resolver errors. This usually means that a name doesn't exist in DNS,
1068
  so if it's a case of slow DNS propagation the operation can be retried
1069
  later.
1070

    
1071
:pyeval:`errors.ECODE_NORES`
1072
  Not enough resources (iallocator failure, disk space, memory,
1073
  etc.). If the resources on the cluster increase, the operation might
1074
  succeed.
1075

    
1076
:pyeval:`errors.ECODE_INVAL`
1077
  Wrong arguments (at syntax level). The operation will not ever be
1078
  accepted unless the arguments change.
1079

    
1080
:pyeval:`errors.ECODE_STATE`
1081
  Wrong entity state. For example, live migration has been requested for
1082
  a down instance, or instance creation on an offline node. The
1083
  operation can be retried once the resource has changed state.
1084

    
1085
:pyeval:`errors.ECODE_NOENT`
1086
  Entity not found. For example, information has been requested for an
1087
  unknown instance.
1088

    
1089
:pyeval:`errors.ECODE_EXISTS`
1090
  Entity already exists. For example, instance creation has been
1091
  requested for an already-existing instance.
1092

    
1093
:pyeval:`errors.ECODE_NOTUNIQUE`
1094
  Resource not unique (e.g. MAC or IP duplication).
1095

    
1096
:pyeval:`errors.ECODE_FAULT`
1097
  Internal cluster error. For example, a node is unreachable but not set
1098
  offline, or the ganeti node daemons are not working, etc. A
1099
  ``gnt-cluster verify`` should be run.
1100

    
1101
:pyeval:`errors.ECODE_ENVIRON`
1102
  Environment error (e.g. node disk error). A ``gnt-cluster verify``
1103
  should be run.
1104

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

    
1108

    
1109
``DELETE``
1110
~~~~~~~~~~
1111

    
1112
Cancel a not-yet-started job.
1113

    
1114

    
1115
``/2/jobs/[job_id]/wait``
1116
+++++++++++++++++++++++++
1117

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

    
1121
Waits for changes on a job. Takes the following body parameters in a
1122
dict:
1123

    
1124
``fields``
1125
  The job fields on which to watch for changes.
1126

    
1127
``previous_job_info``
1128
  Previously received field values or None if not yet available.
1129

    
1130
``previous_log_serial``
1131
  Highest log serial number received so far or None if not yet
1132
  available.
1133

    
1134
Returns None if no changes have been detected and a dict with two keys,
1135
``job_info`` and ``log_entries`` otherwise.
1136

    
1137

    
1138
``/2/nodes``
1139
++++++++++++
1140

    
1141
Nodes resource.
1142

    
1143
It supports the following commands: ``GET``.
1144

    
1145
``GET``
1146
~~~~~~~
1147

    
1148
Returns a list of all nodes.
1149

    
1150
Example::
1151

    
1152
    [
1153
      {
1154
        "id": "node1.example.com",
1155
        "uri": "\/nodes\/node1.example.com"
1156
      },
1157
      {
1158
        "id": "node2.example.com",
1159
        "uri": "\/nodes\/node2.example.com"
1160
      }
1161
    ]
1162

    
1163
If the optional 'bulk' argument is provided and set to 'true' value (i.e
1164
'?bulk=1'), the output contains detailed information about nodes as a
1165
list.
1166

    
1167
Example::
1168

    
1169
    [
1170
      {
1171
        "pinst_cnt": 1,
1172
        "mfree": 31280,
1173
        "mtotal": 32763,
1174
        "name": "www.example.com",
1175
        "tags": [],
1176
        "mnode": 512,
1177
        "dtotal": 5246208,
1178
        "sinst_cnt": 2,
1179
        "dfree": 5171712,
1180
        "offline": false
1181
      },
1182
      ...
1183
    ]
1184

    
1185
``/2/nodes/[node_name]``
1186
+++++++++++++++++++++++++++++++++
1187

    
1188
Returns information about a node.
1189

    
1190
It supports the following commands: ``GET``.
1191

    
1192
``/2/nodes/[node_name]/evacuate``
1193
+++++++++++++++++++++++++++++++++
1194

    
1195
Evacuates instances off a node.
1196

    
1197
It supports the following commands: ``POST``.
1198

    
1199
``POST``
1200
~~~~~~~~
1201

    
1202
Returns a job ID. The result of the job will contain the IDs of the
1203
individual jobs submitted to evacuate the node.
1204

    
1205
Body parameters:
1206

    
1207
.. opcode_params:: OP_NODE_EVACUATE
1208
   :exclude: nodes
1209

    
1210
Up to and including Ganeti 2.4 query arguments were used. Those are no
1211
longer supported. The new request can be detected by the presence of the
1212
:pyeval:`rlib2._NODE_EVAC_RES1` feature string.
1213

    
1214

    
1215
``/2/nodes/[node_name]/migrate``
1216
+++++++++++++++++++++++++++++++++
1217

    
1218
Migrates all primary instances from a node.
1219

    
1220
It supports the following commands: ``POST``.
1221

    
1222
``POST``
1223
~~~~~~~~
1224

    
1225
If no mode is explicitly specified, each instances' hypervisor default
1226
migration mode will be used. Body parameters:
1227

    
1228
.. opcode_params:: OP_NODE_MIGRATE
1229
   :exclude: node_name
1230

    
1231
The query arguments used up to and including Ganeti 2.4 are deprecated
1232
and should no longer be used. The new request format can be detected by
1233
the presence of the :pyeval:`rlib2._NODE_MIGRATE_REQV1` feature string.
1234

    
1235

    
1236
``/2/nodes/[node_name]/role``
1237
+++++++++++++++++++++++++++++
1238

    
1239
Manages node role.
1240

    
1241
It supports the following commands: ``GET``, ``PUT``.
1242

    
1243
The role is always one of the following:
1244

    
1245
  - drained
1246
  - master-candidate
1247
  - offline
1248
  - regular
1249

    
1250
Note that the 'master' role is a special, and currently it can't be
1251
modified via RAPI, only via the command line (``gnt-cluster
1252
master-failover``).
1253

    
1254
``GET``
1255
~~~~~~~
1256

    
1257
Returns the current node role.
1258

    
1259
Example::
1260

    
1261
    "master-candidate"
1262

    
1263
``PUT``
1264
~~~~~~~
1265

    
1266
Change the node role.
1267

    
1268
The request is a string which should be PUT to this URI. The result will
1269
be a job id.
1270

    
1271
It supports the bool ``force`` argument.
1272

    
1273
``/2/nodes/[node_name]/storage``
1274
++++++++++++++++++++++++++++++++
1275

    
1276
Manages storage units on the node.
1277

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

    
1281
.. pyassert::
1282

    
1283
   constants.VALID_STORAGE_TYPES == set([constants.ST_FILE,
1284
                                         constants.ST_LVM_PV,
1285
                                         constants.ST_LVM_VG])
1286

    
1287
Requests a list of storage units on a node. Requires the parameters
1288
``storage_type`` (one of :pyeval:`constants.ST_FILE`,
1289
:pyeval:`constants.ST_LVM_PV` or :pyeval:`constants.ST_LVM_VG`) and
1290
``output_fields``. The result will be a job id, using which the result
1291
can be retrieved.
1292

    
1293
``/2/nodes/[node_name]/storage/modify``
1294
+++++++++++++++++++++++++++++++++++++++
1295

    
1296
Modifies storage units on the node.
1297

    
1298
``PUT``
1299
~~~~~~~
1300

    
1301
Modifies parameters of storage units on the node. Requires the
1302
parameters ``storage_type`` (one of :pyeval:`constants.ST_FILE`,
1303
:pyeval:`constants.ST_LVM_PV` or :pyeval:`constants.ST_LVM_VG`)
1304
and ``name`` (name of the storage unit).  Parameters can be passed
1305
additionally. Currently only :pyeval:`constants.SF_ALLOCATABLE` (bool)
1306
is supported. The result will be a job id.
1307

    
1308
``/2/nodes/[node_name]/storage/repair``
1309
+++++++++++++++++++++++++++++++++++++++
1310

    
1311
Repairs a storage unit on the node.
1312

    
1313
``PUT``
1314
~~~~~~~
1315

    
1316
.. pyassert::
1317

    
1318
   constants.VALID_STORAGE_OPERATIONS == {
1319
    constants.ST_LVM_VG: set([constants.SO_FIX_CONSISTENCY]),
1320
    }
1321

    
1322
Repairs a storage unit on the node. Requires the parameters
1323
``storage_type`` (currently only :pyeval:`constants.ST_LVM_VG` can be
1324
repaired) and ``name`` (name of the storage unit). The result will be a
1325
job id.
1326

    
1327
``/2/nodes/[node_name]/tags``
1328
+++++++++++++++++++++++++++++
1329

    
1330
Manages per-node tags.
1331

    
1332
It supports the following commands: ``GET``, ``PUT``, ``DELETE``.
1333

    
1334
``GET``
1335
~~~~~~~
1336

    
1337
Returns a list of tags.
1338

    
1339
Example::
1340

    
1341
    ["tag1", "tag2", "tag3"]
1342

    
1343
``PUT``
1344
~~~~~~~
1345

    
1346
Add a set of tags.
1347

    
1348
The request as a list of strings should be PUT to this URI. The result
1349
will be a job id.
1350

    
1351
It supports the ``dry-run`` argument.
1352

    
1353
``DELETE``
1354
~~~~~~~~~~
1355

    
1356
Deletes tags.
1357

    
1358
In order to delete a set of tags, the DELETE request should be addressed
1359
to URI like::
1360

    
1361
    /tags?tag=[tag]&tag=[tag]
1362

    
1363
It supports the ``dry-run`` argument.
1364

    
1365

    
1366
``/2/query/[resource]``
1367
+++++++++++++++++++++++
1368

    
1369
Requests resource information. Available fields can be found in man
1370
pages and using ``/2/query/[resource]/fields``. The resource is one of
1371
:pyeval:`utils.CommaJoin(constants.QR_VIA_RAPI)`. See the :doc:`query2
1372
design document <design-query2>` for more details.
1373

    
1374
Supports the following commands: ``GET``, ``PUT``.
1375

    
1376
``GET``
1377
~~~~~~~
1378

    
1379
Returns list of included fields and actual data. Takes a query parameter
1380
named "fields", containing a comma-separated list of field names. Does
1381
not support filtering.
1382

    
1383
``PUT``
1384
~~~~~~~
1385

    
1386
Returns list of included fields and actual data. The list of requested
1387
fields can either be given as the query parameter "fields" or as a body
1388
parameter with the same name. The optional body parameter "filter" can
1389
be given and must be either ``null`` or a list containing filter
1390
operators.
1391

    
1392

    
1393
``/2/query/[resource]/fields``
1394
++++++++++++++++++++++++++++++
1395

    
1396
Request list of available fields for a resource. The resource is one of
1397
:pyeval:`utils.CommaJoin(constants.QR_VIA_RAPI)`. See the
1398
:doc:`query2 design document <design-query2>` for more details.
1399

    
1400
Supports the following commands: ``GET``.
1401

    
1402
``GET``
1403
~~~~~~~
1404

    
1405
Returns a list of field descriptions for available fields. Takes an
1406
optional query parameter named "fields", containing a comma-separated
1407
list of field names.
1408

    
1409

    
1410
``/2/os``
1411
+++++++++
1412

    
1413
OS resource.
1414

    
1415
It supports the following commands: ``GET``.
1416

    
1417
``GET``
1418
~~~~~~~
1419

    
1420
Return a list of all OSes.
1421

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

    
1425
Example::
1426

    
1427
    ["debian-etch"]
1428

    
1429
``/2/tags``
1430
+++++++++++
1431

    
1432
Manages cluster tags.
1433

    
1434
It supports the following commands: ``GET``, ``PUT``, ``DELETE``.
1435

    
1436
``GET``
1437
~~~~~~~
1438

    
1439
Returns the cluster tags.
1440

    
1441
Example::
1442

    
1443
    ["tag1", "tag2", "tag3"]
1444

    
1445
``PUT``
1446
~~~~~~~
1447

    
1448
Adds a set of tags.
1449

    
1450
The request as a list of strings should be PUT to this URI. The result
1451
will be a job id.
1452

    
1453
It supports the ``dry-run`` argument.
1454

    
1455

    
1456
``DELETE``
1457
~~~~~~~~~~
1458

    
1459
Deletes tags.
1460

    
1461
In order to delete a set of tags, the DELETE request should be addressed
1462
to URI like::
1463

    
1464
    /tags?tag=[tag]&tag=[tag]
1465

    
1466
It supports the ``dry-run`` argument.
1467

    
1468

    
1469
``/version``
1470
++++++++++++
1471

    
1472
The version resource.
1473

    
1474
This resource should be used to determine the remote API version and to
1475
adapt clients accordingly.
1476

    
1477
It supports the following commands: ``GET``.
1478

    
1479
``GET``
1480
~~~~~~~
1481

    
1482
Returns the remote API version. Ganeti 1.2 returned ``1`` and Ganeti 2.0
1483
returns ``2``.
1484

    
1485
.. vim: set textwidth=72 :
1486
.. Local Variables:
1487
.. mode: rst
1488
.. fill-column: 72
1489
.. End: