Statistics
| Branch: | Tag: | Revision:

root / doc / rapi.rst @ 6e8091f9

History | View | Annotate | Download (42.2 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
Lines starting with the hash sign (``#``) are treated as comments. Each
28
line consists of two or three fields separated by whitespace. The first
29
two fields are for username and password. The third field is optional
30
and can be used to specify per-user options (separated by comma without
31
spaces). Available options:
32

    
33
.. pyassert::
34

    
35
  rapi.RAPI_ACCESS_ALL == set([
36
    rapi.RAPI_ACCESS_WRITE,
37
    rapi.RAPI_ACCESS_READ,
38
    ])
39

    
40
:pyeval:`rapi.RAPI_ACCESS_WRITE`
41
  Enables the user to execute operations modifying the cluster. Implies
42
  :pyeval:`rapi.RAPI_ACCESS_READ` access.
43
:pyeval:`rapi.RAPI_ACCESS_READ`
44
  Allow access to operations querying for information.
45

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

    
54
Example::
55

    
56
  # Give Jack and Fred read-only access
57
  jack abc123
58
  fred {cleartext}foo555
59

    
60
  # Give write access to an imaginary instance creation script
61
  autocreator xyz789 write
62

    
63
  # Hashed password for Jessica
64
  jessica {HA1}7046452df2cbb530877058712cf17bd4 write
65

    
66
  # Monitoring can query for values
67
  monitoring {HA1}ec018ffe72b8e75bb4d508ed5b6d079c query
68

    
69
  # A user who can query and write
70
  superuser {HA1}ec018ffe72b8e75bb4d508ed5b6d079c query,write
71

    
72

    
73
.. [#pwhash] Using the MD5 hash of username, realm and password is
74
   described in :rfc:`2617` ("HTTP Authentication"), sections 3.2.2.2
75
   and 3.3. The reason for using it over another algorithm is forward
76
   compatibility. If ``ganeti-rapi`` were to implement HTTP Digest
77
   authentication in the future, the same hash could be used.
78
   In the current version ``ganeti-rapi``'s realm, ``Ganeti Remote
79
   API``, can only be changed by modifying the source code.
80

    
81

    
82
Protocol
83
--------
84

    
85
The protocol used is JSON_ over HTTP designed after the REST_ principle.
86
HTTP Basic authentication as per :rfc:`2617` is supported.
87

    
88
.. _JSON: http://www.json.org/
89
.. _REST: http://en.wikipedia.org/wiki/Representational_State_Transfer
90

    
91
HTTP requests with a body (e.g. ``PUT`` or ``POST``) require the request
92
header ``Content-type`` be set to ``application/json`` (see :rfc:`2616`
93
(HTTP/1.1), section 7.2.1).
94

    
95

    
96
A note on JSON as used by RAPI
97
++++++++++++++++++++++++++++++
98

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

    
106
.. highlight:: ruby
107

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

    
116
  require "json"
117

    
118
  # Insert code to get response here
119
  response = "\"1234\""
120

    
121
  decoded = JSON.parse("[#{response}]").first
122

    
123
Short of modifying the encoder to allow encoding to a less strict
124
format, requests will have to be formatted by hand. Newer RAPI requests
125
already use a dictionary as their input data and shouldn't cause any
126
problems.
127

    
128

    
129
PUT or POST?
130
------------
131

    
132
According to :rfc:`2616` the main difference between PUT and POST is
133
that POST can create new resources but PUT can only create the resource
134
the URI was pointing to on the PUT request.
135

    
136
Unfortunately, due to historic reasons, the Ganeti RAPI library is not
137
consistent with this usage, so just use the methods as documented below
138
for each resource.
139

    
140
For more details have a look in the source code at
141
``lib/rapi/rlib2.py``.
142

    
143

    
144
Generic parameter types
145
-----------------------
146

    
147
A few generic refered parameter types and the values they allow.
148

    
149
``bool``
150
++++++++
151

    
152
A boolean option will accept ``1`` or ``0`` as numbers but not
153
i.e. ``True`` or ``False``.
154

    
155
Generic parameters
156
------------------
157

    
158
A few parameter mean the same thing across all resources which implement
159
it.
160

    
161
``bulk``
162
++++++++
163

    
164
Bulk-mode means that for the resources which usually return just a list
165
of child resources (e.g. ``/2/instances`` which returns just instance
166
names), the output will instead contain detailed data for all these
167
subresources. This is more efficient than query-ing the sub-resources
168
themselves.
169

    
170
``dry-run``
171
+++++++++++
172

    
173
The boolean *dry-run* argument, if provided and set, signals to Ganeti
174
that the job should not be executed, only the pre-execution checks will
175
be done.
176

    
177
This is useful in trying to determine (without guarantees though, as in
178
the meantime the cluster state could have changed) if the operation is
179
likely to succeed or at least start executing.
180

    
181
``force``
182
+++++++++++
183

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

    
187
Parameter details
188
-----------------
189

    
190
Some parameters are not straight forward, so we describe them in details
191
here.
192

    
193
.. _rapi-ipolicy:
194

    
195
``ipolicy``
196
+++++++++++
197

    
198
The instance policy specification is a dict with the following fields:
199

    
200
.. pyassert::
201

    
202
  constants.IPOLICY_ALL_KEYS == set([constants.ISPECS_MIN,
203
                                     constants.ISPECS_MAX,
204
                                     constants.ISPECS_STD,
205
                                     constants.IPOLICY_DTS,
206
                                     constants.IPOLICY_VCPU_RATIO,
207
                                     constants.IPOLICY_SPINDLE_RATIO])
208

    
209

    
210
.. pyassert::
211

    
212
  (set(constants.ISPECS_PARAMETER_TYPES.keys()) ==
213
   set([constants.ISPEC_MEM_SIZE,
214
        constants.ISPEC_DISK_SIZE,
215
        constants.ISPEC_DISK_COUNT,
216
        constants.ISPEC_CPU_COUNT,
217
        constants.ISPEC_NIC_COUNT,
218
        constants.ISPEC_SPINDLE_USE]))
219

    
220
.. |ispec-min| replace:: :pyeval:`constants.ISPECS_MIN`
221
.. |ispec-max| replace:: :pyeval:`constants.ISPECS_MAX`
222
.. |ispec-std| replace:: :pyeval:`constants.ISPECS_STD`
223

    
224

    
225
|ispec-min|, |ispec-max|, |ispec-std|
226
  A sub- `dict` with the following fields, which sets the limit and standard
227
  values of the instances:
228

    
229
  :pyeval:`constants.ISPEC_MEM_SIZE`
230
    The size in MiB of the memory used
231
  :pyeval:`constants.ISPEC_DISK_SIZE`
232
    The size in MiB of the disk used
233
  :pyeval:`constants.ISPEC_DISK_COUNT`
234
    The numbers of disks used
235
  :pyeval:`constants.ISPEC_CPU_COUNT`
236
    The numbers of cpus used
237
  :pyeval:`constants.ISPEC_NIC_COUNT`
238
    The numbers of nics used
239
  :pyeval:`constants.ISPEC_SPINDLE_USE`
240
    The numbers of virtual disk spindles used by this instance. They are
241
    not real in the sense of actual HDD spindles, but useful for
242
    accounting the spindle usage on the residing node
243
:pyeval:`constants.IPOLICY_DTS`
244
  A `list` of disk templates allowed for instances using this policy
245
:pyeval:`constants.IPOLICY_VCPU_RATIO`
246
  Maximum ratio of virtual to physical CPUs (`float`)
247
:pyeval:`constants.IPOLICY_SPINDLE_RATIO`
248
  Maximum ratio of instances to their node's ``spindle_count`` (`float`)
249

    
250
Usage examples
251
--------------
252

    
253
You can access the API using your favorite programming language as long
254
as it supports network connections.
255

    
256
Ganeti RAPI client
257
++++++++++++++++++
258

    
259
Ganeti includes a standalone RAPI client, ``lib/rapi/client.py``.
260

    
261
Shell
262
+++++
263

    
264
.. highlight:: shell-example
265

    
266
Using wget::
267

    
268
   $ wget -q -O - https://%CLUSTERNAME%:5080/2/info
269

    
270
or curl::
271

    
272
  $ curl https://%CLUSTERNAME%:5080/2/info
273

    
274

    
275
Python
276
++++++
277

    
278
.. highlight:: python
279

    
280
::
281

    
282
  import urllib2
283
  f = urllib2.urlopen('https://CLUSTERNAME:5080/2/info')
284
  print f.read()
285

    
286

    
287
JavaScript
288
++++++++++
289

    
290
.. warning:: While it's possible to use JavaScript, it poses several
291
   potential problems, including browser blocking request due to
292
   non-standard ports or different domain names. Fetching the data on
293
   the webserver is easier.
294

    
295
.. highlight:: javascript
296

    
297
::
298

    
299
  var url = 'https://CLUSTERNAME:5080/2/info';
300
  var info;
301
  var xmlreq = new XMLHttpRequest();
302
  xmlreq.onreadystatechange = function () {
303
    if (xmlreq.readyState != 4) return;
304
    if (xmlreq.status == 200) {
305
      info = eval("(" + xmlreq.responseText + ")");
306
      alert(info);
307
    } else {
308
      alert('Error fetching cluster info');
309
    }
310
    xmlreq = null;
311
  };
312
  xmlreq.open('GET', url, true);
313
  xmlreq.send(null);
314

    
315
Resources
316
---------
317

    
318
.. highlight:: javascript
319

    
320
``/``
321
+++++
322

    
323
The root resource. Has no function, but for legacy reasons the ``GET``
324
method is supported.
325

    
326
``/2``
327
++++++
328

    
329
Has no function, but for legacy reasons the ``GET`` method is supported.
330

    
331
``/2/info``
332
+++++++++++
333

    
334
Cluster information resource.
335

    
336
It supports the following commands: ``GET``.
337

    
338
``GET``
339
~~~~~~~
340

    
341
Returns cluster information.
342

    
343
Example::
344

    
345
  {
346
    "config_version": 2000000,
347
    "name": "cluster",
348
    "software_version": "2.0.0~beta2",
349
    "os_api_version": 10,
350
    "export_version": 0,
351
    "candidate_pool_size": 10,
352
    "enabled_hypervisors": [
353
      "fake"
354
    ],
355
    "hvparams": {
356
      "fake": {}
357
     },
358
    "default_hypervisor": "fake",
359
    "master": "node1.example.com",
360
    "architecture": [
361
      "64bit",
362
      "x86_64"
363
    ],
364
    "protocol_version": 20,
365
    "beparams": {
366
      "default": {
367
        "auto_balance": true,
368
        "vcpus": 1,
369
        "memory": 128
370
       }
371
      }
372
    }
373

    
374

    
375
``/2/redistribute-config``
376
++++++++++++++++++++++++++
377

    
378
Redistribute configuration to all nodes.
379

    
380
It supports the following commands: ``PUT``.
381

    
382
``PUT``
383
~~~~~~~
384

    
385
Redistribute configuration to all nodes. The result will be a job id.
386

    
387
Job result:
388

    
389
.. opcode_result:: OP_CLUSTER_REDIST_CONF
390

    
391

    
392
``/2/features``
393
+++++++++++++++
394

    
395
``GET``
396
~~~~~~~
397

    
398
Returns a list of features supported by the RAPI server. Available
399
features:
400

    
401
.. pyassert::
402

    
403
  rlib2.ALL_FEATURES == set([rlib2._INST_CREATE_REQV1,
404
                             rlib2._INST_REINSTALL_REQV1,
405
                             rlib2._NODE_MIGRATE_REQV1,
406
                             rlib2._NODE_EVAC_RES1])
407

    
408
:pyeval:`rlib2._INST_CREATE_REQV1`
409
  Instance creation request data version 1 supported
410
:pyeval:`rlib2._INST_REINSTALL_REQV1`
411
  Instance reinstall supports body parameters
412
:pyeval:`rlib2._NODE_MIGRATE_REQV1`
413
  Whether migrating a node (``/2/nodes/[node_name]/migrate``) supports
414
  request body parameters
415
:pyeval:`rlib2._NODE_EVAC_RES1`
416
  Whether evacuating a node (``/2/nodes/[node_name]/evacuate``) returns
417
  a new-style result (see resource description)
418

    
419

    
420
``/2/modify``
421
++++++++++++++++++++++++++++++++++++++++
422

    
423
Modifies cluster parameters.
424

    
425
Supports the following commands: ``PUT``.
426

    
427
``PUT``
428
~~~~~~~
429

    
430
Returns a job ID.
431

    
432
Body parameters:
433

    
434
.. opcode_params:: OP_CLUSTER_SET_PARAMS
435

    
436
Job result:
437

    
438
.. opcode_result:: OP_CLUSTER_SET_PARAMS
439

    
440

    
441
``/2/groups``
442
+++++++++++++
443

    
444
The groups resource.
445

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

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

    
451
Returns a list of all existing node groups.
452

    
453
Example::
454

    
455
    [
456
      {
457
        "name": "group1",
458
        "uri": "\/2\/groups\/group1"
459
      },
460
      {
461
        "name": "group2",
462
        "uri": "\/2\/groups\/group2"
463
      }
464
    ]
465

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

    
470
Returned fields: :pyeval:`utils.CommaJoin(sorted(rlib2.G_FIELDS))`.
471

    
472
Example::
473

    
474
    [
475
      {
476
        "name": "group1",
477
        "node_cnt": 2,
478
        "node_list": [
479
          "node1.example.com",
480
          "node2.example.com"
481
        ],
482
        "uuid": "0d7d407c-262e-49af-881a-6a430034bf43"
483
      },
484
      {
485
        "name": "group2",
486
        "node_cnt": 1,
487
        "node_list": [
488
          "node3.example.com"
489
        ],
490
        "uuid": "f5a277e7-68f9-44d3-a378-4b25ecb5df5c"
491
      }
492
    ]
493

    
494
``POST``
495
~~~~~~~~
496

    
497
Creates a node group.
498

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

    
502
Returns: a job ID that can be used later for polling.
503

    
504
Body parameters:
505

    
506
.. opcode_params:: OP_GROUP_ADD
507

    
508
Earlier versions used a parameter named ``name`` which, while still
509
supported, has been renamed to ``group_name``.
510

    
511
Job result:
512

    
513
.. opcode_result:: OP_GROUP_ADD
514

    
515

    
516
``/2/groups/[group_name]``
517
++++++++++++++++++++++++++
518

    
519
Returns information about a node group.
520

    
521
It supports the following commands: ``GET``, ``DELETE``.
522

    
523
``GET``
524
~~~~~~~
525

    
526
Returns information about a node group, similar to the bulk output from
527
the node group list.
528

    
529
Returned fields: :pyeval:`utils.CommaJoin(sorted(rlib2.G_FIELDS))`.
530

    
531
``DELETE``
532
~~~~~~~~~~
533

    
534
Deletes a node group.
535

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

    
538
Job result:
539

    
540
.. opcode_result:: OP_GROUP_REMOVE
541

    
542

    
543
``/2/groups/[group_name]/modify``
544
+++++++++++++++++++++++++++++++++
545

    
546
Modifies the parameters of a node group.
547

    
548
Supports the following commands: ``PUT``.
549

    
550
``PUT``
551
~~~~~~~
552

    
553
Returns a job ID.
554

    
555
Body parameters:
556

    
557
.. opcode_params:: OP_GROUP_SET_PARAMS
558
   :exclude: group_name
559

    
560
Job result:
561

    
562
.. opcode_result:: OP_GROUP_SET_PARAMS
563

    
564

    
565
``/2/groups/[group_name]/rename``
566
+++++++++++++++++++++++++++++++++
567

    
568
Renames a node group.
569

    
570
Supports the following commands: ``PUT``.
571

    
572
``PUT``
573
~~~~~~~
574

    
575
Returns a job ID.
576

    
577
Body parameters:
578

    
579
.. opcode_params:: OP_GROUP_RENAME
580
   :exclude: group_name
581

    
582
Job result:
583

    
584
.. opcode_result:: OP_GROUP_RENAME
585

    
586

    
587
``/2/groups/[group_name]/assign-nodes``
588
+++++++++++++++++++++++++++++++++++++++
589

    
590
Assigns nodes to a group.
591

    
592
Supports the following commands: ``PUT``.
593

    
594
``PUT``
595
~~~~~~~
596

    
597
Returns a job ID. It supports the ``dry-run`` and ``force`` arguments.
598

    
599
Body parameters:
600

    
601
.. opcode_params:: OP_GROUP_ASSIGN_NODES
602
   :exclude: group_name, force, dry_run
603

    
604
Job result:
605

    
606
.. opcode_result:: OP_GROUP_ASSIGN_NODES
607

    
608

    
609
``/2/groups/[group_name]/tags``
610
+++++++++++++++++++++++++++++++
611

    
612
Manages per-nodegroup tags.
613

    
614
Supports the following commands: ``GET``, ``PUT``, ``DELETE``.
615

    
616
``GET``
617
~~~~~~~
618

    
619
Returns a list of tags.
620

    
621
Example::
622

    
623
    ["tag1", "tag2", "tag3"]
624

    
625
``PUT``
626
~~~~~~~
627

    
628
Add a set of tags.
629

    
630
The request as a list of strings should be ``PUT`` to this URI. The
631
result will be a job id.
632

    
633
It supports the ``dry-run`` argument.
634

    
635

    
636
``DELETE``
637
~~~~~~~~~~
638

    
639
Delete a tag.
640

    
641
In order to delete a set of tags, the DELETE request should be addressed
642
to URI like::
643

    
644
    /tags?tag=[tag]&tag=[tag]
645

    
646
It supports the ``dry-run`` argument.
647

    
648

    
649
``/2/networks``
650
+++++++++++++++
651

    
652
The networks resource.
653

    
654
It supports the following commands: ``GET``, ``POST``.
655

    
656
``GET``
657
~~~~~~~
658

    
659
Returns a list of all existing networks.
660

    
661
Example::
662

    
663
    [
664
      {
665
        "name": "network1",
666
        "uri": "\/2\/networks\/network1"
667
      },
668
      {
669
        "name": "network2",
670
        "uri": "\/2\/networks\/network2"
671
      }
672
    ]
673

    
674
If the optional bool *bulk* argument is provided and set to a true value
675
(i.e ``?bulk=1``), the output contains detailed information about networks
676
as a list.
677

    
678
Returned fields: :pyeval:`utils.CommaJoin(sorted(rlib2.NET_FIELDS))`.
679

    
680
Example::
681

    
682
    [
683
      {
684
        'external_reservations': '10.0.0.0, 10.0.0.1, 10.0.0.15',
685
        'free_count': 13,
686
        'gateway': '10.0.0.1',
687
        'gateway6': None,
688
        'group_list': ['default(bridged, prv0)'],
689
        'inst_list': [],
690
        'mac_prefix': None,
691
        'map': 'XX.............X',
692
        'name': 'nat',
693
        'network': '10.0.0.0/28',
694
        'network6': None,
695
        'network_type': 'private',
696
        'reserved_count': 3,
697
        'tags': ['nfdhcpd']
698
      },
699
    ]
700

    
701
``POST``
702
~~~~~~~~
703

    
704
Creates a network.
705

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

    
709
Returns: a job ID that can be used later for polling.
710

    
711
Body parameters:
712

    
713
.. opcode_params:: OP_NETWORK_ADD
714

    
715
Job result:
716

    
717
.. opcode_result:: OP_NETWORK_ADD
718

    
719

    
720
``/2/networks/[network_name]``
721
++++++++++++++++++++++++++++++
722

    
723
Returns information about a network.
724

    
725
It supports the following commands: ``GET``, ``DELETE``.
726

    
727
``GET``
728
~~~~~~~
729

    
730
Returns information about a network, similar to the bulk output from
731
the network list.
732

    
733
Returned fields: :pyeval:`utils.CommaJoin(sorted(rlib2.NET_FIELDS))`.
734

    
735
``DELETE``
736
~~~~~~~~~~
737

    
738
Deletes a network.
739

    
740
It supports the ``dry-run`` argument.
741

    
742
Job result:
743

    
744
.. opcode_result:: OP_NETWORK_REMOVE
745

    
746

    
747
``/2/networks/[network_name]/modify``
748
+++++++++++++++++++++++++++++++++++++
749

    
750
Modifies the parameters of a network.
751

    
752
Supports the following commands: ``PUT``.
753

    
754
``PUT``
755
~~~~~~~
756

    
757
Returns a job ID.
758

    
759
Body parameters:
760

    
761
.. opcode_params:: OP_NETWORK_SET_PARAMS
762

    
763
Job result:
764

    
765
.. opcode_result:: OP_NETWORK_SET_PARAMS
766

    
767

    
768
``/2/networks/[network_name]/connect``
769
++++++++++++++++++++++++++++++++++++++
770

    
771
Connects a network to a nodegroup.
772

    
773
Supports the following commands: ``PUT``.
774

    
775
``PUT``
776
~~~~~~~
777

    
778
Returns a job ID. It supports the ``dry-run`` arguments.
779

    
780
Body parameters:
781

    
782
.. opcode_params:: OP_NETWORK_CONNECT
783

    
784
Job result:
785

    
786
.. opcode_result:: OP_NETWORK_CONNECT
787

    
788

    
789
``/2/networks/[network_name]/disconnect``
790
+++++++++++++++++++++++++++++++++++++++++
791

    
792
Disonnects a network from a nodegroup.
793

    
794
Supports the following commands: ``PUT``.
795

    
796
``PUT``
797
~~~~~~~
798

    
799
Returns a job ID. It supports the ``dry-run`` arguments.
800

    
801
Body parameters:
802

    
803
.. opcode_params:: OP_NETWORK_DISCONNECT
804

    
805
Job result:
806

    
807
.. opcode_result:: OP_NETWORK_DISCONNECT
808

    
809

    
810
``/2/networks/[network_name]/tags``
811
+++++++++++++++++++++++++++++++++++
812

    
813
Manages per-network tags.
814

    
815
Supports the following commands: ``GET``, ``PUT``, ``DELETE``.
816

    
817
``GET``
818
~~~~~~~
819

    
820
Returns a list of tags.
821

    
822
Example::
823

    
824
    ["tag1", "tag2", "tag3"]
825

    
826
``PUT``
827
~~~~~~~
828

    
829
Add a set of tags.
830

    
831
The request as a list of strings should be ``PUT`` to this URI. The
832
result will be a job id.
833

    
834
It supports the ``dry-run`` argument.
835

    
836

    
837
``DELETE``
838
~~~~~~~~~~
839

    
840
Delete a tag.
841

    
842
In order to delete a set of tags, the DELETE request should be addressed
843
to URI like::
844

    
845
    /tags?tag=[tag]&tag=[tag]
846

    
847
It supports the ``dry-run`` argument.
848

    
849

    
850
``/2/instances-multi-alloc``
851
++++++++++++++++++++++++++++
852

    
853
Tries to allocate multiple instances.
854

    
855
It supports the following commands: ``POST``
856

    
857
``POST``
858
~~~~~~~~
859

    
860
The parameters:
861

    
862
.. opcode_params:: OP_INSTANCE_MULTI_ALLOC
863

    
864
Job result:
865

    
866
.. opcode_result:: OP_INSTANCE_MULTI_ALLOC
867

    
868

    
869
``/2/instances``
870
++++++++++++++++
871

    
872
The instances resource.
873

    
874
It supports the following commands: ``GET``, ``POST``.
875

    
876
``GET``
877
~~~~~~~
878

    
879
Returns a list of all available instances.
880

    
881
Example::
882

    
883
    [
884
      {
885
        "name": "web.example.com",
886
        "uri": "\/instances\/web.example.com"
887
      },
888
      {
889
        "name": "mail.example.com",
890
        "uri": "\/instances\/mail.example.com"
891
      }
892
    ]
893

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

    
898
Returned fields: :pyeval:`utils.CommaJoin(sorted(rlib2.I_FIELDS))`.
899

    
900
Example::
901

    
902
    [
903
      {
904
         "status": "running",
905
         "disk_usage": 20480,
906
         "nic.bridges": [
907
           "xen-br0"
908
          ],
909
         "name": "web.example.com",
910
         "tags": ["tag1", "tag2"],
911
         "beparams": {
912
           "vcpus": 2,
913
           "memory": 512
914
         },
915
         "disk.sizes": [
916
             20480
917
         ],
918
         "pnode": "node1.example.com",
919
         "nic.macs": ["01:23:45:67:89:01"],
920
         "snodes": ["node2.example.com"],
921
         "disk_template": "drbd",
922
         "admin_state": true,
923
         "os": "debian-etch",
924
         "oper_state": true
925
      },
926
      ...
927
    ]
928

    
929

    
930
``POST``
931
~~~~~~~~
932

    
933
Creates an instance.
934

    
935
If the optional bool *dry-run* argument is provided, the job will not be
936
actually executed, only the pre-execution checks will be done. Query-ing
937
the job result will return, in both dry-run and normal case, the list of
938
nodes selected for the instance.
939

    
940
Returns: a job ID that can be used later for polling.
941

    
942
Body parameters:
943

    
944
``__version__`` (int, required)
945
  Must be ``1`` (older Ganeti versions used a different format for
946
  instance creation requests, version ``0``, but that format is no
947
  longer supported)
948

    
949
.. opcode_params:: OP_INSTANCE_CREATE
950

    
951
Earlier versions used parameters named ``name`` and ``os``. These have
952
been replaced by ``instance_name`` and ``os_type`` to match the
953
underlying opcode. The old names can still be used.
954

    
955
Job result:
956

    
957
.. opcode_result:: OP_INSTANCE_CREATE
958

    
959

    
960
``/2/instances/[instance_name]``
961
++++++++++++++++++++++++++++++++
962

    
963
Instance-specific resource.
964

    
965
It supports the following commands: ``GET``, ``DELETE``.
966

    
967
``GET``
968
~~~~~~~
969

    
970
Returns information about an instance, similar to the bulk output from
971
the instance list.
972

    
973
Returned fields: :pyeval:`utils.CommaJoin(sorted(rlib2.I_FIELDS))`.
974

    
975
``DELETE``
976
~~~~~~~~~~
977

    
978
Deletes an instance.
979

    
980
It supports the ``dry-run`` argument.
981

    
982
Job result:
983

    
984
.. opcode_result:: OP_INSTANCE_REMOVE
985

    
986

    
987
``/2/instances/[instance_name]/info``
988
+++++++++++++++++++++++++++++++++++++++
989

    
990
It supports the following commands: ``GET``.
991

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

    
995
Requests detailed information about the instance. An optional parameter,
996
``static`` (bool), can be set to return only static information from the
997
configuration without querying the instance's nodes. The result will be
998
a job id.
999

    
1000
Job result:
1001

    
1002
.. opcode_result:: OP_INSTANCE_QUERY_DATA
1003

    
1004

    
1005
``/2/instances/[instance_name]/reboot``
1006
+++++++++++++++++++++++++++++++++++++++
1007

    
1008
Reboots URI for an instance.
1009

    
1010
It supports the following commands: ``POST``.
1011

    
1012
``POST``
1013
~~~~~~~~
1014

    
1015
Reboots the instance.
1016

    
1017
The URI takes optional ``type=soft|hard|full`` and
1018
``ignore_secondaries=0|1`` parameters.
1019

    
1020
``type`` defines the reboot type. ``soft`` is just a normal reboot,
1021
without terminating the hypervisor. ``hard`` means full shutdown
1022
(including terminating the hypervisor process) and startup again.
1023
``full`` is like ``hard`` but also recreates the configuration from
1024
ground up as if you would have done a ``gnt-instance shutdown`` and
1025
``gnt-instance start`` on it.
1026

    
1027
``ignore_secondaries`` is a bool argument indicating if we start the
1028
instance even if secondary disks are failing.
1029

    
1030
It supports the ``dry-run`` argument.
1031

    
1032
Job result:
1033

    
1034
.. opcode_result:: OP_INSTANCE_REBOOT
1035

    
1036

    
1037
``/2/instances/[instance_name]/shutdown``
1038
+++++++++++++++++++++++++++++++++++++++++
1039

    
1040
Instance shutdown URI.
1041

    
1042
It supports the following commands: ``PUT``.
1043

    
1044
``PUT``
1045
~~~~~~~
1046

    
1047
Shutdowns an instance.
1048

    
1049
It supports the ``dry-run`` argument.
1050

    
1051
.. opcode_params:: OP_INSTANCE_SHUTDOWN
1052
   :exclude: instance_name, dry_run
1053

    
1054
Job result:
1055

    
1056
.. opcode_result:: OP_INSTANCE_SHUTDOWN
1057

    
1058

    
1059
``/2/instances/[instance_name]/startup``
1060
++++++++++++++++++++++++++++++++++++++++
1061

    
1062
Instance startup URI.
1063

    
1064
It supports the following commands: ``PUT``.
1065

    
1066
``PUT``
1067
~~~~~~~
1068

    
1069
Startup an instance.
1070

    
1071
The URI takes an optional ``force=1|0`` parameter to start the
1072
instance even if secondary disks are failing.
1073

    
1074
It supports the ``dry-run`` argument.
1075

    
1076
Job result:
1077

    
1078
.. opcode_result:: OP_INSTANCE_STARTUP
1079

    
1080

    
1081
``/2/instances/[instance_name]/reinstall``
1082
++++++++++++++++++++++++++++++++++++++++++++++
1083

    
1084
Installs the operating system again.
1085

    
1086
It supports the following commands: ``POST``.
1087

    
1088
``POST``
1089
~~~~~~~~
1090

    
1091
Returns a job ID.
1092

    
1093
Body parameters:
1094

    
1095
``os`` (string, required)
1096
  Instance operating system.
1097
``start`` (bool, defaults to true)
1098
  Whether to start instance after reinstallation.
1099
``osparams`` (dict)
1100
  Dictionary with (temporary) OS parameters.
1101

    
1102
For backwards compatbility, this resource also takes the query
1103
parameters ``os`` (OS template name) and ``nostartup`` (bool). New
1104
clients should use the body parameters.
1105

    
1106

    
1107
``/2/instances/[instance_name]/replace-disks``
1108
++++++++++++++++++++++++++++++++++++++++++++++
1109

    
1110
Replaces disks on an instance.
1111

    
1112
It supports the following commands: ``POST``.
1113

    
1114
``POST``
1115
~~~~~~~~
1116

    
1117
Returns a job ID.
1118

    
1119
Body parameters:
1120

    
1121
.. opcode_params:: OP_INSTANCE_REPLACE_DISKS
1122
   :exclude: instance_name
1123

    
1124
Ganeti 2.4 and below used query parameters. Those are deprecated and
1125
should no longer be used.
1126

    
1127
Job result:
1128

    
1129
.. opcode_result:: OP_INSTANCE_REPLACE_DISKS
1130

    
1131

    
1132
``/2/instances/[instance_name]/activate-disks``
1133
+++++++++++++++++++++++++++++++++++++++++++++++
1134

    
1135
Activate disks on an instance.
1136

    
1137
It supports the following commands: ``PUT``.
1138

    
1139
``PUT``
1140
~~~~~~~
1141

    
1142
Takes the bool parameter ``ignore_size``. When set ignore the recorded
1143
size (useful for forcing activation when recorded size is wrong).
1144

    
1145
Job result:
1146

    
1147
.. opcode_result:: OP_INSTANCE_ACTIVATE_DISKS
1148

    
1149

    
1150
``/2/instances/[instance_name]/deactivate-disks``
1151
+++++++++++++++++++++++++++++++++++++++++++++++++
1152

    
1153
Deactivate disks on an instance.
1154

    
1155
It supports the following commands: ``PUT``.
1156

    
1157
``PUT``
1158
~~~~~~~
1159

    
1160
Takes no parameters.
1161

    
1162
Job result:
1163

    
1164
.. opcode_result:: OP_INSTANCE_DEACTIVATE_DISKS
1165

    
1166

    
1167
``/2/instances/[instance_name]/recreate-disks``
1168
+++++++++++++++++++++++++++++++++++++++++++++++++
1169

    
1170
Recreate disks of an instance. Supports the following commands:
1171
``POST``.
1172

    
1173
``POST``
1174
~~~~~~~~
1175

    
1176
Returns a job ID.
1177

    
1178
Body parameters:
1179

    
1180
.. opcode_params:: OP_INSTANCE_RECREATE_DISKS
1181
   :exclude: instance_name
1182

    
1183
Job result:
1184

    
1185
.. opcode_result:: OP_INSTANCE_RECREATE_DISKS
1186

    
1187

    
1188
``/2/instances/[instance_name]/disk/[disk_index]/grow``
1189
+++++++++++++++++++++++++++++++++++++++++++++++++++++++
1190

    
1191
Grows one disk of an instance.
1192

    
1193
Supports the following commands: ``POST``.
1194

    
1195
``POST``
1196
~~~~~~~~
1197

    
1198
Returns a job ID.
1199

    
1200
Body parameters:
1201

    
1202
.. opcode_params:: OP_INSTANCE_GROW_DISK
1203
   :exclude: instance_name, disk
1204

    
1205
Job result:
1206

    
1207
.. opcode_result:: OP_INSTANCE_GROW_DISK
1208

    
1209

    
1210
``/2/instances/[instance_name]/prepare-export``
1211
+++++++++++++++++++++++++++++++++++++++++++++++++
1212

    
1213
Prepares an export of an instance.
1214

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

    
1217
``PUT``
1218
~~~~~~~
1219

    
1220
Takes one parameter, ``mode``, for the export mode. Returns a job ID.
1221

    
1222
Job result:
1223

    
1224
.. opcode_result:: OP_BACKUP_PREPARE
1225

    
1226

    
1227
``/2/instances/[instance_name]/export``
1228
+++++++++++++++++++++++++++++++++++++++++++++++++
1229

    
1230
Exports an instance.
1231

    
1232
It supports the following commands: ``PUT``.
1233

    
1234
``PUT``
1235
~~~~~~~
1236

    
1237
Returns a job ID.
1238

    
1239
Body parameters:
1240

    
1241
.. opcode_params:: OP_BACKUP_EXPORT
1242
   :exclude: instance_name
1243
   :alias: target_node=destination
1244

    
1245
Job result:
1246

    
1247
.. opcode_result:: OP_BACKUP_EXPORT
1248

    
1249

    
1250
``/2/instances/[instance_name]/migrate``
1251
++++++++++++++++++++++++++++++++++++++++
1252

    
1253
Migrates an instance.
1254

    
1255
Supports the following commands: ``PUT``.
1256

    
1257
``PUT``
1258
~~~~~~~
1259

    
1260
Returns a job ID.
1261

    
1262
Body parameters:
1263

    
1264
.. opcode_params:: OP_INSTANCE_MIGRATE
1265
   :exclude: instance_name, live
1266

    
1267
Job result:
1268

    
1269
.. opcode_result:: OP_INSTANCE_MIGRATE
1270

    
1271

    
1272
``/2/instances/[instance_name]/failover``
1273
+++++++++++++++++++++++++++++++++++++++++
1274

    
1275
Does a failover of an instance.
1276

    
1277
Supports the following commands: ``PUT``.
1278

    
1279
``PUT``
1280
~~~~~~~
1281

    
1282
Returns a job ID.
1283

    
1284
Body parameters:
1285

    
1286
.. opcode_params:: OP_INSTANCE_FAILOVER
1287
   :exclude: instance_name
1288

    
1289
Job result:
1290

    
1291
.. opcode_result:: OP_INSTANCE_FAILOVER
1292

    
1293

    
1294
``/2/instances/[instance_name]/rename``
1295
++++++++++++++++++++++++++++++++++++++++
1296

    
1297
Renames an instance.
1298

    
1299
Supports the following commands: ``PUT``.
1300

    
1301
``PUT``
1302
~~~~~~~
1303

    
1304
Returns a job ID.
1305

    
1306
Body parameters:
1307

    
1308
.. opcode_params:: OP_INSTANCE_RENAME
1309
   :exclude: instance_name
1310

    
1311
Job result:
1312

    
1313
.. opcode_result:: OP_INSTANCE_RENAME
1314

    
1315

    
1316
``/2/instances/[instance_name]/modify``
1317
++++++++++++++++++++++++++++++++++++++++
1318

    
1319
Modifies an instance.
1320

    
1321
Supports the following commands: ``PUT``.
1322

    
1323
``PUT``
1324
~~~~~~~
1325

    
1326
Returns a job ID.
1327

    
1328
Body parameters:
1329

    
1330
.. opcode_params:: OP_INSTANCE_SET_PARAMS
1331
   :exclude: instance_name
1332

    
1333
Job result:
1334

    
1335
.. opcode_result:: OP_INSTANCE_SET_PARAMS
1336

    
1337

    
1338
``/2/instances/[instance_name]/console``
1339
++++++++++++++++++++++++++++++++++++++++
1340

    
1341
Request information for connecting to instance's console.
1342

    
1343
.. pyassert::
1344

    
1345
  not (hasattr(rlib2.R_2_instances_name_console, "PUT") or
1346
       hasattr(rlib2.R_2_instances_name_console, "POST") or
1347
       hasattr(rlib2.R_2_instances_name_console, "DELETE"))
1348

    
1349
Supports the following commands: ``GET``. Requires authentication with
1350
one of the following options:
1351
:pyeval:`utils.CommaJoin(rlib2.R_2_instances_name_console.GET_ACCESS)`.
1352

    
1353
``GET``
1354
~~~~~~~
1355

    
1356
Returns a dictionary containing information about the instance's
1357
console. Contained keys:
1358

    
1359
.. pyassert::
1360

    
1361
   constants.CONS_ALL == frozenset([
1362
     constants.CONS_MESSAGE,
1363
     constants.CONS_SSH,
1364
     constants.CONS_VNC,
1365
     constants.CONS_SPICE,
1366
     ])
1367

    
1368
``instance``
1369
  Instance name
1370
``kind``
1371
  Console type, one of :pyeval:`constants.CONS_SSH`,
1372
  :pyeval:`constants.CONS_VNC`, :pyeval:`constants.CONS_SPICE`
1373
  or :pyeval:`constants.CONS_MESSAGE`
1374
``message``
1375
  Message to display (:pyeval:`constants.CONS_MESSAGE` type only)
1376
``host``
1377
  Host to connect to (:pyeval:`constants.CONS_SSH`,
1378
  :pyeval:`constants.CONS_VNC` or :pyeval:`constants.CONS_SPICE` only)
1379
``port``
1380
  TCP port to connect to (:pyeval:`constants.CONS_VNC` or
1381
  :pyeval:`constants.CONS_SPICE` only)
1382
``user``
1383
  Username to use (:pyeval:`constants.CONS_SSH` only)
1384
``command``
1385
  Command to execute on machine (:pyeval:`constants.CONS_SSH` only)
1386
``display``
1387
  VNC display number (:pyeval:`constants.CONS_VNC` only)
1388

    
1389

    
1390
``/2/instances/[instance_name]/tags``
1391
+++++++++++++++++++++++++++++++++++++
1392

    
1393
Manages per-instance tags.
1394

    
1395
It supports the following commands: ``GET``, ``PUT``, ``DELETE``.
1396

    
1397
``GET``
1398
~~~~~~~
1399

    
1400
Returns a list of tags.
1401

    
1402
Example::
1403

    
1404
    ["tag1", "tag2", "tag3"]
1405

    
1406
``PUT``
1407
~~~~~~~
1408

    
1409
Add a set of tags.
1410

    
1411
The request as a list of strings should be ``PUT`` to this URI. The
1412
result will be a job id.
1413

    
1414
It supports the ``dry-run`` argument.
1415

    
1416

    
1417
``DELETE``
1418
~~~~~~~~~~
1419

    
1420
Delete a tag.
1421

    
1422
In order to delete a set of tags, the DELETE request should be addressed
1423
to URI like::
1424

    
1425
    /tags?tag=[tag]&tag=[tag]
1426

    
1427
It supports the ``dry-run`` argument.
1428

    
1429

    
1430
``/2/jobs``
1431
+++++++++++
1432

    
1433
The ``/2/jobs`` resource.
1434

    
1435
It supports the following commands: ``GET``.
1436

    
1437
``GET``
1438
~~~~~~~
1439

    
1440
Returns a dictionary of jobs.
1441

    
1442
Returns: a dictionary with jobs id and uri.
1443

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

    
1448
Returned fields for bulk requests (unlike other bulk requests, these
1449
fields are not the same as for per-job requests):
1450
:pyeval:`utils.CommaJoin(sorted(rlib2.J_FIELDS_BULK))`.
1451

    
1452
``/2/jobs/[job_id]``
1453
++++++++++++++++++++
1454

    
1455

    
1456
Individual job URI.
1457

    
1458
It supports the following commands: ``GET``, ``DELETE``.
1459

    
1460
``GET``
1461
~~~~~~~
1462

    
1463
Returns a dictionary with job parameters, containing the fields
1464
:pyeval:`utils.CommaJoin(sorted(rlib2.J_FIELDS))`.
1465

    
1466
The result includes:
1467

    
1468
- id: job ID as a number
1469
- status: current job status as a string
1470
- ops: involved OpCodes as a list of dictionaries for each opcodes in
1471
  the job
1472
- opstatus: OpCodes status as a list
1473
- opresult: OpCodes results as a list
1474

    
1475
For a successful opcode, the ``opresult`` field corresponding to it will
1476
contain the raw result from its :term:`LogicalUnit`. In case an opcode
1477
has failed, its element in the opresult list will be a list of two
1478
elements:
1479

    
1480
- first element the error type (the Ganeti internal error name)
1481
- second element a list of either one or two elements:
1482

    
1483
  - the first element is the textual error description
1484
  - the second element, if any, will hold an error classification
1485

    
1486
The error classification is most useful for the ``OpPrereqError``
1487
error type - these errors happen before the OpCode has started
1488
executing, so it's possible to retry the OpCode without side
1489
effects. But whether it make sense to retry depends on the error
1490
classification:
1491

    
1492
.. pyassert::
1493

    
1494
   errors.ECODE_ALL == set([errors.ECODE_RESOLVER, errors.ECODE_NORES,
1495
     errors.ECODE_INVAL, errors.ECODE_STATE, errors.ECODE_NOENT,
1496
     errors.ECODE_EXISTS, errors.ECODE_NOTUNIQUE, errors.ECODE_FAULT,
1497
     errors.ECODE_ENVIRON])
1498

    
1499
:pyeval:`errors.ECODE_RESOLVER`
1500
  Resolver errors. This usually means that a name doesn't exist in DNS,
1501
  so if it's a case of slow DNS propagation the operation can be retried
1502
  later.
1503

    
1504
:pyeval:`errors.ECODE_NORES`
1505
  Not enough resources (iallocator failure, disk space, memory,
1506
  etc.). If the resources on the cluster increase, the operation might
1507
  succeed.
1508

    
1509
:pyeval:`errors.ECODE_INVAL`
1510
  Wrong arguments (at syntax level). The operation will not ever be
1511
  accepted unless the arguments change.
1512

    
1513
:pyeval:`errors.ECODE_STATE`
1514
  Wrong entity state. For example, live migration has been requested for
1515
  a down instance, or instance creation on an offline node. The
1516
  operation can be retried once the resource has changed state.
1517

    
1518
:pyeval:`errors.ECODE_NOENT`
1519
  Entity not found. For example, information has been requested for an
1520
  unknown instance.
1521

    
1522
:pyeval:`errors.ECODE_EXISTS`
1523
  Entity already exists. For example, instance creation has been
1524
  requested for an already-existing instance.
1525

    
1526
:pyeval:`errors.ECODE_NOTUNIQUE`
1527
  Resource not unique (e.g. MAC or IP duplication).
1528

    
1529
:pyeval:`errors.ECODE_FAULT`
1530
  Internal cluster error. For example, a node is unreachable but not set
1531
  offline, or the ganeti node daemons are not working, etc. A
1532
  ``gnt-cluster verify`` should be run.
1533

    
1534
:pyeval:`errors.ECODE_ENVIRON`
1535
  Environment error (e.g. node disk error). A ``gnt-cluster verify``
1536
  should be run.
1537

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

    
1541

    
1542
``DELETE``
1543
~~~~~~~~~~
1544

    
1545
Cancel a not-yet-started job.
1546

    
1547

    
1548
``/2/jobs/[job_id]/wait``
1549
+++++++++++++++++++++++++
1550

    
1551
``GET``
1552
~~~~~~~
1553

    
1554
Waits for changes on a job. Takes the following body parameters in a
1555
dict:
1556

    
1557
``fields``
1558
  The job fields on which to watch for changes
1559

    
1560
``previous_job_info``
1561
  Previously received field values or None if not yet available
1562

    
1563
``previous_log_serial``
1564
  Highest log serial number received so far or None if not yet
1565
  available
1566

    
1567
Returns None if no changes have been detected and a dict with two keys,
1568
``job_info`` and ``log_entries`` otherwise.
1569

    
1570

    
1571
``/2/nodes``
1572
++++++++++++
1573

    
1574
Nodes resource.
1575

    
1576
It supports the following commands: ``GET``.
1577

    
1578
``GET``
1579
~~~~~~~
1580

    
1581
Returns a list of all nodes.
1582

    
1583
Example::
1584

    
1585
    [
1586
      {
1587
        "id": "node1.example.com",
1588
        "uri": "\/nodes\/node1.example.com"
1589
      },
1590
      {
1591
        "id": "node2.example.com",
1592
        "uri": "\/nodes\/node2.example.com"
1593
      }
1594
    ]
1595

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

    
1600
Returned fields: :pyeval:`utils.CommaJoin(sorted(rlib2.N_FIELDS))`.
1601

    
1602
Example::
1603

    
1604
    [
1605
      {
1606
        "pinst_cnt": 1,
1607
        "mfree": 31280,
1608
        "mtotal": 32763,
1609
        "name": "www.example.com",
1610
        "tags": [],
1611
        "mnode": 512,
1612
        "dtotal": 5246208,
1613
        "sinst_cnt": 2,
1614
        "dfree": 5171712,
1615
        "offline": false
1616
      },
1617
      ...
1618
    ]
1619

    
1620
``/2/nodes/[node_name]``
1621
+++++++++++++++++++++++++++++++++
1622

    
1623
Returns information about a node.
1624

    
1625
It supports the following commands: ``GET``.
1626

    
1627
Returned fields: :pyeval:`utils.CommaJoin(sorted(rlib2.N_FIELDS))`.
1628

    
1629
``/2/nodes/[node_name]/powercycle``
1630
+++++++++++++++++++++++++++++++++++
1631

    
1632
Powercycles a node. Supports the following commands: ``POST``.
1633

    
1634
``POST``
1635
~~~~~~~~
1636

    
1637
Returns a job ID.
1638

    
1639
Job result:
1640

    
1641
.. opcode_result:: OP_NODE_POWERCYCLE
1642

    
1643

    
1644
``/2/nodes/[node_name]/evacuate``
1645
+++++++++++++++++++++++++++++++++
1646

    
1647
Evacuates instances off a node.
1648

    
1649
It supports the following commands: ``POST``.
1650

    
1651
``POST``
1652
~~~~~~~~
1653

    
1654
Returns a job ID. The result of the job will contain the IDs of the
1655
individual jobs submitted to evacuate the node.
1656

    
1657
Body parameters:
1658

    
1659
.. opcode_params:: OP_NODE_EVACUATE
1660
   :exclude: nodes
1661

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

    
1666
Job result:
1667

    
1668
.. opcode_result:: OP_NODE_EVACUATE
1669

    
1670

    
1671
``/2/nodes/[node_name]/migrate``
1672
+++++++++++++++++++++++++++++++++
1673

    
1674
Migrates all primary instances from a node.
1675

    
1676
It supports the following commands: ``POST``.
1677

    
1678
``POST``
1679
~~~~~~~~
1680

    
1681
If no mode is explicitly specified, each instances' hypervisor default
1682
migration mode will be used. Body parameters:
1683

    
1684
.. opcode_params:: OP_NODE_MIGRATE
1685
   :exclude: node_name
1686

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

    
1691
Job result:
1692

    
1693
.. opcode_result:: OP_NODE_MIGRATE
1694

    
1695

    
1696
``/2/nodes/[node_name]/role``
1697
+++++++++++++++++++++++++++++
1698

    
1699
Manages node role.
1700

    
1701
It supports the following commands: ``GET``, ``PUT``.
1702

    
1703
The role is always one of the following:
1704

    
1705
  - drained
1706
  - master-candidate
1707
  - offline
1708
  - regular
1709

    
1710
Note that the 'master' role is a special, and currently it can't be
1711
modified via RAPI, only via the command line (``gnt-cluster
1712
master-failover``).
1713

    
1714
``GET``
1715
~~~~~~~
1716

    
1717
Returns the current node role.
1718

    
1719
Example::
1720

    
1721
    "master-candidate"
1722

    
1723
``PUT``
1724
~~~~~~~
1725

    
1726
Change the node role.
1727

    
1728
The request is a string which should be PUT to this URI. The result will
1729
be a job id.
1730

    
1731
It supports the bool ``force`` argument.
1732

    
1733
Job result:
1734

    
1735
.. opcode_result:: OP_NODE_SET_PARAMS
1736

    
1737

    
1738
``/2/nodes/[node_name]/modify``
1739
+++++++++++++++++++++++++++++++
1740

    
1741
Modifies the parameters of a node. Supports the following commands:
1742
``POST``.
1743

    
1744
``POST``
1745
~~~~~~~~
1746

    
1747
Returns a job ID.
1748

    
1749
Body parameters:
1750

    
1751
.. opcode_params:: OP_NODE_SET_PARAMS
1752
   :exclude: node_name
1753

    
1754
Job result:
1755

    
1756
.. opcode_result:: OP_NODE_SET_PARAMS
1757

    
1758

    
1759
``/2/nodes/[node_name]/storage``
1760
++++++++++++++++++++++++++++++++
1761

    
1762
Manages storage units on the node.
1763

    
1764
``GET``
1765
~~~~~~~
1766

    
1767
.. pyassert::
1768

    
1769
   constants.VALID_STORAGE_TYPES == set([constants.ST_FILE,
1770
                                         constants.ST_LVM_PV,
1771
                                         constants.ST_LVM_VG])
1772

    
1773
Requests a list of storage units on a node. Requires the parameters
1774
``storage_type`` (one of :pyeval:`constants.ST_FILE`,
1775
:pyeval:`constants.ST_LVM_PV` or :pyeval:`constants.ST_LVM_VG`) and
1776
``output_fields``. The result will be a job id, using which the result
1777
can be retrieved.
1778

    
1779
``/2/nodes/[node_name]/storage/modify``
1780
+++++++++++++++++++++++++++++++++++++++
1781

    
1782
Modifies storage units on the node.
1783

    
1784
``PUT``
1785
~~~~~~~
1786

    
1787
Modifies parameters of storage units on the node. Requires the
1788
parameters ``storage_type`` (one of :pyeval:`constants.ST_FILE`,
1789
:pyeval:`constants.ST_LVM_PV` or :pyeval:`constants.ST_LVM_VG`)
1790
and ``name`` (name of the storage unit).  Parameters can be passed
1791
additionally. Currently only :pyeval:`constants.SF_ALLOCATABLE` (bool)
1792
is supported. The result will be a job id.
1793

    
1794
Job result:
1795

    
1796
.. opcode_result:: OP_NODE_MODIFY_STORAGE
1797

    
1798

    
1799
``/2/nodes/[node_name]/storage/repair``
1800
+++++++++++++++++++++++++++++++++++++++
1801

    
1802
Repairs a storage unit on the node.
1803

    
1804
``PUT``
1805
~~~~~~~
1806

    
1807
.. pyassert::
1808

    
1809
   constants.VALID_STORAGE_OPERATIONS == {
1810
    constants.ST_LVM_VG: set([constants.SO_FIX_CONSISTENCY]),
1811
    }
1812

    
1813
Repairs a storage unit on the node. Requires the parameters
1814
``storage_type`` (currently only :pyeval:`constants.ST_LVM_VG` can be
1815
repaired) and ``name`` (name of the storage unit). The result will be a
1816
job id.
1817

    
1818
Job result:
1819

    
1820
.. opcode_result:: OP_REPAIR_NODE_STORAGE
1821

    
1822

    
1823
``/2/nodes/[node_name]/tags``
1824
+++++++++++++++++++++++++++++
1825

    
1826
Manages per-node tags.
1827

    
1828
It supports the following commands: ``GET``, ``PUT``, ``DELETE``.
1829

    
1830
``GET``
1831
~~~~~~~
1832

    
1833
Returns a list of tags.
1834

    
1835
Example::
1836

    
1837
    ["tag1", "tag2", "tag3"]
1838

    
1839
``PUT``
1840
~~~~~~~
1841

    
1842
Add a set of tags.
1843

    
1844
The request as a list of strings should be PUT to this URI. The result
1845
will be a job id.
1846

    
1847
It supports the ``dry-run`` argument.
1848

    
1849
``DELETE``
1850
~~~~~~~~~~
1851

    
1852
Deletes tags.
1853

    
1854
In order to delete a set of tags, the DELETE request should be addressed
1855
to URI like::
1856

    
1857
    /tags?tag=[tag]&tag=[tag]
1858

    
1859
It supports the ``dry-run`` argument.
1860

    
1861

    
1862
``/2/query/[resource]``
1863
+++++++++++++++++++++++
1864

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

    
1870
.. pyassert::
1871

    
1872
  (rlib2.R_2_query.GET_ACCESS == rlib2.R_2_query.PUT_ACCESS and
1873
   not (hasattr(rlib2.R_2_query, "POST") or
1874
        hasattr(rlib2.R_2_query, "DELETE")))
1875

    
1876
Supports the following commands: ``GET``, ``PUT``. Requires
1877
authentication with one of the following options:
1878
:pyeval:`utils.CommaJoin(rlib2.R_2_query.GET_ACCESS)`.
1879

    
1880
``GET``
1881
~~~~~~~
1882

    
1883
Returns list of included fields and actual data. Takes a query parameter
1884
named "fields", containing a comma-separated list of field names. Does
1885
not support filtering.
1886

    
1887
``PUT``
1888
~~~~~~~
1889

    
1890
Returns list of included fields and actual data. The list of requested
1891
fields can either be given as the query parameter "fields" or as a body
1892
parameter with the same name. The optional body parameter "filter" can
1893
be given and must be either ``null`` or a list containing filter
1894
operators.
1895

    
1896

    
1897
``/2/query/[resource]/fields``
1898
++++++++++++++++++++++++++++++
1899

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

    
1904
Supports the following commands: ``GET``.
1905

    
1906
``GET``
1907
~~~~~~~
1908

    
1909
Returns a list of field descriptions for available fields. Takes an
1910
optional query parameter named "fields", containing a comma-separated
1911
list of field names.
1912

    
1913

    
1914
``/2/os``
1915
+++++++++
1916

    
1917
OS resource.
1918

    
1919
It supports the following commands: ``GET``.
1920

    
1921
``GET``
1922
~~~~~~~
1923

    
1924
Return a list of all OSes.
1925

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

    
1929
Example::
1930

    
1931
    ["debian-etch"]
1932

    
1933
``/2/tags``
1934
+++++++++++
1935

    
1936
Manages cluster tags.
1937

    
1938
It supports the following commands: ``GET``, ``PUT``, ``DELETE``.
1939

    
1940
``GET``
1941
~~~~~~~
1942

    
1943
Returns the cluster tags.
1944

    
1945
Example::
1946

    
1947
    ["tag1", "tag2", "tag3"]
1948

    
1949
``PUT``
1950
~~~~~~~
1951

    
1952
Adds a set of tags.
1953

    
1954
The request as a list of strings should be PUT to this URI. The result
1955
will be a job id.
1956

    
1957
It supports the ``dry-run`` argument.
1958

    
1959

    
1960
``DELETE``
1961
~~~~~~~~~~
1962

    
1963
Deletes tags.
1964

    
1965
In order to delete a set of tags, the DELETE request should be addressed
1966
to URI like::
1967

    
1968
    /tags?tag=[tag]&tag=[tag]
1969

    
1970
It supports the ``dry-run`` argument.
1971

    
1972

    
1973
``/version``
1974
++++++++++++
1975

    
1976
The version resource.
1977

    
1978
This resource should be used to determine the remote API version and to
1979
adapt clients accordingly.
1980

    
1981
It supports the following commands: ``GET``.
1982

    
1983
``GET``
1984
~~~~~~~
1985

    
1986
Returns the remote API version. Ganeti 1.2 returned ``1`` and Ganeti 2.0
1987
returns ``2``.
1988

    
1989
.. vim: set textwidth=72 :
1990
.. Local Variables:
1991
.. mode: rst
1992
.. fill-column: 72
1993
.. End: