Statistics
| Branch: | Tag: | Revision:

root / doc / rapi.rst @ da1168c5

History | View | Annotate | Download (40.9 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
Parameter details
170
-----------------
171

    
172
Some parameters are not straight forward, so we describe them in details
173
here.
174

    
175
.. _rapi-ipolicy:
176

    
177
``ipolicy``
178
+++++++++++
179

    
180
The instance policy specification is a dict with the following fields:
181

    
182
.. pyassert::
183

    
184
  constants.IPOLICY_ALL_KEYS == set([constants.ISPECS_MIN,
185
                                     constants.ISPECS_MAX,
186
                                     constants.ISPECS_STD,
187
                                     constants.IPOLICY_DTS,
188
                                     constants.IPOLICY_VCPU_RATIO,
189
                                     constants.IPOLICY_SPINDLE_RATIO])
190

    
191

    
192
.. pyassert::
193

    
194
  (set(constants.ISPECS_PARAMETER_TYPES.keys()) ==
195
   set([constants.ISPEC_MEM_SIZE,
196
        constants.ISPEC_DISK_SIZE,
197
        constants.ISPEC_DISK_COUNT,
198
        constants.ISPEC_CPU_COUNT,
199
        constants.ISPEC_NIC_COUNT,
200
        constants.ISPEC_SPINDLE_USE]))
201

    
202
.. |ispec-min| replace:: :pyeval:`constants.ISPECS_MIN`
203
.. |ispec-max| replace:: :pyeval:`constants.ISPECS_MAX`
204
.. |ispec-std| replace:: :pyeval:`constants.ISPECS_STD`
205

    
206

    
207
|ispec-min|, |ispec-max|, |ispec-std|
208
  A sub- `dict` with the following fields, which sets the limit and standard
209
  values of the instances:
210

    
211
  :pyeval:`constants.ISPEC_MEM_SIZE`
212
    The size in MiB of the memory used
213
  :pyeval:`constants.ISPEC_DISK_SIZE`
214
    The size in MiB of the disk used
215
  :pyeval:`constants.ISPEC_DISK_COUNT`
216
    The numbers of disks used
217
  :pyeval:`constants.ISPEC_CPU_COUNT`
218
    The numbers of cpus used
219
  :pyeval:`constants.ISPEC_NIC_COUNT`
220
    The numbers of nics used
221
  :pyeval:`constants.ISPEC_SPINDLE_USE`
222
    The numbers of virtual disk spindles used by this instance. They are
223
    not real in the sense of actual HDD spindles, but useful for
224
    accounting the spindle usage on the residing node
225
:pyeval:`constants.IPOLICY_DTS`
226
  A `list` of disk templates allowed for instances using this policy
227
:pyeval:`constants.IPOLICY_VCPU_RATIO`
228
  Maximum ratio of virtual to physical CPUs (`float`)
229
:pyeval:`constants.IPOLICY_SPINDLE_RATIO`
230
  Maximum ratio of instances to their node's ``spindle_count`` (`float`)
231

    
232
Usage examples
233
--------------
234

    
235
You can access the API using your favorite programming language as long
236
as it supports network connections.
237

    
238
Ganeti RAPI client
239
++++++++++++++++++
240

    
241
Ganeti includes a standalone RAPI client, ``lib/rapi/client.py``.
242

    
243
Shell
244
+++++
245

    
246
.. highlight:: sh
247

    
248
Using wget::
249

    
250
   wget -q -O - https://CLUSTERNAME:5080/2/info
251

    
252
or curl::
253

    
254
  curl https://CLUSTERNAME:5080/2/info
255

    
256

    
257
Python
258
++++++
259

    
260
.. highlight:: python
261

    
262
::
263

    
264
  import urllib2
265
  f = urllib2.urlopen('https://CLUSTERNAME:5080/2/info')
266
  print f.read()
267

    
268

    
269
JavaScript
270
++++++++++
271

    
272
.. warning:: While it's possible to use JavaScript, it poses several
273
   potential problems, including browser blocking request due to
274
   non-standard ports or different domain names. Fetching the data on
275
   the webserver is easier.
276

    
277
.. highlight:: javascript
278

    
279
::
280

    
281
  var url = 'https://CLUSTERNAME:5080/2/info';
282
  var info;
283
  var xmlreq = new XMLHttpRequest();
284
  xmlreq.onreadystatechange = function () {
285
    if (xmlreq.readyState != 4) return;
286
    if (xmlreq.status == 200) {
287
      info = eval("(" + xmlreq.responseText + ")");
288
      alert(info);
289
    } else {
290
      alert('Error fetching cluster info');
291
    }
292
    xmlreq = null;
293
  };
294
  xmlreq.open('GET', url, true);
295
  xmlreq.send(null);
296

    
297
Resources
298
---------
299

    
300
.. highlight:: javascript
301

    
302
``/``
303
+++++
304

    
305
The root resource. Has no function, but for legacy reasons the ``GET``
306
method is supported.
307

    
308
``/2``
309
++++++
310

    
311
Has no function, but for legacy reasons the ``GET`` method is supported.
312

    
313
``/2/info``
314
+++++++++++
315

    
316
Cluster information resource.
317

    
318
It supports the following commands: ``GET``.
319

    
320
``GET``
321
~~~~~~~
322

    
323
Returns cluster information.
324

    
325
Example::
326

    
327
  {
328
    "config_version": 2000000,
329
    "name": "cluster",
330
    "software_version": "2.0.0~beta2",
331
    "os_api_version": 10,
332
    "export_version": 0,
333
    "candidate_pool_size": 10,
334
    "enabled_hypervisors": [
335
      "fake"
336
    ],
337
    "hvparams": {
338
      "fake": {}
339
     },
340
    "default_hypervisor": "fake",
341
    "master": "node1.example.com",
342
    "architecture": [
343
      "64bit",
344
      "x86_64"
345
    ],
346
    "protocol_version": 20,
347
    "beparams": {
348
      "default": {
349
        "auto_balance": true,
350
        "vcpus": 1,
351
        "memory": 128
352
       }
353
      }
354
    }
355

    
356

    
357
``/2/redistribute-config``
358
++++++++++++++++++++++++++
359

    
360
Redistribute configuration to all nodes.
361

    
362
It supports the following commands: ``PUT``.
363

    
364
``PUT``
365
~~~~~~~
366

    
367
Redistribute configuration to all nodes. The result will be a job id.
368

    
369
Job result:
370

    
371
.. opcode_result:: OP_CLUSTER_REDIST_CONF
372

    
373

    
374
``/2/features``
375
+++++++++++++++
376

    
377
``GET``
378
~~~~~~~
379

    
380
Returns a list of features supported by the RAPI server. Available
381
features:
382

    
383
.. pyassert::
384

    
385
  rlib2.ALL_FEATURES == set([rlib2._INST_CREATE_REQV1,
386
                             rlib2._INST_REINSTALL_REQV1,
387
                             rlib2._NODE_MIGRATE_REQV1,
388
                             rlib2._NODE_EVAC_RES1])
389

    
390
:pyeval:`rlib2._INST_CREATE_REQV1`
391
  Instance creation request data version 1 supported
392
:pyeval:`rlib2._INST_REINSTALL_REQV1`
393
  Instance reinstall supports body parameters
394
:pyeval:`rlib2._NODE_MIGRATE_REQV1`
395
  Whether migrating a node (``/2/nodes/[node_name]/migrate``) supports
396
  request body parameters
397
:pyeval:`rlib2._NODE_EVAC_RES1`
398
  Whether evacuating a node (``/2/nodes/[node_name]/evacuate``) returns
399
  a new-style result (see resource description)
400

    
401

    
402
``/2/modify``
403
++++++++++++++++++++++++++++++++++++++++
404

    
405
Modifies cluster parameters.
406

    
407
Supports the following commands: ``PUT``.
408

    
409
``PUT``
410
~~~~~~~
411

    
412
Returns a job ID.
413

    
414
Body parameters:
415

    
416
.. opcode_params:: OP_CLUSTER_SET_PARAMS
417

    
418
Job result:
419

    
420
.. opcode_result:: OP_CLUSTER_SET_PARAMS
421

    
422

    
423
``/2/groups``
424
+++++++++++++
425

    
426
The groups resource.
427

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

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

    
433
Returns a list of all existing node groups.
434

    
435
Example::
436

    
437
    [
438
      {
439
        "name": "group1",
440
        "uri": "\/2\/groups\/group1"
441
      },
442
      {
443
        "name": "group2",
444
        "uri": "\/2\/groups\/group2"
445
      }
446
    ]
447

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

    
452
Returned fields: :pyeval:`utils.CommaJoin(sorted(rlib2.G_FIELDS))`.
453

    
454
Example::
455

    
456
    [
457
      {
458
        "name": "group1",
459
        "node_cnt": 2,
460
        "node_list": [
461
          "node1.example.com",
462
          "node2.example.com"
463
        ],
464
        "uuid": "0d7d407c-262e-49af-881a-6a430034bf43"
465
      },
466
      {
467
        "name": "group2",
468
        "node_cnt": 1,
469
        "node_list": [
470
          "node3.example.com"
471
        ],
472
        "uuid": "f5a277e7-68f9-44d3-a378-4b25ecb5df5c"
473
      }
474
    ]
475

    
476
``POST``
477
~~~~~~~~
478

    
479
Creates a node group.
480

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

    
484
Returns: a job ID that can be used later for polling.
485

    
486
Body parameters:
487

    
488
.. opcode_params:: OP_GROUP_ADD
489

    
490
Earlier versions used a parameter named ``name`` which, while still
491
supported, has been renamed to ``group_name``.
492

    
493
Job result:
494

    
495
.. opcode_result:: OP_GROUP_ADD
496

    
497

    
498
``/2/groups/[group_name]``
499
++++++++++++++++++++++++++
500

    
501
Returns information about a node group.
502

    
503
It supports the following commands: ``GET``, ``DELETE``.
504

    
505
``GET``
506
~~~~~~~
507

    
508
Returns information about a node group, similar to the bulk output from
509
the node group list.
510

    
511
Returned fields: :pyeval:`utils.CommaJoin(sorted(rlib2.G_FIELDS))`.
512

    
513
``DELETE``
514
~~~~~~~~~~
515

    
516
Deletes a node group.
517

    
518
It supports the ``dry-run`` argument.
519

    
520
Job result:
521

    
522
.. opcode_result:: OP_GROUP_REMOVE
523

    
524

    
525
``/2/groups/[group_name]/modify``
526
+++++++++++++++++++++++++++++++++
527

    
528
Modifies the parameters of a node group.
529

    
530
Supports the following commands: ``PUT``.
531

    
532
``PUT``
533
~~~~~~~
534

    
535
Returns a job ID.
536

    
537
Body parameters:
538

    
539
.. opcode_params:: OP_GROUP_SET_PARAMS
540
   :exclude: group_name
541

    
542
Job result:
543

    
544
.. opcode_result:: OP_GROUP_SET_PARAMS
545

    
546

    
547
``/2/groups/[group_name]/rename``
548
+++++++++++++++++++++++++++++++++
549

    
550
Renames a node group.
551

    
552
Supports the following commands: ``PUT``.
553

    
554
``PUT``
555
~~~~~~~
556

    
557
Returns a job ID.
558

    
559
Body parameters:
560

    
561
.. opcode_params:: OP_GROUP_RENAME
562
   :exclude: group_name
563

    
564
Job result:
565

    
566
.. opcode_result:: OP_GROUP_RENAME
567

    
568

    
569
``/2/groups/[group_name]/assign-nodes``
570
+++++++++++++++++++++++++++++++++++++++
571

    
572
Assigns nodes to a group.
573

    
574
Supports the following commands: ``PUT``.
575

    
576
``PUT``
577
~~~~~~~
578

    
579
Returns a job ID. It supports the ``dry-run`` and ``force`` arguments.
580

    
581
Body parameters:
582

    
583
.. opcode_params:: OP_GROUP_ASSIGN_NODES
584
   :exclude: group_name, force, dry_run
585

    
586
Job result:
587

    
588
.. opcode_result:: OP_GROUP_ASSIGN_NODES
589

    
590

    
591
``/2/groups/[group_name]/tags``
592
+++++++++++++++++++++++++++++++
593

    
594
Manages per-nodegroup tags.
595

    
596
Supports the following commands: ``GET``, ``PUT``, ``DELETE``.
597

    
598
``GET``
599
~~~~~~~
600

    
601
Returns a list of tags.
602

    
603
Example::
604

    
605
    ["tag1", "tag2", "tag3"]
606

    
607
``PUT``
608
~~~~~~~
609

    
610
Add a set of tags.
611

    
612
The request as a list of strings should be ``PUT`` to this URI. The
613
result will be a job id.
614

    
615
It supports the ``dry-run`` argument.
616

    
617

    
618
``DELETE``
619
~~~~~~~~~~
620

    
621
Delete a tag.
622

    
623
In order to delete a set of tags, the DELETE request should be addressed
624
to URI like::
625

    
626
    /tags?tag=[tag]&tag=[tag]
627

    
628
It supports the ``dry-run`` argument.
629

    
630

    
631
``/2/networks``
632
+++++++++++++++
633

    
634
The networks resource.
635

    
636
It supports the following commands: ``GET``, ``POST``.
637

    
638
``GET``
639
~~~~~~~
640

    
641
Returns a list of all existing networks.
642

    
643
Example::
644

    
645
    [
646
      {
647
        "name": "network1",
648
        "uri": "\/2\/networks\/network1"
649
      },
650
      {
651
        "name": "network2",
652
        "uri": "\/2\/networks\/network2"
653
      }
654
    ]
655

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

    
660
Returned fields: :pyeval:`utils.CommaJoin(sorted(rlib2.NET_FIELDS))`.
661

    
662
Example::
663

    
664
    [
665
      {
666
        'external_reservations': '10.0.0.0, 10.0.0.1, 10.0.0.15',
667
        'free_count': 13,
668
        'gateway': '10.0.0.1',
669
        'gateway6': None,
670
        'group_list': ['default(bridged, prv0)'],
671
        'inst_list': [],
672
        'mac_prefix': None,
673
        'map': 'XX.............X',
674
        'name': 'nat',
675
        'network': '10.0.0.0/28',
676
        'network6': None,
677
        'network_type': 'private',
678
        'reserved_count': 3,
679
        'tags': ['nfdhcpd']
680
      },
681
    ]
682

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

    
686
Creates a network.
687

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

    
691
Returns: a job ID that can be used later for polling.
692

    
693
Body parameters:
694

    
695
.. opcode_params:: OP_NETWORK_ADD
696

    
697
Job result:
698

    
699
.. opcode_result:: OP_NETWORK_ADD
700

    
701

    
702
``/2/networks/[network_name]``
703
++++++++++++++++++++++++++++++
704

    
705
Returns information about a network.
706

    
707
It supports the following commands: ``GET``, ``DELETE``.
708

    
709
``GET``
710
~~~~~~~
711

    
712
Returns information about a network, similar to the bulk output from
713
the network list.
714

    
715
Returned fields: :pyeval:`utils.CommaJoin(sorted(rlib2.NET_FIELDS))`.
716

    
717
``DELETE``
718
~~~~~~~~~~
719

    
720
Deletes a network.
721

    
722
It supports the ``dry-run`` argument.
723

    
724
Job result:
725

    
726
.. opcode_result:: OP_NETWORK_REMOVE
727

    
728

    
729
``/2/networks/[network_name]/modify``
730
+++++++++++++++++++++++++++++++++++++
731

    
732
Modifies the parameters of a network.
733

    
734
Supports the following commands: ``PUT``.
735

    
736
``PUT``
737
~~~~~~~
738

    
739
Returns a job ID.
740

    
741
Body parameters:
742

    
743
.. opcode_params:: OP_NETWORK_SET_PARAMS
744

    
745
Job result:
746

    
747
.. opcode_result:: OP_NETWORK_SET_PARAMS
748

    
749

    
750
``/2/networks/[network_name]/connect``
751
++++++++++++++++++++++++++++++++++++++
752

    
753
Connects a network to a nodegroup.
754

    
755
Supports the following commands: ``PUT``.
756

    
757
``PUT``
758
~~~~~~~
759

    
760
Returns a job ID. It supports the ``dry-run`` arguments.
761

    
762
Body parameters:
763

    
764
.. opcode_params:: OP_NETWORK_CONNECT
765

    
766
Job result:
767

    
768
.. opcode_result:: OP_NETWORK_CONNECT
769

    
770

    
771
``/2/networks/[network_name]/disconnect``
772
+++++++++++++++++++++++++++++++++++++++++
773

    
774
Disonnects a network from a nodegroup.
775

    
776
Supports the following commands: ``PUT``.
777

    
778
``PUT``
779
~~~~~~~
780

    
781
Returns a job ID. It supports the ``dry-run`` arguments.
782

    
783
Body parameters:
784

    
785
.. opcode_params:: OP_NETWORK_DISCONNECT
786

    
787
Job result:
788

    
789
.. opcode_result:: OP_NETWORK_DISCONNECT
790

    
791

    
792
``/2/networks/[network_name]/tags``
793
+++++++++++++++++++++++++++++++++++
794

    
795
Manages per-network tags.
796

    
797
Supports the following commands: ``GET``, ``PUT``, ``DELETE``.
798

    
799
``GET``
800
~~~~~~~
801

    
802
Returns a list of tags.
803

    
804
Example::
805

    
806
    ["tag1", "tag2", "tag3"]
807

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

    
811
Add a set of tags.
812

    
813
The request as a list of strings should be ``PUT`` to this URI. The
814
result will be a job id.
815

    
816
It supports the ``dry-run`` argument.
817

    
818

    
819
``DELETE``
820
~~~~~~~~~~
821

    
822
Delete a tag.
823

    
824
In order to delete a set of tags, the DELETE request should be addressed
825
to URI like::
826

    
827
    /tags?tag=[tag]&tag=[tag]
828

    
829
It supports the ``dry-run`` argument.
830

    
831

    
832
``/2/instances``
833
++++++++++++++++
834

    
835
The instances resource.
836

    
837
It supports the following commands: ``GET``, ``POST``.
838

    
839
``GET``
840
~~~~~~~
841

    
842
Returns a list of all available instances.
843

    
844
Example::
845

    
846
    [
847
      {
848
        "name": "web.example.com",
849
        "uri": "\/instances\/web.example.com"
850
      },
851
      {
852
        "name": "mail.example.com",
853
        "uri": "\/instances\/mail.example.com"
854
      }
855
    ]
856

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

    
861
Returned fields: :pyeval:`utils.CommaJoin(sorted(rlib2.I_FIELDS))`.
862

    
863
Example::
864

    
865
    [
866
      {
867
         "status": "running",
868
         "disk_usage": 20480,
869
         "nic.bridges": [
870
           "xen-br0"
871
          ],
872
         "name": "web.example.com",
873
         "tags": ["tag1", "tag2"],
874
         "beparams": {
875
           "vcpus": 2,
876
           "memory": 512
877
         },
878
         "disk.sizes": [
879
             20480
880
         ],
881
         "pnode": "node1.example.com",
882
         "nic.macs": ["01:23:45:67:89:01"],
883
         "snodes": ["node2.example.com"],
884
         "disk_template": "drbd",
885
         "admin_state": true,
886
         "os": "debian-etch",
887
         "oper_state": true
888
      },
889
      ...
890
    ]
891

    
892

    
893
``POST``
894
~~~~~~~~
895

    
896
Creates an instance.
897

    
898
If the optional bool *dry-run* argument is provided, the job will not be
899
actually executed, only the pre-execution checks will be done. Query-ing
900
the job result will return, in both dry-run and normal case, the list of
901
nodes selected for the instance.
902

    
903
Returns: a job ID that can be used later for polling.
904

    
905
Body parameters:
906

    
907
``__version__`` (int, required)
908
  Must be ``1`` (older Ganeti versions used a different format for
909
  instance creation requests, version ``0``, but that format is no
910
  longer supported)
911

    
912
.. opcode_params:: OP_INSTANCE_CREATE
913

    
914
Earlier versions used parameters named ``name`` and ``os``. These have
915
been replaced by ``instance_name`` and ``os_type`` to match the
916
underlying opcode. The old names can still be used.
917

    
918
Job result:
919

    
920
.. opcode_result:: OP_INSTANCE_CREATE
921

    
922

    
923
``/2/instances/[instance_name]``
924
++++++++++++++++++++++++++++++++
925

    
926
Instance-specific resource.
927

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

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

    
933
Returns information about an instance, similar to the bulk output from
934
the instance list.
935

    
936
Returned fields: :pyeval:`utils.CommaJoin(sorted(rlib2.I_FIELDS))`.
937

    
938
``DELETE``
939
~~~~~~~~~~
940

    
941
Deletes an instance.
942

    
943
It supports the ``dry-run`` argument.
944

    
945
Job result:
946

    
947
.. opcode_result:: OP_INSTANCE_REMOVE
948

    
949

    
950
``/2/instances/[instance_name]/info``
951
+++++++++++++++++++++++++++++++++++++++
952

    
953
It supports the following commands: ``GET``.
954

    
955
``GET``
956
~~~~~~~
957

    
958
Requests detailed information about the instance. An optional parameter,
959
``static`` (bool), can be set to return only static information from the
960
configuration without querying the instance's nodes. The result will be
961
a job id.
962

    
963
Job result:
964

    
965
.. opcode_result:: OP_INSTANCE_QUERY_DATA
966

    
967

    
968
``/2/instances/[instance_name]/reboot``
969
+++++++++++++++++++++++++++++++++++++++
970

    
971
Reboots URI for an instance.
972

    
973
It supports the following commands: ``POST``.
974

    
975
``POST``
976
~~~~~~~~
977

    
978
Reboots the instance.
979

    
980
The URI takes optional ``type=soft|hard|full`` and
981
``ignore_secondaries=0|1`` parameters.
982

    
983
``type`` defines the reboot type. ``soft`` is just a normal reboot,
984
without terminating the hypervisor. ``hard`` means full shutdown
985
(including terminating the hypervisor process) and startup again.
986
``full`` is like ``hard`` but also recreates the configuration from
987
ground up as if you would have done a ``gnt-instance shutdown`` and
988
``gnt-instance start`` on it.
989

    
990
``ignore_secondaries`` is a bool argument indicating if we start the
991
instance even if secondary disks are failing.
992

    
993
It supports the ``dry-run`` argument.
994

    
995
Job result:
996

    
997
.. opcode_result:: OP_INSTANCE_REBOOT
998

    
999

    
1000
``/2/instances/[instance_name]/shutdown``
1001
+++++++++++++++++++++++++++++++++++++++++
1002

    
1003
Instance shutdown URI.
1004

    
1005
It supports the following commands: ``PUT``.
1006

    
1007
``PUT``
1008
~~~~~~~
1009

    
1010
Shutdowns an instance.
1011

    
1012
It supports the ``dry-run`` argument.
1013

    
1014
.. opcode_params:: OP_INSTANCE_SHUTDOWN
1015
   :exclude: instance_name, dry_run
1016

    
1017
Job result:
1018

    
1019
.. opcode_result:: OP_INSTANCE_SHUTDOWN
1020

    
1021

    
1022
``/2/instances/[instance_name]/startup``
1023
++++++++++++++++++++++++++++++++++++++++
1024

    
1025
Instance startup URI.
1026

    
1027
It supports the following commands: ``PUT``.
1028

    
1029
``PUT``
1030
~~~~~~~
1031

    
1032
Startup an instance.
1033

    
1034
The URI takes an optional ``force=1|0`` parameter to start the
1035
instance even if secondary disks are failing.
1036

    
1037
It supports the ``dry-run`` argument.
1038

    
1039
Job result:
1040

    
1041
.. opcode_result:: OP_INSTANCE_STARTUP
1042

    
1043

    
1044
``/2/instances/[instance_name]/reinstall``
1045
++++++++++++++++++++++++++++++++++++++++++++++
1046

    
1047
Installs the operating system again.
1048

    
1049
It supports the following commands: ``POST``.
1050

    
1051
``POST``
1052
~~~~~~~~
1053

    
1054
Returns a job ID.
1055

    
1056
Body parameters:
1057

    
1058
``os`` (string, required)
1059
  Instance operating system.
1060
``start`` (bool, defaults to true)
1061
  Whether to start instance after reinstallation.
1062
``osparams`` (dict)
1063
  Dictionary with (temporary) OS parameters.
1064

    
1065
For backwards compatbility, this resource also takes the query
1066
parameters ``os`` (OS template name) and ``nostartup`` (bool). New
1067
clients should use the body parameters.
1068

    
1069

    
1070
``/2/instances/[instance_name]/replace-disks``
1071
++++++++++++++++++++++++++++++++++++++++++++++
1072

    
1073
Replaces disks on an instance.
1074

    
1075
It supports the following commands: ``POST``.
1076

    
1077
``POST``
1078
~~~~~~~~
1079

    
1080
Returns a job ID.
1081

    
1082
Body parameters:
1083

    
1084
.. opcode_params:: OP_INSTANCE_REPLACE_DISKS
1085
   :exclude: instance_name
1086

    
1087
Ganeti 2.4 and below used query parameters. Those are deprecated and
1088
should no longer be used.
1089

    
1090
Job result:
1091

    
1092
.. opcode_result:: OP_INSTANCE_REPLACE_DISKS
1093

    
1094

    
1095
``/2/instances/[instance_name]/activate-disks``
1096
+++++++++++++++++++++++++++++++++++++++++++++++
1097

    
1098
Activate disks on an instance.
1099

    
1100
It supports the following commands: ``PUT``.
1101

    
1102
``PUT``
1103
~~~~~~~
1104

    
1105
Takes the bool parameter ``ignore_size``. When set ignore the recorded
1106
size (useful for forcing activation when recorded size is wrong).
1107

    
1108
Job result:
1109

    
1110
.. opcode_result:: OP_INSTANCE_ACTIVATE_DISKS
1111

    
1112

    
1113
``/2/instances/[instance_name]/deactivate-disks``
1114
+++++++++++++++++++++++++++++++++++++++++++++++++
1115

    
1116
Deactivate disks on an instance.
1117

    
1118
It supports the following commands: ``PUT``.
1119

    
1120
``PUT``
1121
~~~~~~~
1122

    
1123
Takes no parameters.
1124

    
1125
Job result:
1126

    
1127
.. opcode_result:: OP_INSTANCE_DEACTIVATE_DISKS
1128

    
1129

    
1130
``/2/instances/[instance_name]/recreate-disks``
1131
+++++++++++++++++++++++++++++++++++++++++++++++++
1132

    
1133
Recreate disks of an instance. Supports the following commands:
1134
``POST``.
1135

    
1136
``POST``
1137
~~~~~~~~
1138

    
1139
Returns a job ID.
1140

    
1141
Body parameters:
1142

    
1143
.. opcode_params:: OP_INSTANCE_RECREATE_DISKS
1144
   :exclude: instance_name
1145

    
1146
Job result:
1147

    
1148
.. opcode_result:: OP_INSTANCE_RECREATE_DISKS
1149

    
1150

    
1151
``/2/instances/[instance_name]/disk/[disk_index]/grow``
1152
+++++++++++++++++++++++++++++++++++++++++++++++++++++++
1153

    
1154
Grows one disk of an instance.
1155

    
1156
Supports the following commands: ``POST``.
1157

    
1158
``POST``
1159
~~~~~~~~
1160

    
1161
Returns a job ID.
1162

    
1163
Body parameters:
1164

    
1165
.. opcode_params:: OP_INSTANCE_GROW_DISK
1166
   :exclude: instance_name, disk
1167

    
1168
Job result:
1169

    
1170
.. opcode_result:: OP_INSTANCE_GROW_DISK
1171

    
1172

    
1173
``/2/instances/[instance_name]/prepare-export``
1174
+++++++++++++++++++++++++++++++++++++++++++++++++
1175

    
1176
Prepares an export of an instance.
1177

    
1178
It supports the following commands: ``PUT``.
1179

    
1180
``PUT``
1181
~~~~~~~
1182

    
1183
Takes one parameter, ``mode``, for the export mode. Returns a job ID.
1184

    
1185
Job result:
1186

    
1187
.. opcode_result:: OP_BACKUP_PREPARE
1188

    
1189

    
1190
``/2/instances/[instance_name]/export``
1191
+++++++++++++++++++++++++++++++++++++++++++++++++
1192

    
1193
Exports an instance.
1194

    
1195
It supports the following commands: ``PUT``.
1196

    
1197
``PUT``
1198
~~~~~~~
1199

    
1200
Returns a job ID.
1201

    
1202
Body parameters:
1203

    
1204
.. opcode_params:: OP_BACKUP_EXPORT
1205
   :exclude: instance_name
1206
   :alias: target_node=destination
1207

    
1208
Job result:
1209

    
1210
.. opcode_result:: OP_BACKUP_EXPORT
1211

    
1212

    
1213
``/2/instances/[instance_name]/migrate``
1214
++++++++++++++++++++++++++++++++++++++++
1215

    
1216
Migrates an instance.
1217

    
1218
Supports the following commands: ``PUT``.
1219

    
1220
``PUT``
1221
~~~~~~~
1222

    
1223
Returns a job ID.
1224

    
1225
Body parameters:
1226

    
1227
.. opcode_params:: OP_INSTANCE_MIGRATE
1228
   :exclude: instance_name, live
1229

    
1230
Job result:
1231

    
1232
.. opcode_result:: OP_INSTANCE_MIGRATE
1233

    
1234

    
1235
``/2/instances/[instance_name]/failover``
1236
+++++++++++++++++++++++++++++++++++++++++
1237

    
1238
Does a failover of an instance.
1239

    
1240
Supports the following commands: ``PUT``.
1241

    
1242
``PUT``
1243
~~~~~~~
1244

    
1245
Returns a job ID.
1246

    
1247
Body parameters:
1248

    
1249
.. opcode_params:: OP_INSTANCE_FAILOVER
1250
   :exclude: instance_name
1251

    
1252
Job result:
1253

    
1254
.. opcode_result:: OP_INSTANCE_FAILOVER
1255

    
1256

    
1257
``/2/instances/[instance_name]/rename``
1258
++++++++++++++++++++++++++++++++++++++++
1259

    
1260
Renames an instance.
1261

    
1262
Supports the following commands: ``PUT``.
1263

    
1264
``PUT``
1265
~~~~~~~
1266

    
1267
Returns a job ID.
1268

    
1269
Body parameters:
1270

    
1271
.. opcode_params:: OP_INSTANCE_RENAME
1272
   :exclude: instance_name
1273

    
1274
Job result:
1275

    
1276
.. opcode_result:: OP_INSTANCE_RENAME
1277

    
1278

    
1279
``/2/instances/[instance_name]/modify``
1280
++++++++++++++++++++++++++++++++++++++++
1281

    
1282
Modifies an instance.
1283

    
1284
Supports the following commands: ``PUT``.
1285

    
1286
``PUT``
1287
~~~~~~~
1288

    
1289
Returns a job ID.
1290

    
1291
Body parameters:
1292

    
1293
.. opcode_params:: OP_INSTANCE_SET_PARAMS
1294
   :exclude: instance_name
1295

    
1296
Job result:
1297

    
1298
.. opcode_result:: OP_INSTANCE_SET_PARAMS
1299

    
1300

    
1301
``/2/instances/[instance_name]/console``
1302
++++++++++++++++++++++++++++++++++++++++
1303

    
1304
Request information for connecting to instance's console.
1305

    
1306
Supports the following commands: ``GET``.
1307

    
1308
``GET``
1309
~~~~~~~
1310

    
1311
Returns a dictionary containing information about the instance's
1312
console. Contained keys:
1313

    
1314
.. pyassert::
1315

    
1316
   constants.CONS_ALL == frozenset([
1317
     constants.CONS_MESSAGE,
1318
     constants.CONS_SSH,
1319
     constants.CONS_VNC,
1320
     constants.CONS_SPICE,
1321
     ])
1322

    
1323
``instance``
1324
  Instance name
1325
``kind``
1326
  Console type, one of :pyeval:`constants.CONS_SSH`,
1327
  :pyeval:`constants.CONS_VNC`, :pyeval:`constants.CONS_SPICE`
1328
  or :pyeval:`constants.CONS_MESSAGE`
1329
``message``
1330
  Message to display (:pyeval:`constants.CONS_MESSAGE` type only)
1331
``host``
1332
  Host to connect to (:pyeval:`constants.CONS_SSH`,
1333
  :pyeval:`constants.CONS_VNC` or :pyeval:`constants.CONS_SPICE` only)
1334
``port``
1335
  TCP port to connect to (:pyeval:`constants.CONS_VNC` or
1336
  :pyeval:`constants.CONS_SPICE` only)
1337
``user``
1338
  Username to use (:pyeval:`constants.CONS_SSH` only)
1339
``command``
1340
  Command to execute on machine (:pyeval:`constants.CONS_SSH` only)
1341
``display``
1342
  VNC display number (:pyeval:`constants.CONS_VNC` only)
1343

    
1344

    
1345
``/2/instances/[instance_name]/tags``
1346
+++++++++++++++++++++++++++++++++++++
1347

    
1348
Manages per-instance tags.
1349

    
1350
It supports the following commands: ``GET``, ``PUT``, ``DELETE``.
1351

    
1352
``GET``
1353
~~~~~~~
1354

    
1355
Returns a list of tags.
1356

    
1357
Example::
1358

    
1359
    ["tag1", "tag2", "tag3"]
1360

    
1361
``PUT``
1362
~~~~~~~
1363

    
1364
Add a set of tags.
1365

    
1366
The request as a list of strings should be ``PUT`` to this URI. The
1367
result will be a job id.
1368

    
1369
It supports the ``dry-run`` argument.
1370

    
1371

    
1372
``DELETE``
1373
~~~~~~~~~~
1374

    
1375
Delete a tag.
1376

    
1377
In order to delete a set of tags, the DELETE request should be addressed
1378
to URI like::
1379

    
1380
    /tags?tag=[tag]&tag=[tag]
1381

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

    
1384

    
1385
``/2/jobs``
1386
+++++++++++
1387

    
1388
The ``/2/jobs`` resource.
1389

    
1390
It supports the following commands: ``GET``.
1391

    
1392
``GET``
1393
~~~~~~~
1394

    
1395
Returns a dictionary of jobs.
1396

    
1397
Returns: a dictionary with jobs id and uri.
1398

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

    
1403
Returned fields for bulk requests (unlike other bulk requests, these
1404
fields are not the same as for per-job requests):
1405
:pyeval:`utils.CommaJoin(sorted(rlib2.J_FIELDS_BULK))`.
1406

    
1407
``/2/jobs/[job_id]``
1408
++++++++++++++++++++
1409

    
1410

    
1411
Individual job URI.
1412

    
1413
It supports the following commands: ``GET``, ``DELETE``.
1414

    
1415
``GET``
1416
~~~~~~~
1417

    
1418
Returns a dictionary with job parameters, containing the fields
1419
:pyeval:`utils.CommaJoin(sorted(rlib2.J_FIELDS))`.
1420

    
1421
The result includes:
1422

    
1423
- id: job ID as a number
1424
- status: current job status as a string
1425
- ops: involved OpCodes as a list of dictionaries for each opcodes in
1426
  the job
1427
- opstatus: OpCodes status as a list
1428
- opresult: OpCodes results as a list
1429

    
1430
For a successful opcode, the ``opresult`` field corresponding to it will
1431
contain the raw result from its :term:`LogicalUnit`. In case an opcode
1432
has failed, its element in the opresult list will be a list of two
1433
elements:
1434

    
1435
- first element the error type (the Ganeti internal error name)
1436
- second element a list of either one or two elements:
1437

    
1438
  - the first element is the textual error description
1439
  - the second element, if any, will hold an error classification
1440

    
1441
The error classification is most useful for the ``OpPrereqError``
1442
error type - these errors happen before the OpCode has started
1443
executing, so it's possible to retry the OpCode without side
1444
effects. But whether it make sense to retry depends on the error
1445
classification:
1446

    
1447
.. pyassert::
1448

    
1449
   errors.ECODE_ALL == set([errors.ECODE_RESOLVER, errors.ECODE_NORES,
1450
     errors.ECODE_INVAL, errors.ECODE_STATE, errors.ECODE_NOENT,
1451
     errors.ECODE_EXISTS, errors.ECODE_NOTUNIQUE, errors.ECODE_FAULT,
1452
     errors.ECODE_ENVIRON])
1453

    
1454
:pyeval:`errors.ECODE_RESOLVER`
1455
  Resolver errors. This usually means that a name doesn't exist in DNS,
1456
  so if it's a case of slow DNS propagation the operation can be retried
1457
  later.
1458

    
1459
:pyeval:`errors.ECODE_NORES`
1460
  Not enough resources (iallocator failure, disk space, memory,
1461
  etc.). If the resources on the cluster increase, the operation might
1462
  succeed.
1463

    
1464
:pyeval:`errors.ECODE_INVAL`
1465
  Wrong arguments (at syntax level). The operation will not ever be
1466
  accepted unless the arguments change.
1467

    
1468
:pyeval:`errors.ECODE_STATE`
1469
  Wrong entity state. For example, live migration has been requested for
1470
  a down instance, or instance creation on an offline node. The
1471
  operation can be retried once the resource has changed state.
1472

    
1473
:pyeval:`errors.ECODE_NOENT`
1474
  Entity not found. For example, information has been requested for an
1475
  unknown instance.
1476

    
1477
:pyeval:`errors.ECODE_EXISTS`
1478
  Entity already exists. For example, instance creation has been
1479
  requested for an already-existing instance.
1480

    
1481
:pyeval:`errors.ECODE_NOTUNIQUE`
1482
  Resource not unique (e.g. MAC or IP duplication).
1483

    
1484
:pyeval:`errors.ECODE_FAULT`
1485
  Internal cluster error. For example, a node is unreachable but not set
1486
  offline, or the ganeti node daemons are not working, etc. A
1487
  ``gnt-cluster verify`` should be run.
1488

    
1489
:pyeval:`errors.ECODE_ENVIRON`
1490
  Environment error (e.g. node disk error). A ``gnt-cluster verify``
1491
  should be run.
1492

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

    
1496

    
1497
``DELETE``
1498
~~~~~~~~~~
1499

    
1500
Cancel a not-yet-started job.
1501

    
1502

    
1503
``/2/jobs/[job_id]/wait``
1504
+++++++++++++++++++++++++
1505

    
1506
``GET``
1507
~~~~~~~
1508

    
1509
Waits for changes on a job. Takes the following body parameters in a
1510
dict:
1511

    
1512
``fields``
1513
  The job fields on which to watch for changes
1514

    
1515
``previous_job_info``
1516
  Previously received field values or None if not yet available
1517

    
1518
``previous_log_serial``
1519
  Highest log serial number received so far or None if not yet
1520
  available
1521

    
1522
Returns None if no changes have been detected and a dict with two keys,
1523
``job_info`` and ``log_entries`` otherwise.
1524

    
1525

    
1526
``/2/nodes``
1527
++++++++++++
1528

    
1529
Nodes resource.
1530

    
1531
It supports the following commands: ``GET``.
1532

    
1533
``GET``
1534
~~~~~~~
1535

    
1536
Returns a list of all nodes.
1537

    
1538
Example::
1539

    
1540
    [
1541
      {
1542
        "id": "node1.example.com",
1543
        "uri": "\/nodes\/node1.example.com"
1544
      },
1545
      {
1546
        "id": "node2.example.com",
1547
        "uri": "\/nodes\/node2.example.com"
1548
      }
1549
    ]
1550

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

    
1555
Returned fields: :pyeval:`utils.CommaJoin(sorted(rlib2.N_FIELDS))`.
1556

    
1557
Example::
1558

    
1559
    [
1560
      {
1561
        "pinst_cnt": 1,
1562
        "mfree": 31280,
1563
        "mtotal": 32763,
1564
        "name": "www.example.com",
1565
        "tags": [],
1566
        "mnode": 512,
1567
        "dtotal": 5246208,
1568
        "sinst_cnt": 2,
1569
        "dfree": 5171712,
1570
        "offline": false
1571
      },
1572
      ...
1573
    ]
1574

    
1575
``/2/nodes/[node_name]``
1576
+++++++++++++++++++++++++++++++++
1577

    
1578
Returns information about a node.
1579

    
1580
It supports the following commands: ``GET``.
1581

    
1582
Returned fields: :pyeval:`utils.CommaJoin(sorted(rlib2.N_FIELDS))`.
1583

    
1584
``/2/nodes/[node_name]/powercycle``
1585
+++++++++++++++++++++++++++++++++++
1586

    
1587
Powercycles a node. Supports the following commands: ``POST``.
1588

    
1589
``POST``
1590
~~~~~~~~
1591

    
1592
Returns a job ID.
1593

    
1594
Job result:
1595

    
1596
.. opcode_result:: OP_NODE_POWERCYCLE
1597

    
1598

    
1599
``/2/nodes/[node_name]/evacuate``
1600
+++++++++++++++++++++++++++++++++
1601

    
1602
Evacuates instances off a node.
1603

    
1604
It supports the following commands: ``POST``.
1605

    
1606
``POST``
1607
~~~~~~~~
1608

    
1609
Returns a job ID. The result of the job will contain the IDs of the
1610
individual jobs submitted to evacuate the node.
1611

    
1612
Body parameters:
1613

    
1614
.. opcode_params:: OP_NODE_EVACUATE
1615
   :exclude: nodes
1616

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

    
1621
Job result:
1622

    
1623
.. opcode_result:: OP_NODE_EVACUATE
1624

    
1625

    
1626
``/2/nodes/[node_name]/migrate``
1627
+++++++++++++++++++++++++++++++++
1628

    
1629
Migrates all primary instances from a node.
1630

    
1631
It supports the following commands: ``POST``.
1632

    
1633
``POST``
1634
~~~~~~~~
1635

    
1636
If no mode is explicitly specified, each instances' hypervisor default
1637
migration mode will be used. Body parameters:
1638

    
1639
.. opcode_params:: OP_NODE_MIGRATE
1640
   :exclude: node_name
1641

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

    
1646
Job result:
1647

    
1648
.. opcode_result:: OP_NODE_MIGRATE
1649

    
1650

    
1651
``/2/nodes/[node_name]/role``
1652
+++++++++++++++++++++++++++++
1653

    
1654
Manages node role.
1655

    
1656
It supports the following commands: ``GET``, ``PUT``.
1657

    
1658
The role is always one of the following:
1659

    
1660
  - drained
1661
  - master-candidate
1662
  - offline
1663
  - regular
1664

    
1665
Note that the 'master' role is a special, and currently it can't be
1666
modified via RAPI, only via the command line (``gnt-cluster
1667
master-failover``).
1668

    
1669
``GET``
1670
~~~~~~~
1671

    
1672
Returns the current node role.
1673

    
1674
Example::
1675

    
1676
    "master-candidate"
1677

    
1678
``PUT``
1679
~~~~~~~
1680

    
1681
Change the node role.
1682

    
1683
The request is a string which should be PUT to this URI. The result will
1684
be a job id.
1685

    
1686
It supports the bool ``force`` argument.
1687

    
1688
Job result:
1689

    
1690
.. opcode_result:: OP_NODE_SET_PARAMS
1691

    
1692

    
1693
``/2/nodes/[node_name]/modify``
1694
+++++++++++++++++++++++++++++++
1695

    
1696
Modifies the parameters of a node. Supports the following commands:
1697
``POST``.
1698

    
1699
``POST``
1700
~~~~~~~~
1701

    
1702
Returns a job ID.
1703

    
1704
Body parameters:
1705

    
1706
.. opcode_params:: OP_NODE_SET_PARAMS
1707
   :exclude: node_name
1708

    
1709
Job result:
1710

    
1711
.. opcode_result:: OP_NODE_SET_PARAMS
1712

    
1713

    
1714
``/2/nodes/[node_name]/storage``
1715
++++++++++++++++++++++++++++++++
1716

    
1717
Manages storage units on the node.
1718

    
1719
``GET``
1720
~~~~~~~
1721

    
1722
.. pyassert::
1723

    
1724
   constants.VALID_STORAGE_TYPES == set([constants.ST_FILE,
1725
                                         constants.ST_LVM_PV,
1726
                                         constants.ST_LVM_VG])
1727

    
1728
Requests a list of storage units on a node. Requires the parameters
1729
``storage_type`` (one of :pyeval:`constants.ST_FILE`,
1730
:pyeval:`constants.ST_LVM_PV` or :pyeval:`constants.ST_LVM_VG`) and
1731
``output_fields``. The result will be a job id, using which the result
1732
can be retrieved.
1733

    
1734
``/2/nodes/[node_name]/storage/modify``
1735
+++++++++++++++++++++++++++++++++++++++
1736

    
1737
Modifies storage units on the node.
1738

    
1739
``PUT``
1740
~~~~~~~
1741

    
1742
Modifies parameters of storage units on the node. Requires the
1743
parameters ``storage_type`` (one of :pyeval:`constants.ST_FILE`,
1744
:pyeval:`constants.ST_LVM_PV` or :pyeval:`constants.ST_LVM_VG`)
1745
and ``name`` (name of the storage unit).  Parameters can be passed
1746
additionally. Currently only :pyeval:`constants.SF_ALLOCATABLE` (bool)
1747
is supported. The result will be a job id.
1748

    
1749
Job result:
1750

    
1751
.. opcode_result:: OP_NODE_MODIFY_STORAGE
1752

    
1753

    
1754
``/2/nodes/[node_name]/storage/repair``
1755
+++++++++++++++++++++++++++++++++++++++
1756

    
1757
Repairs a storage unit on the node.
1758

    
1759
``PUT``
1760
~~~~~~~
1761

    
1762
.. pyassert::
1763

    
1764
   constants.VALID_STORAGE_OPERATIONS == {
1765
    constants.ST_LVM_VG: set([constants.SO_FIX_CONSISTENCY]),
1766
    }
1767

    
1768
Repairs a storage unit on the node. Requires the parameters
1769
``storage_type`` (currently only :pyeval:`constants.ST_LVM_VG` can be
1770
repaired) and ``name`` (name of the storage unit). The result will be a
1771
job id.
1772

    
1773
Job result:
1774

    
1775
.. opcode_result:: OP_REPAIR_NODE_STORAGE
1776

    
1777

    
1778
``/2/nodes/[node_name]/tags``
1779
+++++++++++++++++++++++++++++
1780

    
1781
Manages per-node tags.
1782

    
1783
It supports the following commands: ``GET``, ``PUT``, ``DELETE``.
1784

    
1785
``GET``
1786
~~~~~~~
1787

    
1788
Returns a list of tags.
1789

    
1790
Example::
1791

    
1792
    ["tag1", "tag2", "tag3"]
1793

    
1794
``PUT``
1795
~~~~~~~
1796

    
1797
Add a set of tags.
1798

    
1799
The request as a list of strings should be PUT to this URI. The result
1800
will be a job id.
1801

    
1802
It supports the ``dry-run`` argument.
1803

    
1804
``DELETE``
1805
~~~~~~~~~~
1806

    
1807
Deletes tags.
1808

    
1809
In order to delete a set of tags, the DELETE request should be addressed
1810
to URI like::
1811

    
1812
    /tags?tag=[tag]&tag=[tag]
1813

    
1814
It supports the ``dry-run`` argument.
1815

    
1816

    
1817
``/2/query/[resource]``
1818
+++++++++++++++++++++++
1819

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

    
1825
Supports the following commands: ``GET``, ``PUT``.
1826

    
1827
``GET``
1828
~~~~~~~
1829

    
1830
Returns list of included fields and actual data. Takes a query parameter
1831
named "fields", containing a comma-separated list of field names. Does
1832
not support filtering.
1833

    
1834
``PUT``
1835
~~~~~~~
1836

    
1837
Returns list of included fields and actual data. The list of requested
1838
fields can either be given as the query parameter "fields" or as a body
1839
parameter with the same name. The optional body parameter "filter" can
1840
be given and must be either ``null`` or a list containing filter
1841
operators.
1842

    
1843

    
1844
``/2/query/[resource]/fields``
1845
++++++++++++++++++++++++++++++
1846

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

    
1851
Supports the following commands: ``GET``.
1852

    
1853
``GET``
1854
~~~~~~~
1855

    
1856
Returns a list of field descriptions for available fields. Takes an
1857
optional query parameter named "fields", containing a comma-separated
1858
list of field names.
1859

    
1860

    
1861
``/2/os``
1862
+++++++++
1863

    
1864
OS resource.
1865

    
1866
It supports the following commands: ``GET``.
1867

    
1868
``GET``
1869
~~~~~~~
1870

    
1871
Return a list of all OSes.
1872

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

    
1876
Example::
1877

    
1878
    ["debian-etch"]
1879

    
1880
``/2/tags``
1881
+++++++++++
1882

    
1883
Manages cluster tags.
1884

    
1885
It supports the following commands: ``GET``, ``PUT``, ``DELETE``.
1886

    
1887
``GET``
1888
~~~~~~~
1889

    
1890
Returns the cluster tags.
1891

    
1892
Example::
1893

    
1894
    ["tag1", "tag2", "tag3"]
1895

    
1896
``PUT``
1897
~~~~~~~
1898

    
1899
Adds a set of tags.
1900

    
1901
The request as a list of strings should be PUT to this URI. The result
1902
will be a job id.
1903

    
1904
It supports the ``dry-run`` argument.
1905

    
1906

    
1907
``DELETE``
1908
~~~~~~~~~~
1909

    
1910
Deletes tags.
1911

    
1912
In order to delete a set of tags, the DELETE request should be addressed
1913
to URI like::
1914

    
1915
    /tags?tag=[tag]&tag=[tag]
1916

    
1917
It supports the ``dry-run`` argument.
1918

    
1919

    
1920
``/version``
1921
++++++++++++
1922

    
1923
The version resource.
1924

    
1925
This resource should be used to determine the remote API version and to
1926
adapt clients accordingly.
1927

    
1928
It supports the following commands: ``GET``.
1929

    
1930
``GET``
1931
~~~~~~~
1932

    
1933
Returns the remote API version. Ganeti 1.2 returned ``1`` and Ganeti 2.0
1934
returns ``2``.
1935

    
1936
.. vim: set textwidth=72 :
1937
.. Local Variables:
1938
.. mode: rst
1939
.. fill-column: 72
1940
.. End: