Statistics
| Branch: | Tag: | Revision:

root / doc / rapi.rst @ 0f945c65

History | View | Annotate | Download (33.4 kB)

1
Ganeti remote API
2
=================
3

    
4
Documents Ganeti version |version|
5

    
6
.. contents::
7

    
8
Introduction
9
------------
10

    
11
Ganeti supports a remote API for enable external tools to easily
12
retrieve information about a cluster's state. The remote API daemon,
13
*ganeti-rapi*, is automatically started on the master node. By default
14
it runs on TCP port 5080, but this can be changed either in
15
``.../constants.py`` or via the command line parameter *-p*. SSL mode,
16
which is used by default, can also be disabled by passing command line
17
parameters.
18

    
19

    
20
Users and passwords
21
-------------------
22

    
23
``ganeti-rapi`` reads users and passwords from a file (usually
24
``/var/lib/ganeti/rapi/users``) on startup. Changes to the file will be
25
read automatically.
26

    
27
Each line consists of two or three fields separated by whitespace. The
28
first two fields are for username and password. The third field is
29
optional and can be used to specify per-user options. Currently,
30
``write`` is the only option supported and enables the user to execute
31
operations modifying the cluster. Lines starting with the hash sign
32
(``#``) are treated as comments.
33

    
34
Passwords can either be written in clear text or as a hash. Clear text
35
passwords may not start with an opening brace (``{``) or they must be
36
prefixed with ``{cleartext}``. To use the hashed form, get the MD5 hash
37
of the string ``$username:Ganeti Remote API:$password`` (e.g. ``echo -n
38
'jack:Ganeti Remote API:abc123' | openssl md5``) [#pwhash]_ and prefix
39
it with ``{ha1}``. Using the scheme prefix for all passwords is
40
recommended. Scheme prefixes are not case sensitive.
41

    
42
Example::
43

    
44
  # Give Jack and Fred read-only access
45
  jack abc123
46
  fred {cleartext}foo555
47

    
48
  # Give write access to an imaginary instance creation script
49
  autocreator xyz789 write
50

    
51
  # Hashed password for Jessica
52
  jessica {HA1}7046452df2cbb530877058712cf17bd4 write
53

    
54

    
55
.. [#pwhash] Using the MD5 hash of username, realm and password is
56
   described in :rfc:`2617` ("HTTP Authentication"), sections 3.2.2.2
57
   and 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. Has no function, but for legacy reasons the ``GET``
243
method is supported.
244

    
245
``/2/info``
246
+++++++++++
247

    
248
Cluster information resource.
249

    
250
It supports the following commands: ``GET``.
251

    
252
``GET``
253
~~~~~~~
254

    
255
Returns cluster information.
256

    
257
Example::
258

    
259
  {
260
    "config_version": 2000000,
261
    "name": "cluster",
262
    "software_version": "2.0.0~beta2",
263
    "os_api_version": 10,
264
    "export_version": 0,
265
    "candidate_pool_size": 10,
266
    "enabled_hypervisors": [
267
      "fake"
268
    ],
269
    "hvparams": {
270
      "fake": {}
271
     },
272
    "default_hypervisor": "fake",
273
    "master": "node1.example.com",
274
    "architecture": [
275
      "64bit",
276
      "x86_64"
277
    ],
278
    "protocol_version": 20,
279
    "beparams": {
280
      "default": {
281
        "auto_balance": true,
282
        "vcpus": 1,
283
        "memory": 128
284
       }
285
      }
286
    }
287

    
288

    
289
``/2/redistribute-config``
290
++++++++++++++++++++++++++
291

    
292
Redistribute configuration to all nodes.
293

    
294
It supports the following commands: ``PUT``.
295

    
296
``PUT``
297
~~~~~~~
298

    
299
Redistribute configuration to all nodes. The result will be a job id.
300

    
301

    
302
``/2/features``
303
+++++++++++++++
304

    
305
``GET``
306
~~~~~~~
307

    
308
Returns a list of features supported by the RAPI server. Available
309
features:
310

    
311
.. pyassert::
312

    
313
  rlib2.ALL_FEATURES == set([rlib2._INST_CREATE_REQV1,
314
                             rlib2._INST_REINSTALL_REQV1,
315
                             rlib2._NODE_MIGRATE_REQV1,
316
                             rlib2._NODE_EVAC_RES1])
317

    
318
:pyeval:`rlib2._INST_CREATE_REQV1`
319
  Instance creation request data version 1 supported.
320
:pyeval:`rlib2._INST_REINSTALL_REQV1`
321
  Instance reinstall supports body parameters.
322
:pyeval:`rlib2._NODE_MIGRATE_REQV1`
323
  Whether migrating a node (``/2/nodes/[node_name]/migrate``) supports
324
  request body parameters.
325
:pyeval:`rlib2._NODE_EVAC_RES1`
326
  Whether evacuating a node (``/2/nodes/[node_name]/evacuate``) returns
327
  a new-style result (see resource description)
328

    
329

    
330
``/2/modify``
331
++++++++++++++++++++++++++++++++++++++++
332

    
333
Modifies cluster parameters.
334

    
335
Supports the following commands: ``PUT``.
336

    
337
``PUT``
338
~~~~~~~
339

    
340
Returns a job ID.
341

    
342
Body parameters:
343

    
344
.. opcode_params:: OP_CLUSTER_SET_PARAMS
345

    
346

    
347
``/2/groups``
348
+++++++++++++
349

    
350
The groups resource.
351

    
352
It supports the following commands: ``GET``, ``POST``.
353

    
354
``GET``
355
~~~~~~~
356

    
357
Returns a list of all existing node groups.
358

    
359
Example::
360

    
361
    [
362
      {
363
        "name": "group1",
364
        "uri": "\/2\/groups\/group1"
365
      },
366
      {
367
        "name": "group2",
368
        "uri": "\/2\/groups\/group2"
369
      }
370
    ]
371

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

    
376
Returned fields: :pyeval:`utils.CommaJoin(sorted(rlib2.G_FIELDS))`
377

    
378
Example::
379

    
380
    [
381
      {
382
        "name": "group1",
383
        "node_cnt": 2,
384
        "node_list": [
385
          "node1.example.com",
386
          "node2.example.com"
387
        ],
388
        "uuid": "0d7d407c-262e-49af-881a-6a430034bf43"
389
      },
390
      {
391
        "name": "group2",
392
        "node_cnt": 1,
393
        "node_list": [
394
          "node3.example.com"
395
        ],
396
        "uuid": "f5a277e7-68f9-44d3-a378-4b25ecb5df5c"
397
      }
398
    ]
399

    
400
``POST``
401
~~~~~~~~
402

    
403
Creates a node group.
404

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

    
408
Returns: a job ID that can be used later for polling.
409

    
410
Body parameters:
411

    
412
.. opcode_params:: OP_GROUP_ADD
413

    
414
Earlier versions used a parameter named ``name`` which, while still
415
supported, has been renamed to ``group_name``.
416

    
417

    
418
``/2/groups/[group_name]``
419
++++++++++++++++++++++++++
420

    
421
Returns information about a node group.
422

    
423
It supports the following commands: ``GET``, ``DELETE``.
424

    
425
``GET``
426
~~~~~~~
427

    
428
Returns information about a node group, similar to the bulk output from
429
the node group list.
430

    
431
Returned fields: :pyeval:`utils.CommaJoin(sorted(rlib2.G_FIELDS))`
432

    
433
``DELETE``
434
~~~~~~~~~~
435

    
436
Deletes a node group.
437

    
438
It supports the ``dry-run`` argument.
439

    
440

    
441
``/2/groups/[group_name]/modify``
442
+++++++++++++++++++++++++++++++++
443

    
444
Modifies the parameters of a node group.
445

    
446
Supports the following commands: ``PUT``.
447

    
448
``PUT``
449
~~~~~~~
450

    
451
Returns a job ID.
452

    
453
Body parameters:
454

    
455
.. opcode_params:: OP_GROUP_SET_PARAMS
456
   :exclude: group_name
457

    
458
Job result:
459

    
460
.. opcode_result:: OP_GROUP_SET_PARAMS
461

    
462

    
463
``/2/groups/[group_name]/rename``
464
+++++++++++++++++++++++++++++++++
465

    
466
Renames a node group.
467

    
468
Supports the following commands: ``PUT``.
469

    
470
``PUT``
471
~~~~~~~
472

    
473
Returns a job ID.
474

    
475
Body parameters:
476

    
477
.. opcode_params:: OP_GROUP_RENAME
478
   :exclude: group_name
479

    
480
Job result:
481

    
482
.. opcode_result:: OP_GROUP_RENAME
483

    
484

    
485
``/2/groups/[group_name]/assign-nodes``
486
+++++++++++++++++++++++++++++++++++++++
487

    
488
Assigns nodes to a group.
489

    
490
Supports the following commands: ``PUT``.
491

    
492
``PUT``
493
~~~~~~~
494

    
495
Returns a job ID. It supports the ``dry-run`` and ``force`` arguments.
496

    
497
Body parameters:
498

    
499
.. opcode_params:: OP_GROUP_ASSIGN_NODES
500
   :exclude: group_name, force, dry_run
501

    
502

    
503
``/2/groups/[group_name]/tags``
504
+++++++++++++++++++++++++++++++
505

    
506
Manages per-nodegroup tags.
507

    
508
Supports the following commands: ``GET``, ``PUT``, ``DELETE``.
509

    
510
``GET``
511
~~~~~~~
512

    
513
Returns a list of tags.
514

    
515
Example::
516

    
517
    ["tag1", "tag2", "tag3"]
518

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

    
522
Add a set of tags.
523

    
524
The request as a list of strings should be ``PUT`` to this URI. The
525
result will be a job id.
526

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

    
529

    
530
``DELETE``
531
~~~~~~~~~~
532

    
533
Delete a tag.
534

    
535
In order to delete a set of tags, the DELETE request should be addressed
536
to URI like::
537

    
538
    /tags?tag=[tag]&tag=[tag]
539

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

    
542

    
543
``/2/instances``
544
++++++++++++++++
545

    
546
The instances resource.
547

    
548
It supports the following commands: ``GET``, ``POST``.
549

    
550
``GET``
551
~~~~~~~
552

    
553
Returns a list of all available instances.
554

    
555
Example::
556

    
557
    [
558
      {
559
        "name": "web.example.com",
560
        "uri": "\/instances\/web.example.com"
561
      },
562
      {
563
        "name": "mail.example.com",
564
        "uri": "\/instances\/mail.example.com"
565
      }
566
    ]
567

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

    
572
Returned fields: :pyeval:`utils.CommaJoin(sorted(rlib2.I_FIELDS))`
573

    
574
Example::
575

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

    
603

    
604
``POST``
605
~~~~~~~~
606

    
607
Creates an instance.
608

    
609
If the optional bool *dry-run* argument is provided, the job will not be
610
actually executed, only the pre-execution checks will be done. Query-ing
611
the job result will return, in both dry-run and normal case, the list of
612
nodes selected for the instance.
613

    
614
Returns: a job ID that can be used later for polling.
615

    
616
Body parameters:
617

    
618
``__version__`` (int, required)
619
  Must be ``1`` (older Ganeti versions used a different format for
620
  instance creation requests, version ``0``, but that format is no
621
  longer supported)
622

    
623
.. opcode_params:: OP_INSTANCE_CREATE
624

    
625
Earlier versions used parameters named ``name`` and ``os``. These have
626
been replaced by ``instance_name`` and ``os_type`` to match the
627
underlying opcode. The old names can still be used.
628

    
629
Job result:
630

    
631
.. opcode_result:: OP_INSTANCE_CREATE
632

    
633

    
634
``/2/instances/[instance_name]``
635
++++++++++++++++++++++++++++++++
636

    
637
Instance-specific resource.
638

    
639
It supports the following commands: ``GET``, ``DELETE``.
640

    
641
``GET``
642
~~~~~~~
643

    
644
Returns information about an instance, similar to the bulk output from
645
the instance list.
646

    
647
Returned fields: :pyeval:`utils.CommaJoin(sorted(rlib2.I_FIELDS))`
648

    
649
``DELETE``
650
~~~~~~~~~~
651

    
652
Deletes an instance.
653

    
654
It supports the ``dry-run`` argument.
655

    
656

    
657
``/2/instances/[instance_name]/info``
658
+++++++++++++++++++++++++++++++++++++++
659

    
660
It supports the following commands: ``GET``.
661

    
662
``GET``
663
~~~~~~~
664

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

    
670

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

    
674
Reboots URI for an instance.
675

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

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

    
681
Reboots the instance.
682

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

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

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

    
696
It supports the ``dry-run`` argument.
697

    
698

    
699
``/2/instances/[instance_name]/shutdown``
700
+++++++++++++++++++++++++++++++++++++++++
701

    
702
Instance shutdown URI.
703

    
704
It supports the following commands: ``PUT``.
705

    
706
``PUT``
707
~~~~~~~
708

    
709
Shutdowns an instance.
710

    
711
It supports the ``dry-run`` argument.
712

    
713
.. opcode_params:: OP_INSTANCE_SHUTDOWN
714
   :exclude: instance_name, dry_run
715

    
716

    
717
``/2/instances/[instance_name]/startup``
718
++++++++++++++++++++++++++++++++++++++++
719

    
720
Instance startup URI.
721

    
722
It supports the following commands: ``PUT``.
723

    
724
``PUT``
725
~~~~~~~
726

    
727
Startup an instance.
728

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

    
732
It supports the ``dry-run`` argument.
733

    
734
``/2/instances/[instance_name]/reinstall``
735
++++++++++++++++++++++++++++++++++++++++++++++
736

    
737
Installs the operating system again.
738

    
739
It supports the following commands: ``POST``.
740

    
741
``POST``
742
~~~~~~~~
743

    
744
Returns a job ID.
745

    
746
Body parameters:
747

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

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

    
759

    
760
``/2/instances/[instance_name]/replace-disks``
761
++++++++++++++++++++++++++++++++++++++++++++++
762

    
763
Replaces disks on an instance.
764

    
765
It supports the following commands: ``POST``.
766

    
767
``POST``
768
~~~~~~~~
769

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

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

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

    
781

    
782
``/2/instances/[instance_name]/activate-disks``
783
+++++++++++++++++++++++++++++++++++++++++++++++
784

    
785
Activate disks on an instance.
786

    
787
It supports the following commands: ``PUT``.
788

    
789
``PUT``
790
~~~~~~~
791

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

    
795

    
796
``/2/instances/[instance_name]/deactivate-disks``
797
+++++++++++++++++++++++++++++++++++++++++++++++++
798

    
799
Deactivate disks on an instance.
800

    
801
It supports the following commands: ``PUT``.
802

    
803
``PUT``
804
~~~~~~~
805

    
806
Takes no parameters.
807

    
808

    
809
``/2/instances/[instance_name]/disk/[disk_index]/grow``
810
+++++++++++++++++++++++++++++++++++++++++++++++++++++++
811

    
812
Grows one disk of an instance.
813

    
814
Supports the following commands: ``POST``.
815

    
816
``POST``
817
~~~~~~~~
818

    
819
Returns a job ID.
820

    
821
Body parameters:
822

    
823
.. opcode_params:: OP_INSTANCE_GROW_DISK
824
   :exclude: instance_name, disk
825

    
826

    
827
``/2/instances/[instance_name]/prepare-export``
828
+++++++++++++++++++++++++++++++++++++++++++++++++
829

    
830
Prepares an export of an instance.
831

    
832
It supports the following commands: ``PUT``.
833

    
834
``PUT``
835
~~~~~~~
836

    
837
Takes one parameter, ``mode``, for the export mode. Returns a job ID.
838

    
839

    
840
``/2/instances/[instance_name]/export``
841
+++++++++++++++++++++++++++++++++++++++++++++++++
842

    
843
Exports an instance.
844

    
845
It supports the following commands: ``PUT``.
846

    
847
``PUT``
848
~~~~~~~
849

    
850
Returns a job ID.
851

    
852
Body parameters:
853

    
854
.. opcode_params:: OP_BACKUP_EXPORT
855
   :exclude: instance_name
856
   :alias: target_node=destination
857

    
858

    
859
``/2/instances/[instance_name]/migrate``
860
++++++++++++++++++++++++++++++++++++++++
861

    
862
Migrates an instance.
863

    
864
Supports the following commands: ``PUT``.
865

    
866
``PUT``
867
~~~~~~~
868

    
869
Returns a job ID.
870

    
871
Body parameters:
872

    
873
.. opcode_params:: OP_INSTANCE_MIGRATE
874
   :exclude: instance_name, live
875

    
876

    
877
``/2/instances/[instance_name]/failover``
878
+++++++++++++++++++++++++++++++++++++++++
879

    
880
Does a failover of an instance.
881

    
882
Supports the following commands: ``PUT``.
883

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

    
887
Returns a job ID.
888

    
889
Body parameters:
890

    
891
.. opcode_params:: OP_INSTANCE_FAILOVER
892
   :exclude: instance_name
893

    
894

    
895
``/2/instances/[instance_name]/rename``
896
++++++++++++++++++++++++++++++++++++++++
897

    
898
Renames an instance.
899

    
900
Supports the following commands: ``PUT``.
901

    
902
``PUT``
903
~~~~~~~
904

    
905
Returns a job ID.
906

    
907
Body parameters:
908

    
909
.. opcode_params:: OP_INSTANCE_RENAME
910
   :exclude: instance_name
911

    
912
Job result:
913

    
914
.. opcode_result:: OP_INSTANCE_RENAME
915

    
916

    
917
``/2/instances/[instance_name]/modify``
918
++++++++++++++++++++++++++++++++++++++++
919

    
920
Modifies an instance.
921

    
922
Supports the following commands: ``PUT``.
923

    
924
``PUT``
925
~~~~~~~
926

    
927
Returns a job ID.
928

    
929
Body parameters:
930

    
931
.. opcode_params:: OP_INSTANCE_SET_PARAMS
932
   :exclude: instance_name
933

    
934
Job result:
935

    
936
.. opcode_result:: OP_INSTANCE_SET_PARAMS
937

    
938

    
939
``/2/instances/[instance_name]/console``
940
++++++++++++++++++++++++++++++++++++++++
941

    
942
Request information for connecting to instance's console.
943

    
944
Supports the following commands: ``GET``.
945

    
946
``GET``
947
~~~~~~~
948

    
949
Returns a dictionary containing information about the instance's
950
console. Contained keys:
951

    
952
.. pyassert::
953

    
954
   constants.CONS_ALL == frozenset([
955
     constants.CONS_MESSAGE,
956
     constants.CONS_SSH,
957
     constants.CONS_VNC,
958
     ])
959

    
960
``instance``
961
  Instance name.
962
``kind``
963
  Console type, one of :pyeval:`constants.CONS_SSH`,
964
  :pyeval:`constants.CONS_VNC` or :pyeval:`constants.CONS_MESSAGE`.
965
``message``
966
  Message to display (:pyeval:`constants.CONS_MESSAGE` type only).
967
``host``
968
  Host to connect to (:pyeval:`constants.CONS_SSH` and
969
  :pyeval:`constants.CONS_VNC` only).
970
``port``
971
  TCP port to connect to (:pyeval:`constants.CONS_VNC` only).
972
``user``
973
  Username to use (:pyeval:`constants.CONS_SSH` only).
974
``command``
975
  Command to execute on machine (:pyeval:`constants.CONS_SSH` only)
976
``display``
977
  VNC display number (:pyeval:`constants.CONS_VNC` only).
978

    
979

    
980
``/2/instances/[instance_name]/tags``
981
+++++++++++++++++++++++++++++++++++++
982

    
983
Manages per-instance tags.
984

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

    
987
``GET``
988
~~~~~~~
989

    
990
Returns a list of tags.
991

    
992
Example::
993

    
994
    ["tag1", "tag2", "tag3"]
995

    
996
``PUT``
997
~~~~~~~
998

    
999
Add a set of tags.
1000

    
1001
The request as a list of strings should be ``PUT`` to this URI. The
1002
result will be a job id.
1003

    
1004
It supports the ``dry-run`` argument.
1005

    
1006

    
1007
``DELETE``
1008
~~~~~~~~~~
1009

    
1010
Delete a tag.
1011

    
1012
In order to delete a set of tags, the DELETE request should be addressed
1013
to URI like::
1014

    
1015
    /tags?tag=[tag]&tag=[tag]
1016

    
1017
It supports the ``dry-run`` argument.
1018

    
1019

    
1020
``/2/jobs``
1021
+++++++++++
1022

    
1023
The ``/2/jobs`` resource.
1024

    
1025
It supports the following commands: ``GET``.
1026

    
1027
``GET``
1028
~~~~~~~
1029

    
1030
Returns a dictionary of jobs.
1031

    
1032
Returns: a dictionary with jobs id and uri.
1033

    
1034
If the optional bool *bulk* argument is provided and set to a true value
1035
(i.e. ``?bulk=1``), the output contains detailed information about jobs
1036
as a list.
1037

    
1038
Returned fields for bulk requests (unlike other bulk requests, these
1039
fields are not the same as for per-job requests):
1040
:pyeval:`utils.CommaJoin(sorted(rlib2.J_FIELDS_BULK))`
1041

    
1042
``/2/jobs/[job_id]``
1043
++++++++++++++++++++
1044

    
1045

    
1046
Individual job URI.
1047

    
1048
It supports the following commands: ``GET``, ``DELETE``.
1049

    
1050
``GET``
1051
~~~~~~~
1052

    
1053
Returns a dictionary with job parameters, containing the fields
1054
:pyeval:`utils.CommaJoin(sorted(rlib2.J_FIELDS))`.
1055

    
1056
The result includes:
1057

    
1058
- id: job ID as a number
1059
- status: current job status as a string
1060
- ops: involved OpCodes as a list of dictionaries for each opcodes in
1061
  the job
1062
- opstatus: OpCodes status as a list
1063
- opresult: OpCodes results as a list
1064

    
1065
For a successful opcode, the ``opresult`` field corresponding to it will
1066
contain the raw result from its :term:`LogicalUnit`. In case an opcode
1067
has failed, its element in the opresult list will be a list of two
1068
elements:
1069

    
1070
- first element the error type (the Ganeti internal error name)
1071
- second element a list of either one or two elements:
1072

    
1073
  - the first element is the textual error description
1074
  - the second element, if any, will hold an error classification
1075

    
1076
The error classification is most useful for the ``OpPrereqError``
1077
error type - these errors happen before the OpCode has started
1078
executing, so it's possible to retry the OpCode without side
1079
effects. But whether it make sense to retry depends on the error
1080
classification:
1081

    
1082
.. pyassert::
1083

    
1084
   errors.ECODE_ALL == set([errors.ECODE_RESOLVER, errors.ECODE_NORES,
1085
     errors.ECODE_INVAL, errors.ECODE_STATE, errors.ECODE_NOENT,
1086
     errors.ECODE_EXISTS, errors.ECODE_NOTUNIQUE, errors.ECODE_FAULT,
1087
     errors.ECODE_ENVIRON])
1088

    
1089
:pyeval:`errors.ECODE_RESOLVER`
1090
  Resolver errors. This usually means that a name doesn't exist in DNS,
1091
  so if it's a case of slow DNS propagation the operation can be retried
1092
  later.
1093

    
1094
:pyeval:`errors.ECODE_NORES`
1095
  Not enough resources (iallocator failure, disk space, memory,
1096
  etc.). If the resources on the cluster increase, the operation might
1097
  succeed.
1098

    
1099
:pyeval:`errors.ECODE_INVAL`
1100
  Wrong arguments (at syntax level). The operation will not ever be
1101
  accepted unless the arguments change.
1102

    
1103
:pyeval:`errors.ECODE_STATE`
1104
  Wrong entity state. For example, live migration has been requested for
1105
  a down instance, or instance creation on an offline node. The
1106
  operation can be retried once the resource has changed state.
1107

    
1108
:pyeval:`errors.ECODE_NOENT`
1109
  Entity not found. For example, information has been requested for an
1110
  unknown instance.
1111

    
1112
:pyeval:`errors.ECODE_EXISTS`
1113
  Entity already exists. For example, instance creation has been
1114
  requested for an already-existing instance.
1115

    
1116
:pyeval:`errors.ECODE_NOTUNIQUE`
1117
  Resource not unique (e.g. MAC or IP duplication).
1118

    
1119
:pyeval:`errors.ECODE_FAULT`
1120
  Internal cluster error. For example, a node is unreachable but not set
1121
  offline, or the ganeti node daemons are not working, etc. A
1122
  ``gnt-cluster verify`` should be run.
1123

    
1124
:pyeval:`errors.ECODE_ENVIRON`
1125
  Environment error (e.g. node disk error). A ``gnt-cluster verify``
1126
  should be run.
1127

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

    
1131

    
1132
``DELETE``
1133
~~~~~~~~~~
1134

    
1135
Cancel a not-yet-started job.
1136

    
1137

    
1138
``/2/jobs/[job_id]/wait``
1139
+++++++++++++++++++++++++
1140

    
1141
``GET``
1142
~~~~~~~
1143

    
1144
Waits for changes on a job. Takes the following body parameters in a
1145
dict:
1146

    
1147
``fields``
1148
  The job fields on which to watch for changes.
1149

    
1150
``previous_job_info``
1151
  Previously received field values or None if not yet available.
1152

    
1153
``previous_log_serial``
1154
  Highest log serial number received so far or None if not yet
1155
  available.
1156

    
1157
Returns None if no changes have been detected and a dict with two keys,
1158
``job_info`` and ``log_entries`` otherwise.
1159

    
1160

    
1161
``/2/nodes``
1162
++++++++++++
1163

    
1164
Nodes resource.
1165

    
1166
It supports the following commands: ``GET``.
1167

    
1168
``GET``
1169
~~~~~~~
1170

    
1171
Returns a list of all nodes.
1172

    
1173
Example::
1174

    
1175
    [
1176
      {
1177
        "id": "node1.example.com",
1178
        "uri": "\/nodes\/node1.example.com"
1179
      },
1180
      {
1181
        "id": "node2.example.com",
1182
        "uri": "\/nodes\/node2.example.com"
1183
      }
1184
    ]
1185

    
1186
If the optional bool *bulk* argument is provided and set to a true value
1187
(i.e ``?bulk=1``), the output contains detailed information about nodes
1188
as a list.
1189

    
1190
Returned fields: :pyeval:`utils.CommaJoin(sorted(rlib2.N_FIELDS))`
1191

    
1192
Example::
1193

    
1194
    [
1195
      {
1196
        "pinst_cnt": 1,
1197
        "mfree": 31280,
1198
        "mtotal": 32763,
1199
        "name": "www.example.com",
1200
        "tags": [],
1201
        "mnode": 512,
1202
        "dtotal": 5246208,
1203
        "sinst_cnt": 2,
1204
        "dfree": 5171712,
1205
        "offline": false
1206
      },
1207
      ...
1208
    ]
1209

    
1210
``/2/nodes/[node_name]``
1211
+++++++++++++++++++++++++++++++++
1212

    
1213
Returns information about a node.
1214

    
1215
It supports the following commands: ``GET``.
1216

    
1217
Returned fields: :pyeval:`utils.CommaJoin(sorted(rlib2.N_FIELDS))`
1218

    
1219
``/2/nodes/[node_name]/evacuate``
1220
+++++++++++++++++++++++++++++++++
1221

    
1222
Evacuates instances off a node.
1223

    
1224
It supports the following commands: ``POST``.
1225

    
1226
``POST``
1227
~~~~~~~~
1228

    
1229
Returns a job ID. The result of the job will contain the IDs of the
1230
individual jobs submitted to evacuate the node.
1231

    
1232
Body parameters:
1233

    
1234
.. opcode_params:: OP_NODE_EVACUATE
1235
   :exclude: nodes
1236

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

    
1241
Job result:
1242

    
1243
.. opcode_result:: OP_NODE_EVACUATE
1244

    
1245

    
1246
``/2/nodes/[node_name]/migrate``
1247
+++++++++++++++++++++++++++++++++
1248

    
1249
Migrates all primary instances from a node.
1250

    
1251
It supports the following commands: ``POST``.
1252

    
1253
``POST``
1254
~~~~~~~~
1255

    
1256
If no mode is explicitly specified, each instances' hypervisor default
1257
migration mode will be used. Body parameters:
1258

    
1259
.. opcode_params:: OP_NODE_MIGRATE
1260
   :exclude: node_name
1261

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

    
1266

    
1267
``/2/nodes/[node_name]/role``
1268
+++++++++++++++++++++++++++++
1269

    
1270
Manages node role.
1271

    
1272
It supports the following commands: ``GET``, ``PUT``.
1273

    
1274
The role is always one of the following:
1275

    
1276
  - drained
1277
  - master-candidate
1278
  - offline
1279
  - regular
1280

    
1281
Note that the 'master' role is a special, and currently it can't be
1282
modified via RAPI, only via the command line (``gnt-cluster
1283
master-failover``).
1284

    
1285
``GET``
1286
~~~~~~~
1287

    
1288
Returns the current node role.
1289

    
1290
Example::
1291

    
1292
    "master-candidate"
1293

    
1294
``PUT``
1295
~~~~~~~
1296

    
1297
Change the node role.
1298

    
1299
The request is a string which should be PUT to this URI. The result will
1300
be a job id.
1301

    
1302
It supports the bool ``force`` argument.
1303

    
1304
``/2/nodes/[node_name]/storage``
1305
++++++++++++++++++++++++++++++++
1306

    
1307
Manages storage units on the node.
1308

    
1309
``GET``
1310
~~~~~~~
1311

    
1312
.. pyassert::
1313

    
1314
   constants.VALID_STORAGE_TYPES == set([constants.ST_FILE,
1315
                                         constants.ST_LVM_PV,
1316
                                         constants.ST_LVM_VG])
1317

    
1318
Requests a list of storage units on a node. Requires the parameters
1319
``storage_type`` (one of :pyeval:`constants.ST_FILE`,
1320
:pyeval:`constants.ST_LVM_PV` or :pyeval:`constants.ST_LVM_VG`) and
1321
``output_fields``. The result will be a job id, using which the result
1322
can be retrieved.
1323

    
1324
``/2/nodes/[node_name]/storage/modify``
1325
+++++++++++++++++++++++++++++++++++++++
1326

    
1327
Modifies storage units on the node.
1328

    
1329
``PUT``
1330
~~~~~~~
1331

    
1332
Modifies parameters of storage units on the node. Requires the
1333
parameters ``storage_type`` (one of :pyeval:`constants.ST_FILE`,
1334
:pyeval:`constants.ST_LVM_PV` or :pyeval:`constants.ST_LVM_VG`)
1335
and ``name`` (name of the storage unit).  Parameters can be passed
1336
additionally. Currently only :pyeval:`constants.SF_ALLOCATABLE` (bool)
1337
is supported. The result will be a job id.
1338

    
1339
``/2/nodes/[node_name]/storage/repair``
1340
+++++++++++++++++++++++++++++++++++++++
1341

    
1342
Repairs a storage unit on the node.
1343

    
1344
``PUT``
1345
~~~~~~~
1346

    
1347
.. pyassert::
1348

    
1349
   constants.VALID_STORAGE_OPERATIONS == {
1350
    constants.ST_LVM_VG: set([constants.SO_FIX_CONSISTENCY]),
1351
    }
1352

    
1353
Repairs a storage unit on the node. Requires the parameters
1354
``storage_type`` (currently only :pyeval:`constants.ST_LVM_VG` can be
1355
repaired) and ``name`` (name of the storage unit). The result will be a
1356
job id.
1357

    
1358
``/2/nodes/[node_name]/tags``
1359
+++++++++++++++++++++++++++++
1360

    
1361
Manages per-node tags.
1362

    
1363
It supports the following commands: ``GET``, ``PUT``, ``DELETE``.
1364

    
1365
``GET``
1366
~~~~~~~
1367

    
1368
Returns a list of tags.
1369

    
1370
Example::
1371

    
1372
    ["tag1", "tag2", "tag3"]
1373

    
1374
``PUT``
1375
~~~~~~~
1376

    
1377
Add a set of tags.
1378

    
1379
The request as a list of strings should be PUT to this URI. The result
1380
will be a job id.
1381

    
1382
It supports the ``dry-run`` argument.
1383

    
1384
``DELETE``
1385
~~~~~~~~~~
1386

    
1387
Deletes tags.
1388

    
1389
In order to delete a set of tags, the DELETE request should be addressed
1390
to URI like::
1391

    
1392
    /tags?tag=[tag]&tag=[tag]
1393

    
1394
It supports the ``dry-run`` argument.
1395

    
1396

    
1397
``/2/query/[resource]``
1398
+++++++++++++++++++++++
1399

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

    
1405
Supports the following commands: ``GET``, ``PUT``.
1406

    
1407
``GET``
1408
~~~~~~~
1409

    
1410
Returns list of included fields and actual data. Takes a query parameter
1411
named "fields", containing a comma-separated list of field names. Does
1412
not support filtering.
1413

    
1414
``PUT``
1415
~~~~~~~
1416

    
1417
Returns list of included fields and actual data. The list of requested
1418
fields can either be given as the query parameter "fields" or as a body
1419
parameter with the same name. The optional body parameter "filter" can
1420
be given and must be either ``null`` or a list containing filter
1421
operators.
1422

    
1423

    
1424
``/2/query/[resource]/fields``
1425
++++++++++++++++++++++++++++++
1426

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

    
1431
Supports the following commands: ``GET``.
1432

    
1433
``GET``
1434
~~~~~~~
1435

    
1436
Returns a list of field descriptions for available fields. Takes an
1437
optional query parameter named "fields", containing a comma-separated
1438
list of field names.
1439

    
1440

    
1441
``/2/os``
1442
+++++++++
1443

    
1444
OS resource.
1445

    
1446
It supports the following commands: ``GET``.
1447

    
1448
``GET``
1449
~~~~~~~
1450

    
1451
Return a list of all OSes.
1452

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

    
1456
Example::
1457

    
1458
    ["debian-etch"]
1459

    
1460
``/2/tags``
1461
+++++++++++
1462

    
1463
Manages cluster tags.
1464

    
1465
It supports the following commands: ``GET``, ``PUT``, ``DELETE``.
1466

    
1467
``GET``
1468
~~~~~~~
1469

    
1470
Returns the cluster tags.
1471

    
1472
Example::
1473

    
1474
    ["tag1", "tag2", "tag3"]
1475

    
1476
``PUT``
1477
~~~~~~~
1478

    
1479
Adds a set of tags.
1480

    
1481
The request as a list of strings should be PUT to this URI. The result
1482
will be a job id.
1483

    
1484
It supports the ``dry-run`` argument.
1485

    
1486

    
1487
``DELETE``
1488
~~~~~~~~~~
1489

    
1490
Deletes tags.
1491

    
1492
In order to delete a set of tags, the DELETE request should be addressed
1493
to URI like::
1494

    
1495
    /tags?tag=[tag]&tag=[tag]
1496

    
1497
It supports the ``dry-run`` argument.
1498

    
1499

    
1500
``/version``
1501
++++++++++++
1502

    
1503
The version resource.
1504

    
1505
This resource should be used to determine the remote API version and to
1506
adapt clients accordingly.
1507

    
1508
It supports the following commands: ``GET``.
1509

    
1510
``GET``
1511
~~~~~~~
1512

    
1513
Returns the remote API version. Ganeti 1.2 returned ``1`` and Ganeti 2.0
1514
returns ``2``.
1515

    
1516
.. vim: set textwidth=72 :
1517
.. Local Variables:
1518
.. mode: rst
1519
.. fill-column: 72
1520
.. End: