Statistics
| Branch: | Tag: | Revision:

root / doc / rapi.rst @ 132cdb87

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``
246
++++++
247

    
248
Has no function, but for legacy reasons the ``GET`` method is supported.
249

    
250
``/2/info``
251
+++++++++++
252

    
253
Cluster information resource.
254

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

    
257
``GET``
258
~~~~~~~
259

    
260
Returns cluster information.
261

    
262
Example::
263

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

    
293

    
294
``/2/redistribute-config``
295
++++++++++++++++++++++++++
296

    
297
Redistribute configuration to all nodes.
298

    
299
It supports the following commands: ``PUT``.
300

    
301
``PUT``
302
~~~~~~~
303

    
304
Redistribute configuration to all nodes. The result will be a job id.
305

    
306

    
307
``/2/features``
308
+++++++++++++++
309

    
310
``GET``
311
~~~~~~~
312

    
313
Returns a list of features supported by the RAPI server. Available
314
features:
315

    
316
.. pyassert::
317

    
318
  rlib2.ALL_FEATURES == set([rlib2._INST_CREATE_REQV1,
319
                             rlib2._INST_REINSTALL_REQV1,
320
                             rlib2._NODE_MIGRATE_REQV1,
321
                             rlib2._NODE_EVAC_RES1])
322

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

    
334

    
335
``/2/modify``
336
++++++++++++++++++++++++++++++++++++++++
337

    
338
Modifies cluster parameters.
339

    
340
Supports the following commands: ``PUT``.
341

    
342
``PUT``
343
~~~~~~~
344

    
345
Returns a job ID.
346

    
347
Body parameters:
348

    
349
.. opcode_params:: OP_CLUSTER_SET_PARAMS
350

    
351

    
352
``/2/groups``
353
+++++++++++++
354

    
355
The groups resource.
356

    
357
It supports the following commands: ``GET``, ``POST``.
358

    
359
``GET``
360
~~~~~~~
361

    
362
Returns a list of all existing node groups.
363

    
364
Example::
365

    
366
    [
367
      {
368
        "name": "group1",
369
        "uri": "\/2\/groups\/group1"
370
      },
371
      {
372
        "name": "group2",
373
        "uri": "\/2\/groups\/group2"
374
      }
375
    ]
376

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

    
381
Returned fields: :pyeval:`utils.CommaJoin(sorted(rlib2.G_FIELDS))`
382

    
383
Example::
384

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

    
405
``POST``
406
~~~~~~~~
407

    
408
Creates a node group.
409

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

    
413
Returns: a job ID that can be used later for polling.
414

    
415
Body parameters:
416

    
417
.. opcode_params:: OP_GROUP_ADD
418

    
419
Earlier versions used a parameter named ``name`` which, while still
420
supported, has been renamed to ``group_name``.
421

    
422

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

    
426
Returns information about a node group.
427

    
428
It supports the following commands: ``GET``, ``DELETE``.
429

    
430
``GET``
431
~~~~~~~
432

    
433
Returns information about a node group, similar to the bulk output from
434
the node group list.
435

    
436
Returned fields: :pyeval:`utils.CommaJoin(sorted(rlib2.G_FIELDS))`
437

    
438
``DELETE``
439
~~~~~~~~~~
440

    
441
Deletes a node group.
442

    
443
It supports the ``dry-run`` argument.
444

    
445

    
446
``/2/groups/[group_name]/modify``
447
+++++++++++++++++++++++++++++++++
448

    
449
Modifies the parameters of a node group.
450

    
451
Supports the following commands: ``PUT``.
452

    
453
``PUT``
454
~~~~~~~
455

    
456
Returns a job ID.
457

    
458
Body parameters:
459

    
460
.. opcode_params:: OP_GROUP_SET_PARAMS
461
   :exclude: group_name
462

    
463
Job result:
464

    
465
.. opcode_result:: OP_GROUP_SET_PARAMS
466

    
467

    
468
``/2/groups/[group_name]/rename``
469
+++++++++++++++++++++++++++++++++
470

    
471
Renames a node group.
472

    
473
Supports the following commands: ``PUT``.
474

    
475
``PUT``
476
~~~~~~~
477

    
478
Returns a job ID.
479

    
480
Body parameters:
481

    
482
.. opcode_params:: OP_GROUP_RENAME
483
   :exclude: group_name
484

    
485
Job result:
486

    
487
.. opcode_result:: OP_GROUP_RENAME
488

    
489

    
490
``/2/groups/[group_name]/assign-nodes``
491
+++++++++++++++++++++++++++++++++++++++
492

    
493
Assigns nodes to a group.
494

    
495
Supports the following commands: ``PUT``.
496

    
497
``PUT``
498
~~~~~~~
499

    
500
Returns a job ID. It supports the ``dry-run`` and ``force`` arguments.
501

    
502
Body parameters:
503

    
504
.. opcode_params:: OP_GROUP_ASSIGN_NODES
505
   :exclude: group_name, force, dry_run
506

    
507

    
508
``/2/groups/[group_name]/tags``
509
+++++++++++++++++++++++++++++++
510

    
511
Manages per-nodegroup tags.
512

    
513
Supports the following commands: ``GET``, ``PUT``, ``DELETE``.
514

    
515
``GET``
516
~~~~~~~
517

    
518
Returns a list of tags.
519

    
520
Example::
521

    
522
    ["tag1", "tag2", "tag3"]
523

    
524
``PUT``
525
~~~~~~~
526

    
527
Add a set of tags.
528

    
529
The request as a list of strings should be ``PUT`` to this URI. The
530
result will be a job id.
531

    
532
It supports the ``dry-run`` argument.
533

    
534

    
535
``DELETE``
536
~~~~~~~~~~
537

    
538
Delete a tag.
539

    
540
In order to delete a set of tags, the DELETE request should be addressed
541
to URI like::
542

    
543
    /tags?tag=[tag]&tag=[tag]
544

    
545
It supports the ``dry-run`` argument.
546

    
547

    
548
``/2/instances``
549
++++++++++++++++
550

    
551
The instances resource.
552

    
553
It supports the following commands: ``GET``, ``POST``.
554

    
555
``GET``
556
~~~~~~~
557

    
558
Returns a list of all available instances.
559

    
560
Example::
561

    
562
    [
563
      {
564
        "name": "web.example.com",
565
        "uri": "\/instances\/web.example.com"
566
      },
567
      {
568
        "name": "mail.example.com",
569
        "uri": "\/instances\/mail.example.com"
570
      }
571
    ]
572

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

    
577
Returned fields: :pyeval:`utils.CommaJoin(sorted(rlib2.I_FIELDS))`
578

    
579
Example::
580

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

    
608

    
609
``POST``
610
~~~~~~~~
611

    
612
Creates an instance.
613

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

    
619
Returns: a job ID that can be used later for polling.
620

    
621
Body parameters:
622

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

    
628
.. opcode_params:: OP_INSTANCE_CREATE
629

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

    
634
Job result:
635

    
636
.. opcode_result:: OP_INSTANCE_CREATE
637

    
638

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

    
642
Instance-specific resource.
643

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

    
646
``GET``
647
~~~~~~~
648

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

    
652
Returned fields: :pyeval:`utils.CommaJoin(sorted(rlib2.I_FIELDS))`
653

    
654
``DELETE``
655
~~~~~~~~~~
656

    
657
Deletes an instance.
658

    
659
It supports the ``dry-run`` argument.
660

    
661

    
662
``/2/instances/[instance_name]/info``
663
+++++++++++++++++++++++++++++++++++++++
664

    
665
It supports the following commands: ``GET``.
666

    
667
``GET``
668
~~~~~~~
669

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

    
675

    
676
``/2/instances/[instance_name]/reboot``
677
+++++++++++++++++++++++++++++++++++++++
678

    
679
Reboots URI for an instance.
680

    
681
It supports the following commands: ``POST``.
682

    
683
``POST``
684
~~~~~~~~
685

    
686
Reboots the instance.
687

    
688
The URI takes optional ``type=soft|hard|full`` and
689
``ignore_secondaries=0|1`` parameters.
690

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

    
698
``ignore_secondaries`` is a bool argument indicating if we start the
699
instance even if secondary disks are failing.
700

    
701
It supports the ``dry-run`` argument.
702

    
703

    
704
``/2/instances/[instance_name]/shutdown``
705
+++++++++++++++++++++++++++++++++++++++++
706

    
707
Instance shutdown URI.
708

    
709
It supports the following commands: ``PUT``.
710

    
711
``PUT``
712
~~~~~~~
713

    
714
Shutdowns an instance.
715

    
716
It supports the ``dry-run`` argument.
717

    
718
.. opcode_params:: OP_INSTANCE_SHUTDOWN
719
   :exclude: instance_name, dry_run
720

    
721

    
722
``/2/instances/[instance_name]/startup``
723
++++++++++++++++++++++++++++++++++++++++
724

    
725
Instance startup URI.
726

    
727
It supports the following commands: ``PUT``.
728

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

    
732
Startup an instance.
733

    
734
The URI takes an optional ``force=1|0`` parameter to start the
735
instance even if secondary disks are failing.
736

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

    
739
``/2/instances/[instance_name]/reinstall``
740
++++++++++++++++++++++++++++++++++++++++++++++
741

    
742
Installs the operating system again.
743

    
744
It supports the following commands: ``POST``.
745

    
746
``POST``
747
~~~~~~~~
748

    
749
Returns a job ID.
750

    
751
Body parameters:
752

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

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

    
764

    
765
``/2/instances/[instance_name]/replace-disks``
766
++++++++++++++++++++++++++++++++++++++++++++++
767

    
768
Replaces disks on an instance.
769

    
770
It supports the following commands: ``POST``.
771

    
772
``POST``
773
~~~~~~~~
774

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

    
780
Either ``remote_node`` or ``iallocator`` needs to be defined when using
781
``mode=replace_new_secondary``.
782

    
783
``mode`` is a mandatory parameter. ``replace_auto`` tries to determine
784
the broken disk(s) on its own and replacing it.
785

    
786

    
787
``/2/instances/[instance_name]/activate-disks``
788
+++++++++++++++++++++++++++++++++++++++++++++++
789

    
790
Activate disks on an instance.
791

    
792
It supports the following commands: ``PUT``.
793

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

    
797
Takes the bool parameter ``ignore_size``. When set ignore the recorded
798
size (useful for forcing activation when recorded size is wrong).
799

    
800

    
801
``/2/instances/[instance_name]/deactivate-disks``
802
+++++++++++++++++++++++++++++++++++++++++++++++++
803

    
804
Deactivate disks on an instance.
805

    
806
It supports the following commands: ``PUT``.
807

    
808
``PUT``
809
~~~~~~~
810

    
811
Takes no parameters.
812

    
813

    
814
``/2/instances/[instance_name]/disk/[disk_index]/grow``
815
+++++++++++++++++++++++++++++++++++++++++++++++++++++++
816

    
817
Grows one disk of an instance.
818

    
819
Supports the following commands: ``POST``.
820

    
821
``POST``
822
~~~~~~~~
823

    
824
Returns a job ID.
825

    
826
Body parameters:
827

    
828
.. opcode_params:: OP_INSTANCE_GROW_DISK
829
   :exclude: instance_name, disk
830

    
831

    
832
``/2/instances/[instance_name]/prepare-export``
833
+++++++++++++++++++++++++++++++++++++++++++++++++
834

    
835
Prepares an export of an instance.
836

    
837
It supports the following commands: ``PUT``.
838

    
839
``PUT``
840
~~~~~~~
841

    
842
Takes one parameter, ``mode``, for the export mode. Returns a job ID.
843

    
844

    
845
``/2/instances/[instance_name]/export``
846
+++++++++++++++++++++++++++++++++++++++++++++++++
847

    
848
Exports an instance.
849

    
850
It supports the following commands: ``PUT``.
851

    
852
``PUT``
853
~~~~~~~
854

    
855
Returns a job ID.
856

    
857
Body parameters:
858

    
859
.. opcode_params:: OP_BACKUP_EXPORT
860
   :exclude: instance_name
861
   :alias: target_node=destination
862

    
863

    
864
``/2/instances/[instance_name]/migrate``
865
++++++++++++++++++++++++++++++++++++++++
866

    
867
Migrates an instance.
868

    
869
Supports the following commands: ``PUT``.
870

    
871
``PUT``
872
~~~~~~~
873

    
874
Returns a job ID.
875

    
876
Body parameters:
877

    
878
.. opcode_params:: OP_INSTANCE_MIGRATE
879
   :exclude: instance_name, live
880

    
881

    
882
``/2/instances/[instance_name]/failover``
883
+++++++++++++++++++++++++++++++++++++++++
884

    
885
Does a failover of an instance.
886

    
887
Supports the following commands: ``PUT``.
888

    
889
``PUT``
890
~~~~~~~
891

    
892
Returns a job ID.
893

    
894
Body parameters:
895

    
896
.. opcode_params:: OP_INSTANCE_FAILOVER
897
   :exclude: instance_name
898

    
899

    
900
``/2/instances/[instance_name]/rename``
901
++++++++++++++++++++++++++++++++++++++++
902

    
903
Renames an instance.
904

    
905
Supports the following commands: ``PUT``.
906

    
907
``PUT``
908
~~~~~~~
909

    
910
Returns a job ID.
911

    
912
Body parameters:
913

    
914
.. opcode_params:: OP_INSTANCE_RENAME
915
   :exclude: instance_name
916

    
917
Job result:
918

    
919
.. opcode_result:: OP_INSTANCE_RENAME
920

    
921

    
922
``/2/instances/[instance_name]/modify``
923
++++++++++++++++++++++++++++++++++++++++
924

    
925
Modifies an instance.
926

    
927
Supports the following commands: ``PUT``.
928

    
929
``PUT``
930
~~~~~~~
931

    
932
Returns a job ID.
933

    
934
Body parameters:
935

    
936
.. opcode_params:: OP_INSTANCE_SET_PARAMS
937
   :exclude: instance_name
938

    
939
Job result:
940

    
941
.. opcode_result:: OP_INSTANCE_SET_PARAMS
942

    
943

    
944
``/2/instances/[instance_name]/console``
945
++++++++++++++++++++++++++++++++++++++++
946

    
947
Request information for connecting to instance's console.
948

    
949
Supports the following commands: ``GET``.
950

    
951
``GET``
952
~~~~~~~
953

    
954
Returns a dictionary containing information about the instance's
955
console. Contained keys:
956

    
957
.. pyassert::
958

    
959
   constants.CONS_ALL == frozenset([
960
     constants.CONS_MESSAGE,
961
     constants.CONS_SSH,
962
     constants.CONS_VNC,
963
     ])
964

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

    
984

    
985
``/2/instances/[instance_name]/tags``
986
+++++++++++++++++++++++++++++++++++++
987

    
988
Manages per-instance tags.
989

    
990
It supports the following commands: ``GET``, ``PUT``, ``DELETE``.
991

    
992
``GET``
993
~~~~~~~
994

    
995
Returns a list of tags.
996

    
997
Example::
998

    
999
    ["tag1", "tag2", "tag3"]
1000

    
1001
``PUT``
1002
~~~~~~~
1003

    
1004
Add a set of tags.
1005

    
1006
The request as a list of strings should be ``PUT`` to this URI. The
1007
result will be a job id.
1008

    
1009
It supports the ``dry-run`` argument.
1010

    
1011

    
1012
``DELETE``
1013
~~~~~~~~~~
1014

    
1015
Delete a tag.
1016

    
1017
In order to delete a set of tags, the DELETE request should be addressed
1018
to URI like::
1019

    
1020
    /tags?tag=[tag]&tag=[tag]
1021

    
1022
It supports the ``dry-run`` argument.
1023

    
1024

    
1025
``/2/jobs``
1026
+++++++++++
1027

    
1028
The ``/2/jobs`` resource.
1029

    
1030
It supports the following commands: ``GET``.
1031

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

    
1035
Returns a dictionary of jobs.
1036

    
1037
Returns: a dictionary with jobs id and uri.
1038

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

    
1043
Returned fields for bulk requests (unlike other bulk requests, these
1044
fields are not the same as for per-job requests):
1045
:pyeval:`utils.CommaJoin(sorted(rlib2.J_FIELDS_BULK))`
1046

    
1047
``/2/jobs/[job_id]``
1048
++++++++++++++++++++
1049

    
1050

    
1051
Individual job URI.
1052

    
1053
It supports the following commands: ``GET``, ``DELETE``.
1054

    
1055
``GET``
1056
~~~~~~~
1057

    
1058
Returns a dictionary with job parameters, containing the fields
1059
:pyeval:`utils.CommaJoin(sorted(rlib2.J_FIELDS))`.
1060

    
1061
The result includes:
1062

    
1063
- id: job ID as a number
1064
- status: current job status as a string
1065
- ops: involved OpCodes as a list of dictionaries for each opcodes in
1066
  the job
1067
- opstatus: OpCodes status as a list
1068
- opresult: OpCodes results as a list
1069

    
1070
For a successful opcode, the ``opresult`` field corresponding to it will
1071
contain the raw result from its :term:`LogicalUnit`. In case an opcode
1072
has failed, its element in the opresult list will be a list of two
1073
elements:
1074

    
1075
- first element the error type (the Ganeti internal error name)
1076
- second element a list of either one or two elements:
1077

    
1078
  - the first element is the textual error description
1079
  - the second element, if any, will hold an error classification
1080

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

    
1087
.. pyassert::
1088

    
1089
   errors.ECODE_ALL == set([errors.ECODE_RESOLVER, errors.ECODE_NORES,
1090
     errors.ECODE_INVAL, errors.ECODE_STATE, errors.ECODE_NOENT,
1091
     errors.ECODE_EXISTS, errors.ECODE_NOTUNIQUE, errors.ECODE_FAULT,
1092
     errors.ECODE_ENVIRON])
1093

    
1094
:pyeval:`errors.ECODE_RESOLVER`
1095
  Resolver errors. This usually means that a name doesn't exist in DNS,
1096
  so if it's a case of slow DNS propagation the operation can be retried
1097
  later.
1098

    
1099
:pyeval:`errors.ECODE_NORES`
1100
  Not enough resources (iallocator failure, disk space, memory,
1101
  etc.). If the resources on the cluster increase, the operation might
1102
  succeed.
1103

    
1104
:pyeval:`errors.ECODE_INVAL`
1105
  Wrong arguments (at syntax level). The operation will not ever be
1106
  accepted unless the arguments change.
1107

    
1108
:pyeval:`errors.ECODE_STATE`
1109
  Wrong entity state. For example, live migration has been requested for
1110
  a down instance, or instance creation on an offline node. The
1111
  operation can be retried once the resource has changed state.
1112

    
1113
:pyeval:`errors.ECODE_NOENT`
1114
  Entity not found. For example, information has been requested for an
1115
  unknown instance.
1116

    
1117
:pyeval:`errors.ECODE_EXISTS`
1118
  Entity already exists. For example, instance creation has been
1119
  requested for an already-existing instance.
1120

    
1121
:pyeval:`errors.ECODE_NOTUNIQUE`
1122
  Resource not unique (e.g. MAC or IP duplication).
1123

    
1124
:pyeval:`errors.ECODE_FAULT`
1125
  Internal cluster error. For example, a node is unreachable but not set
1126
  offline, or the ganeti node daemons are not working, etc. A
1127
  ``gnt-cluster verify`` should be run.
1128

    
1129
:pyeval:`errors.ECODE_ENVIRON`
1130
  Environment error (e.g. node disk error). A ``gnt-cluster verify``
1131
  should be run.
1132

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

    
1136

    
1137
``DELETE``
1138
~~~~~~~~~~
1139

    
1140
Cancel a not-yet-started job.
1141

    
1142

    
1143
``/2/jobs/[job_id]/wait``
1144
+++++++++++++++++++++++++
1145

    
1146
``GET``
1147
~~~~~~~
1148

    
1149
Waits for changes on a job. Takes the following body parameters in a
1150
dict:
1151

    
1152
``fields``
1153
  The job fields on which to watch for changes.
1154

    
1155
``previous_job_info``
1156
  Previously received field values or None if not yet available.
1157

    
1158
``previous_log_serial``
1159
  Highest log serial number received so far or None if not yet
1160
  available.
1161

    
1162
Returns None if no changes have been detected and a dict with two keys,
1163
``job_info`` and ``log_entries`` otherwise.
1164

    
1165

    
1166
``/2/nodes``
1167
++++++++++++
1168

    
1169
Nodes resource.
1170

    
1171
It supports the following commands: ``GET``.
1172

    
1173
``GET``
1174
~~~~~~~
1175

    
1176
Returns a list of all nodes.
1177

    
1178
Example::
1179

    
1180
    [
1181
      {
1182
        "id": "node1.example.com",
1183
        "uri": "\/nodes\/node1.example.com"
1184
      },
1185
      {
1186
        "id": "node2.example.com",
1187
        "uri": "\/nodes\/node2.example.com"
1188
      }
1189
    ]
1190

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

    
1195
Returned fields: :pyeval:`utils.CommaJoin(sorted(rlib2.N_FIELDS))`
1196

    
1197
Example::
1198

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

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

    
1218
Returns information about a node.
1219

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

    
1222
Returned fields: :pyeval:`utils.CommaJoin(sorted(rlib2.N_FIELDS))`
1223

    
1224
``/2/nodes/[node_name]/evacuate``
1225
+++++++++++++++++++++++++++++++++
1226

    
1227
Evacuates instances off a node.
1228

    
1229
It supports the following commands: ``POST``.
1230

    
1231
``POST``
1232
~~~~~~~~
1233

    
1234
Returns a job ID. The result of the job will contain the IDs of the
1235
individual jobs submitted to evacuate the node.
1236

    
1237
Body parameters:
1238

    
1239
.. opcode_params:: OP_NODE_EVACUATE
1240
   :exclude: nodes
1241

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

    
1246
Job result:
1247

    
1248
.. opcode_result:: OP_NODE_EVACUATE
1249

    
1250

    
1251
``/2/nodes/[node_name]/migrate``
1252
+++++++++++++++++++++++++++++++++
1253

    
1254
Migrates all primary instances from a node.
1255

    
1256
It supports the following commands: ``POST``.
1257

    
1258
``POST``
1259
~~~~~~~~
1260

    
1261
If no mode is explicitly specified, each instances' hypervisor default
1262
migration mode will be used. Body parameters:
1263

    
1264
.. opcode_params:: OP_NODE_MIGRATE
1265
   :exclude: node_name
1266

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

    
1271

    
1272
``/2/nodes/[node_name]/role``
1273
+++++++++++++++++++++++++++++
1274

    
1275
Manages node role.
1276

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

    
1279
The role is always one of the following:
1280

    
1281
  - drained
1282
  - master-candidate
1283
  - offline
1284
  - regular
1285

    
1286
Note that the 'master' role is a special, and currently it can't be
1287
modified via RAPI, only via the command line (``gnt-cluster
1288
master-failover``).
1289

    
1290
``GET``
1291
~~~~~~~
1292

    
1293
Returns the current node role.
1294

    
1295
Example::
1296

    
1297
    "master-candidate"
1298

    
1299
``PUT``
1300
~~~~~~~
1301

    
1302
Change the node role.
1303

    
1304
The request is a string which should be PUT to this URI. The result will
1305
be a job id.
1306

    
1307
It supports the bool ``force`` argument.
1308

    
1309
``/2/nodes/[node_name]/storage``
1310
++++++++++++++++++++++++++++++++
1311

    
1312
Manages storage units on the node.
1313

    
1314
``GET``
1315
~~~~~~~
1316

    
1317
.. pyassert::
1318

    
1319
   constants.VALID_STORAGE_TYPES == set([constants.ST_FILE,
1320
                                         constants.ST_LVM_PV,
1321
                                         constants.ST_LVM_VG])
1322

    
1323
Requests a list of storage units on a node. Requires the parameters
1324
``storage_type`` (one of :pyeval:`constants.ST_FILE`,
1325
:pyeval:`constants.ST_LVM_PV` or :pyeval:`constants.ST_LVM_VG`) and
1326
``output_fields``. The result will be a job id, using which the result
1327
can be retrieved.
1328

    
1329
``/2/nodes/[node_name]/storage/modify``
1330
+++++++++++++++++++++++++++++++++++++++
1331

    
1332
Modifies storage units on the node.
1333

    
1334
``PUT``
1335
~~~~~~~
1336

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

    
1344
``/2/nodes/[node_name]/storage/repair``
1345
+++++++++++++++++++++++++++++++++++++++
1346

    
1347
Repairs a storage unit on the node.
1348

    
1349
``PUT``
1350
~~~~~~~
1351

    
1352
.. pyassert::
1353

    
1354
   constants.VALID_STORAGE_OPERATIONS == {
1355
    constants.ST_LVM_VG: set([constants.SO_FIX_CONSISTENCY]),
1356
    }
1357

    
1358
Repairs a storage unit on the node. Requires the parameters
1359
``storage_type`` (currently only :pyeval:`constants.ST_LVM_VG` can be
1360
repaired) and ``name`` (name of the storage unit). The result will be a
1361
job id.
1362

    
1363
``/2/nodes/[node_name]/tags``
1364
+++++++++++++++++++++++++++++
1365

    
1366
Manages per-node tags.
1367

    
1368
It supports the following commands: ``GET``, ``PUT``, ``DELETE``.
1369

    
1370
``GET``
1371
~~~~~~~
1372

    
1373
Returns a list of tags.
1374

    
1375
Example::
1376

    
1377
    ["tag1", "tag2", "tag3"]
1378

    
1379
``PUT``
1380
~~~~~~~
1381

    
1382
Add a set of tags.
1383

    
1384
The request as a list of strings should be PUT to this URI. The result
1385
will be a job id.
1386

    
1387
It supports the ``dry-run`` argument.
1388

    
1389
``DELETE``
1390
~~~~~~~~~~
1391

    
1392
Deletes tags.
1393

    
1394
In order to delete a set of tags, the DELETE request should be addressed
1395
to URI like::
1396

    
1397
    /tags?tag=[tag]&tag=[tag]
1398

    
1399
It supports the ``dry-run`` argument.
1400

    
1401

    
1402
``/2/query/[resource]``
1403
+++++++++++++++++++++++
1404

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

    
1410
Supports the following commands: ``GET``, ``PUT``.
1411

    
1412
``GET``
1413
~~~~~~~
1414

    
1415
Returns list of included fields and actual data. Takes a query parameter
1416
named "fields", containing a comma-separated list of field names. Does
1417
not support filtering.
1418

    
1419
``PUT``
1420
~~~~~~~
1421

    
1422
Returns list of included fields and actual data. The list of requested
1423
fields can either be given as the query parameter "fields" or as a body
1424
parameter with the same name. The optional body parameter "filter" can
1425
be given and must be either ``null`` or a list containing filter
1426
operators.
1427

    
1428

    
1429
``/2/query/[resource]/fields``
1430
++++++++++++++++++++++++++++++
1431

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

    
1436
Supports the following commands: ``GET``.
1437

    
1438
``GET``
1439
~~~~~~~
1440

    
1441
Returns a list of field descriptions for available fields. Takes an
1442
optional query parameter named "fields", containing a comma-separated
1443
list of field names.
1444

    
1445

    
1446
``/2/os``
1447
+++++++++
1448

    
1449
OS resource.
1450

    
1451
It supports the following commands: ``GET``.
1452

    
1453
``GET``
1454
~~~~~~~
1455

    
1456
Return a list of all OSes.
1457

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

    
1461
Example::
1462

    
1463
    ["debian-etch"]
1464

    
1465
``/2/tags``
1466
+++++++++++
1467

    
1468
Manages cluster tags.
1469

    
1470
It supports the following commands: ``GET``, ``PUT``, ``DELETE``.
1471

    
1472
``GET``
1473
~~~~~~~
1474

    
1475
Returns the cluster tags.
1476

    
1477
Example::
1478

    
1479
    ["tag1", "tag2", "tag3"]
1480

    
1481
``PUT``
1482
~~~~~~~
1483

    
1484
Adds a set of tags.
1485

    
1486
The request as a list of strings should be PUT to this URI. The result
1487
will be a job id.
1488

    
1489
It supports the ``dry-run`` argument.
1490

    
1491

    
1492
``DELETE``
1493
~~~~~~~~~~
1494

    
1495
Deletes tags.
1496

    
1497
In order to delete a set of tags, the DELETE request should be addressed
1498
to URI like::
1499

    
1500
    /tags?tag=[tag]&tag=[tag]
1501

    
1502
It supports the ``dry-run`` argument.
1503

    
1504

    
1505
``/version``
1506
++++++++++++
1507

    
1508
The version resource.
1509

    
1510
This resource should be used to determine the remote API version and to
1511
adapt clients accordingly.
1512

    
1513
It supports the following commands: ``GET``.
1514

    
1515
``GET``
1516
~~~~~~~
1517

    
1518
Returns the remote API version. Ganeti 1.2 returned ``1`` and Ganeti 2.0
1519
returns ``2``.
1520

    
1521
.. vim: set textwidth=72 :
1522
.. Local Variables:
1523
.. mode: rst
1524
.. fill-column: 72
1525
.. End: