Statistics
| Branch: | Tag: | Revision:

root / doc / rapi.rst @ 62e999a5

History | View | Annotate | Download (31.8 kB)

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

    
4
Documents Ganeti version |version|
5

    
6
.. contents::
7

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

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

    
19

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

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

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

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

    
42
Example::
43

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

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

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

    
54

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

    
63

    
64
Protocol
65
--------
66

    
67
The protocol used is JSON_ over HTTP designed after the REST_ principle.
68
HTTP Basic authentication as per :rfc:`2617` is supported.
69

    
70
.. _JSON: http://www.json.org/
71
.. _REST: http://en.wikipedia.org/wiki/Representational_State_Transfer
72

    
73

    
74
A note on JSON as used by RAPI
75
++++++++++++++++++++++++++++++
76

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

    
84
.. highlight:: ruby
85

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

    
94
  require "json"
95

    
96
  # Insert code to get response here
97
  response = "\"1234\""
98

    
99
  decoded = JSON.parse("[#{response}]").first
100

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

    
106

    
107
PUT or POST?
108
------------
109

    
110
According to :rfc:`2616` the main difference between PUT and POST is
111
that POST can create new resources but PUT can only create the resource
112
the URI was pointing to on the PUT request.
113

    
114
Unfortunately, due to historic reasons, the Ganeti RAPI library is not
115
consistent with this usage, so just use the methods as documented below
116
for each resource.
117

    
118
For more details have a look in the source code at
119
``lib/rapi/rlib2.py``.
120

    
121

    
122
Generic parameter types
123
-----------------------
124

    
125
A few generic refered parameter types and the values they allow.
126

    
127
``bool``
128
++++++++
129

    
130
A boolean option will accept ``1`` or ``0`` as numbers but not
131
i.e. ``True`` or ``False``.
132

    
133
Generic parameters
134
------------------
135

    
136
A few parameter mean the same thing across all resources which implement
137
it.
138

    
139
``bulk``
140
++++++++
141

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

    
148
``dry-run``
149
+++++++++++
150

    
151
The boolean *dry-run* argument, if provided and set, signals to Ganeti
152
that the job should not be executed, only the pre-execution checks will
153
be done.
154

    
155
This is useful in trying to determine (without guarantees though, as in
156
the meantime the cluster state could have changed) if the operation is
157
likely to succeed or at least start executing.
158

    
159
``force``
160
+++++++++++
161

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

    
165
Usage examples
166
--------------
167

    
168
You can access the API using your favorite programming language as long
169
as it supports network connections.
170

    
171
Ganeti RAPI client
172
++++++++++++++++++
173

    
174
Ganeti includes a standalone RAPI client, ``lib/rapi/client.py``.
175

    
176
Shell
177
+++++
178

    
179
.. highlight:: sh
180

    
181
Using wget::
182

    
183
   wget -q -O - https://CLUSTERNAME:5080/2/info
184

    
185
or curl::
186

    
187
  curl https://CLUSTERNAME:5080/2/info
188

    
189

    
190
Python
191
++++++
192

    
193
.. highlight:: python
194

    
195
::
196

    
197
  import urllib2
198
  f = urllib2.urlopen('https://CLUSTERNAME:5080/2/info')
199
  print f.read()
200

    
201

    
202
JavaScript
203
++++++++++
204

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

    
210
.. highlight:: javascript
211

    
212
::
213

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

    
230
Resources
231
---------
232

    
233
.. highlight:: javascript
234

    
235
``/``
236
+++++
237

    
238
The root resource.
239

    
240
It supports the following commands: ``GET``.
241

    
242
``GET``
243
~~~~~~~
244

    
245
Shows the list of mapped resources.
246

    
247
Returns: a dictionary with 'name' and 'uri' keys for each of them.
248

    
249
``/2``
250
++++++
251

    
252
The ``/2`` resource, the root of the version 2 API.
253

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

    
256
``GET``
257
~~~~~~~
258

    
259
Show the list of mapped resources.
260

    
261
Returns: a dictionary with ``name`` and ``uri`` keys for each of them.
262

    
263
``/2/info``
264
+++++++++++
265

    
266
Cluster information resource.
267

    
268
It supports the following commands: ``GET``.
269

    
270
``GET``
271
~~~~~~~
272

    
273
Returns cluster information.
274

    
275
Example::
276

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

    
306

    
307
``/2/redistribute-config``
308
++++++++++++++++++++++++++
309

    
310
Redistribute configuration to all nodes.
311

    
312
It supports the following commands: ``PUT``.
313

    
314
``PUT``
315
~~~~~~~
316

    
317
Redistribute configuration to all nodes. The result will be a job id.
318

    
319

    
320
``/2/features``
321
+++++++++++++++
322

    
323
``GET``
324
~~~~~~~
325

    
326
Returns a list of features supported by the RAPI server. Available
327
features:
328

    
329
``instance-create-reqv1``
330
  Instance creation request data version 1 supported.
331
``instance-reinstall-reqv1``
332
  Instance reinstall supports body parameters.
333

    
334

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

    
338
Modifies cluster parameters.
339

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

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

    
345
Returns a job ID.
346

    
347
Body parameters:
348

    
349
``vg_name`` (string)
350
  Volume group name.
351
``enabled_hypervisors`` (list)
352
  List of enabled hypervisors.
353
``hvparams`` (dict)
354
  Cluster-wide hypervisor parameter defaults, hypervisor-dependent.
355
``beparams`` (dict)
356
  Cluster-wide backend parameter defaults.
357
``os_hvp`` (dict)
358
  Cluster-wide per-OS hypervisor parameter defaults.
359
``osparams`` (dict)
360
  Dictionary with OS parameters.
361
``candidate_pool_size`` (int)
362
  Master candidate pool size.
363
``uid_pool`` (list)
364
  Set UID pool. Must be list of lists describing UID ranges (two items,
365
  start and end inclusive).
366
``add_uids``
367
  Extend UID pool. Must be list of lists describing UID ranges (two
368
  items, start and end inclusive) to be added.
369
``remove_uids``
370
  Shrink UID pool. Must be list of lists describing UID ranges (two
371
  items, start and end inclusive) to be removed.
372
``maintain_node_health`` (bool)
373
  Whether to automatically maintain node health.
374
``prealloc_wipe_disks`` (bool)
375
  Whether to wipe disks before allocating them to instances.
376
``nicparams`` (dict)
377
  Cluster-wide NIC parameter defaults.
378
``ndparams`` (dict)
379
  Cluster-wide node parameter defaults.
380
``drbd_helper`` (string)
381
  DRBD helper program.
382
``default_iallocator`` (string)
383
  Default iallocator for cluster.
384
``master_netdev`` (string)
385
  Master network device.
386
``reserved_lvs`` (list)
387
  List of reserved LVs (strings).
388
``hidden_os`` (list)
389
  List of modifications as lists. Each modification must have two items,
390
  the operation and the OS name. The operation can be ``add`` or
391
  ``remove``.
392
``blacklisted_os`` (list)
393
  List of modifications as lists. Each modification must have two items,
394
  the operation and the OS name. The operation can be ``add`` or
395
  ``remove``.
396

    
397

    
398
``/2/groups``
399
+++++++++++++
400

    
401
The groups resource.
402

    
403
It supports the following commands: ``GET``, ``POST``.
404

    
405
``GET``
406
~~~~~~~
407

    
408
Returns a list of all existing node groups.
409

    
410
Example::
411

    
412
    [
413
      {
414
        "name": "group1",
415
        "uri": "\/2\/groups\/group1"
416
      },
417
      {
418
        "name": "group2",
419
        "uri": "\/2\/groups\/group2"
420
      }
421
    ]
422

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

    
427
Example::
428

    
429
    [
430
      {
431
        "name": "group1",
432
        "node_cnt": 2,
433
        "node_list": [
434
          "node1.example.com",
435
          "node2.example.com"
436
        ],
437
        "uuid": "0d7d407c-262e-49af-881a-6a430034bf43"
438
      },
439
      {
440
        "name": "group2",
441
        "node_cnt": 1,
442
        "node_list": [
443
          "node3.example.com"
444
        ],
445
        "uuid": "f5a277e7-68f9-44d3-a378-4b25ecb5df5c"
446
      }
447
    ]
448

    
449
``POST``
450
~~~~~~~~
451

    
452
Creates a node group.
453

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

    
457
Returns: a job ID that can be used later for polling.
458

    
459
Body parameters:
460

    
461
``name`` (string, required)
462
  Node group name.
463

    
464

    
465
``/2/groups/[group_name]``
466
++++++++++++++++++++++++++
467

    
468
Returns information about a node group.
469

    
470
It supports the following commands: ``GET``, ``DELETE``.
471

    
472
``GET``
473
~~~~~~~
474

    
475
Returns information about a node group, similar to the bulk output from
476
the node group list.
477

    
478
``DELETE``
479
~~~~~~~~~~
480

    
481
Deletes a node group.
482

    
483
It supports the ``dry-run`` argument.
484

    
485

    
486
``/2/groups/[group_name]/modify``
487
+++++++++++++++++++++++++++++++++
488

    
489
Modifies the parameters of a node group.
490

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

    
493
``PUT``
494
~~~~~~~
495

    
496
Returns a job ID.
497

    
498
Body parameters:
499

    
500
``alloc_policy`` (string)
501
  If present, the new allocation policy for the node group.
502

    
503

    
504
``/2/groups/[group_name]/rename``
505
+++++++++++++++++++++++++++++++++
506

    
507
Renames a node group.
508

    
509
Supports the following commands: ``PUT``.
510

    
511
``PUT``
512
~~~~~~~
513

    
514
Returns a job ID.
515

    
516
Body parameters:
517

    
518
``new_name`` (string, required)
519
  New node group name.
520

    
521

    
522
``/2/instances``
523
++++++++++++++++
524

    
525
The instances resource.
526

    
527
It supports the following commands: ``GET``, ``POST``.
528

    
529
``GET``
530
~~~~~~~
531

    
532
Returns a list of all available instances.
533

    
534
Example::
535

    
536
    [
537
      {
538
        "name": "web.example.com",
539
        "uri": "\/instances\/web.example.com"
540
      },
541
      {
542
        "name": "mail.example.com",
543
        "uri": "\/instances\/mail.example.com"
544
      }
545
    ]
546

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

    
551
Example::
552

    
553
    [
554
      {
555
         "status": "running",
556
         "disk_usage": 20480,
557
         "nic.bridges": [
558
           "xen-br0"
559
          ],
560
         "name": "web.example.com",
561
         "tags": ["tag1", "tag2"],
562
         "beparams": {
563
           "vcpus": 2,
564
           "memory": 512
565
         },
566
         "disk.sizes": [
567
             20480
568
         ],
569
         "pnode": "node1.example.com",
570
         "nic.macs": ["01:23:45:67:89:01"],
571
         "snodes": ["node2.example.com"],
572
         "disk_template": "drbd",
573
         "admin_state": true,
574
         "os": "debian-etch",
575
         "oper_state": true
576
      },
577
      ...
578
    ]
579

    
580

    
581
``POST``
582
~~~~~~~~
583

    
584
Creates an instance.
585

    
586
If the optional bool *dry-run* argument is provided, the job will not be
587
actually executed, only the pre-execution checks will be done. Query-ing
588
the job result will return, in both dry-run and normal case, the list of
589
nodes selected for the instance.
590

    
591
Returns: a job ID that can be used later for polling.
592

    
593
Body parameters:
594

    
595
``__version__`` (int, required)
596
  Must be ``1`` (older Ganeti versions used a different format for
597
  instance creation requests, version ``0``, but that format is not
598
  documented).
599
``mode`` (string, required)
600
  Instance creation mode.
601
``name`` (string, required)
602
  Instance name.
603
``disk_template`` (string, required)
604
  Disk template for instance.
605
``disks`` (list, required)
606
  List of disk definitions. Example: ``[{"size": 100}, {"size": 5}]``.
607
  Each disk definition must contain a ``size`` value and can contain an
608
  optional ``mode`` value denoting the disk access mode (``ro`` or
609
  ``rw``).
610
``nics`` (list, required)
611
  List of NIC (network interface) definitions. Example: ``[{}, {},
612
  {"ip": "198.51.100.4"}]``. Each NIC definition can contain the
613
  optional values ``ip``, ``mode``, ``link`` and ``bridge``.
614
``os`` (string, required)
615
  Instance operating system.
616
``osparams`` (dictionary)
617
  Dictionary with OS parameters. If not valid for the given OS, the job
618
  will fail.
619
``force_variant`` (bool)
620
  Whether to force an unknown variant.
621
``no_install`` (bool)
622
  Do not install the OS (will enable no-start)
623
``pnode`` (string)
624
  Primary node.
625
``snode`` (string)
626
  Secondary node.
627
``src_node`` (string)
628
  Source node for import.
629
``src_path`` (string)
630
  Source directory for import.
631
``start`` (bool)
632
  Whether to start instance after creation.
633
``ip_check`` (bool)
634
  Whether to ensure instance's IP address is inactive.
635
``name_check`` (bool)
636
  Whether to ensure instance's name is resolvable.
637
``file_storage_dir`` (string)
638
  File storage directory.
639
``file_driver`` (string)
640
  File storage driver.
641
``iallocator`` (string)
642
  Instance allocator name.
643
``source_handshake`` (list)
644
  Signed handshake from source (remote import only).
645
``source_x509_ca`` (string)
646
  Source X509 CA in PEM format (remote import only).
647
``source_instance_name`` (string)
648
  Source instance name (remote import only).
649
``hypervisor`` (string)
650
  Hypervisor name.
651
``hvparams`` (dict)
652
  Hypervisor parameters, hypervisor-dependent.
653
``beparams`` (dict)
654
  Backend parameters.
655

    
656

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

    
660
Instance-specific resource.
661

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

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

    
667
Returns information about an instance, similar to the bulk output from
668
the instance list.
669

    
670
``DELETE``
671
~~~~~~~~~~
672

    
673
Deletes an instance.
674

    
675
It supports the ``dry-run`` argument.
676

    
677

    
678
``/2/instances/[instance_name]/info``
679
+++++++++++++++++++++++++++++++++++++++
680

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

    
683
``GET``
684
~~~~~~~
685

    
686
Requests detailed information about the instance. An optional parameter,
687
``static`` (bool), can be set to return only static information from the
688
configuration without querying the instance's nodes. The result will be
689
a job id.
690

    
691

    
692
``/2/instances/[instance_name]/reboot``
693
+++++++++++++++++++++++++++++++++++++++
694

    
695
Reboots URI for an instance.
696

    
697
It supports the following commands: ``POST``.
698

    
699
``POST``
700
~~~~~~~~
701

    
702
Reboots the instance.
703

    
704
The URI takes optional ``type=soft|hard|full`` and
705
``ignore_secondaries=0|1`` parameters.
706

    
707
``type`` defines the reboot type. ``soft`` is just a normal reboot,
708
without terminating the hypervisor. ``hard`` means full shutdown
709
(including terminating the hypervisor process) and startup again.
710
``full`` is like ``hard`` but also recreates the configuration from
711
ground up as if you would have done a ``gnt-instance shutdown`` and
712
``gnt-instance start`` on it.
713

    
714
``ignore_secondaries`` is a bool argument indicating if we start the
715
instance even if secondary disks are failing.
716

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

    
719

    
720
``/2/instances/[instance_name]/shutdown``
721
+++++++++++++++++++++++++++++++++++++++++
722

    
723
Instance shutdown URI.
724

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

    
727
``PUT``
728
~~~~~~~
729

    
730
Shutdowns an instance.
731

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

    
734

    
735
``/2/instances/[instance_name]/startup``
736
++++++++++++++++++++++++++++++++++++++++
737

    
738
Instance startup URI.
739

    
740
It supports the following commands: ``PUT``.
741

    
742
``PUT``
743
~~~~~~~
744

    
745
Startup an instance.
746

    
747
The URI takes an optional ``force=1|0`` parameter to start the
748
instance even if secondary disks are failing.
749

    
750
It supports the ``dry-run`` argument.
751

    
752
``/2/instances/[instance_name]/reinstall``
753
++++++++++++++++++++++++++++++++++++++++++++++
754

    
755
Installs the operating system again.
756

    
757
It supports the following commands: ``POST``.
758

    
759
``POST``
760
~~~~~~~~
761

    
762
Returns a job ID.
763

    
764
Body parameters:
765

    
766
``os`` (string, required)
767
  Instance operating system.
768
``start`` (bool, defaults to true)
769
  Whether to start instance after reinstallation.
770
``osparams`` (dict)
771
  Dictionary with (temporary) OS parameters.
772

    
773
For backwards compatbility, this resource also takes the query
774
parameters ``os`` (OS template name) and ``nostartup`` (bool). New
775
clients should use the body parameters.
776

    
777

    
778
``/2/instances/[instance_name]/replace-disks``
779
++++++++++++++++++++++++++++++++++++++++++++++
780

    
781
Replaces disks on an instance.
782

    
783
It supports the following commands: ``POST``.
784

    
785
``POST``
786
~~~~~~~~
787

    
788
Takes the parameters ``mode`` (one of ``replace_on_primary``,
789
``replace_on_secondary``, ``replace_new_secondary`` or
790
``replace_auto``), ``disks`` (comma separated list of disk indexes),
791
``remote_node`` and ``iallocator``.
792

    
793
Either ``remote_node`` or ``iallocator`` needs to be defined when using
794
``mode=replace_new_secondary``.
795

    
796
``mode`` is a mandatory parameter. ``replace_auto`` tries to determine
797
the broken disk(s) on its own and replacing it.
798

    
799

    
800
``/2/instances/[instance_name]/activate-disks``
801
+++++++++++++++++++++++++++++++++++++++++++++++
802

    
803
Activate disks on an instance.
804

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

    
807
``PUT``
808
~~~~~~~
809

    
810
Takes the bool parameter ``ignore_size``. When set ignore the recorded
811
size (useful for forcing activation when recorded size is wrong).
812

    
813

    
814
``/2/instances/[instance_name]/deactivate-disks``
815
+++++++++++++++++++++++++++++++++++++++++++++++++
816

    
817
Deactivate disks on an instance.
818

    
819
It supports the following commands: ``PUT``.
820

    
821
``PUT``
822
~~~~~~~
823

    
824
Takes no parameters.
825

    
826

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

    
830
Prepares an export of an instance.
831

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

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

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

    
839

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

    
843
Exports an instance.
844

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

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

    
850
Returns a job ID.
851

    
852
Body parameters:
853

    
854
``mode`` (string)
855
  Export mode.
856
``destination`` (required)
857
  Destination information, depends on export mode.
858
``shutdown`` (bool, required)
859
  Whether to shutdown instance before export.
860
``remove_instance`` (bool)
861
  Whether to remove instance after export.
862
``x509_key_name``
863
  Name of X509 key (remote export only).
864
``destination_x509_ca``
865
  Destination X509 CA (remote export only).
866

    
867

    
868
``/2/instances/[instance_name]/migrate``
869
++++++++++++++++++++++++++++++++++++++++
870

    
871
Migrates an instance.
872

    
873
Supports the following commands: ``PUT``.
874

    
875
``PUT``
876
~~~~~~~
877

    
878
Returns a job ID.
879

    
880
Body parameters:
881

    
882
``mode`` (string)
883
  Migration mode.
884
``cleanup`` (bool)
885
  Whether a previously failed migration should be cleaned up.
886

    
887

    
888
``/2/instances/[instance_name]/rename``
889
++++++++++++++++++++++++++++++++++++++++
890

    
891
Renames an instance.
892

    
893
Supports the following commands: ``PUT``.
894

    
895
``PUT``
896
~~~~~~~
897

    
898
Returns a job ID.
899

    
900
Body parameters:
901

    
902
``new_name`` (string, required)
903
  New instance name.
904
``ip_check`` (bool)
905
  Whether to ensure instance's IP address is inactive.
906
``name_check`` (bool)
907
  Whether to ensure instance's name is resolvable.
908

    
909

    
910
``/2/instances/[instance_name]/modify``
911
++++++++++++++++++++++++++++++++++++++++
912

    
913
Modifies an instance.
914

    
915
Supports the following commands: ``PUT``.
916

    
917
``PUT``
918
~~~~~~~
919

    
920
Returns a job ID.
921

    
922
Body parameters:
923

    
924
``osparams`` (dict)
925
  Dictionary with OS parameters.
926
``hvparams`` (dict)
927
  Hypervisor parameters, hypervisor-dependent.
928
``beparams`` (dict)
929
  Backend parameters.
930
``force`` (bool)
931
  Whether to force the operation.
932
``nics`` (list)
933
  List of NIC changes. Each item is of the form ``(op, settings)``.
934
  ``op`` can be ``add`` to add a new NIC with the specified settings,
935
  ``remove`` to remove the last NIC or a number to modify the settings
936
  of the NIC with that index.
937
``disks`` (list)
938
  List of disk changes. See ``nics``.
939
``disk_template`` (string)
940
  Disk template for instance.
941
``remote_node`` (string)
942
  Secondary node (used when changing disk template).
943
``os_name`` (string)
944
  Change instance's OS name. Does not reinstall the instance.
945
``force_variant`` (bool)
946
  Whether to force an unknown variant.
947

    
948

    
949
``/2/instances/[instance_name]/tags``
950
+++++++++++++++++++++++++++++++++++++
951

    
952
Manages per-instance tags.
953

    
954
It supports the following commands: ``GET``, ``PUT``, ``DELETE``.
955

    
956
``GET``
957
~~~~~~~
958

    
959
Returns a list of tags.
960

    
961
Example::
962

    
963
    ["tag1", "tag2", "tag3"]
964

    
965
``PUT``
966
~~~~~~~
967

    
968
Add a set of tags.
969

    
970
The request as a list of strings should be ``PUT`` to this URI. The
971
result will be a job id.
972

    
973
It supports the ``dry-run`` argument.
974

    
975

    
976
``DELETE``
977
~~~~~~~~~~
978

    
979
Delete a tag.
980

    
981
In order to delete a set of tags, the DELETE request should be addressed
982
to URI like::
983

    
984
    /tags?tag=[tag]&tag=[tag]
985

    
986
It supports the ``dry-run`` argument.
987

    
988

    
989
``/2/jobs``
990
+++++++++++
991

    
992
The ``/2/jobs`` resource.
993

    
994
It supports the following commands: ``GET``.
995

    
996
``GET``
997
~~~~~~~
998

    
999
Returns a dictionary of jobs.
1000

    
1001
Returns: a dictionary with jobs id and uri.
1002

    
1003
``/2/jobs/[job_id]``
1004
++++++++++++++++++++
1005

    
1006

    
1007
Individual job URI.
1008

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

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

    
1014
Returns a job status.
1015

    
1016
Returns: a dictionary with job parameters.
1017

    
1018
The result includes:
1019

    
1020
- id: job ID as a number
1021
- status: current job status as a string
1022
- ops: involved OpCodes as a list of dictionaries for each opcodes in
1023
  the job
1024
- opstatus: OpCodes status as a list
1025
- opresult: OpCodes results as a list
1026

    
1027
For a successful opcode, the ``opresult`` field corresponding to it will
1028
contain the raw result from its :term:`LogicalUnit`. In case an opcode
1029
has failed, its element in the opresult list will be a list of two
1030
elements:
1031

    
1032
- first element the error type (the Ganeti internal error name)
1033
- second element a list of either one or two elements:
1034

    
1035
  - the first element is the textual error description
1036
  - the second element, if any, will hold an error classification
1037

    
1038
The error classification is most useful for the ``OpPrereqError``
1039
error type - these errors happen before the OpCode has started
1040
executing, so it's possible to retry the OpCode without side
1041
effects. But whether it make sense to retry depends on the error
1042
classification:
1043

    
1044
``resolver_error``
1045
  Resolver errors. This usually means that a name doesn't exist in DNS,
1046
  so if it's a case of slow DNS propagation the operation can be retried
1047
  later.
1048

    
1049
``insufficient_resources``
1050
  Not enough resources (iallocator failure, disk space, memory,
1051
  etc.). If the resources on the cluster increase, the operation might
1052
  succeed.
1053

    
1054
``wrong_input``
1055
  Wrong arguments (at syntax level). The operation will not ever be
1056
  accepted unless the arguments change.
1057

    
1058
``wrong_state``
1059
  Wrong entity state. For example, live migration has been requested for
1060
  a down instance, or instance creation on an offline node. The
1061
  operation can be retried once the resource has changed state.
1062

    
1063
``unknown_entity``
1064
  Entity not found. For example, information has been requested for an
1065
  unknown instance.
1066

    
1067
``already_exists``
1068
  Entity already exists. For example, instance creation has been
1069
  requested for an already-existing instance.
1070

    
1071
``resource_not_unique``
1072
  Resource not unique (e.g. MAC or IP duplication).
1073

    
1074
``internal_error``
1075
  Internal cluster error. For example, a node is unreachable but not set
1076
  offline, or the ganeti node daemons are not working, etc. A
1077
  ``gnt-cluster verify`` should be run.
1078

    
1079
``environment_error``
1080
  Environment error (e.g. node disk error). A ``gnt-cluster verify``
1081
  should be run.
1082

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

    
1086

    
1087
``DELETE``
1088
~~~~~~~~~~
1089

    
1090
Cancel a not-yet-started job.
1091

    
1092

    
1093
``/2/jobs/[job_id]/wait``
1094
+++++++++++++++++++++++++
1095

    
1096
``GET``
1097
~~~~~~~
1098

    
1099
Waits for changes on a job. Takes the following body parameters in a
1100
dict:
1101

    
1102
``fields``
1103
  The job fields on which to watch for changes.
1104

    
1105
``previous_job_info``
1106
  Previously received field values or None if not yet available.
1107

    
1108
``previous_log_serial``
1109
  Highest log serial number received so far or None if not yet
1110
  available.
1111

    
1112
Returns None if no changes have been detected and a dict with two keys,
1113
``job_info`` and ``log_entries`` otherwise.
1114

    
1115

    
1116
``/2/nodes``
1117
++++++++++++
1118

    
1119
Nodes resource.
1120

    
1121
It supports the following commands: ``GET``.
1122

    
1123
``GET``
1124
~~~~~~~
1125

    
1126
Returns a list of all nodes.
1127

    
1128
Example::
1129

    
1130
    [
1131
      {
1132
        "id": "node1.example.com",
1133
        "uri": "\/nodes\/node1.example.com"
1134
      },
1135
      {
1136
        "id": "node2.example.com",
1137
        "uri": "\/nodes\/node2.example.com"
1138
      }
1139
    ]
1140

    
1141
If the optional 'bulk' argument is provided and set to 'true' value (i.e
1142
'?bulk=1'), the output contains detailed information about nodes as a
1143
list.
1144

    
1145
Example::
1146

    
1147
    [
1148
      {
1149
        "pinst_cnt": 1,
1150
        "mfree": 31280,
1151
        "mtotal": 32763,
1152
        "name": "www.example.com",
1153
        "tags": [],
1154
        "mnode": 512,
1155
        "dtotal": 5246208,
1156
        "sinst_cnt": 2,
1157
        "dfree": 5171712,
1158
        "offline": false
1159
      },
1160
      ...
1161
    ]
1162

    
1163
``/2/nodes/[node_name]``
1164
+++++++++++++++++++++++++++++++++
1165

    
1166
Returns information about a node.
1167

    
1168
It supports the following commands: ``GET``.
1169

    
1170
``/2/nodes/[node_name]/evacuate``
1171
+++++++++++++++++++++++++++++++++
1172

    
1173
Evacuates all secondary instances off a node.
1174

    
1175
It supports the following commands: ``POST``.
1176

    
1177
``POST``
1178
~~~~~~~~
1179

    
1180
To evacuate a node, either one of the ``iallocator`` or ``remote_node``
1181
parameters must be passed::
1182

    
1183
    evacuate?iallocator=[iallocator]
1184
    evacuate?remote_node=[nodeX.example.com]
1185

    
1186
The result value will be a list, each element being a triple of the job
1187
id (for this specific evacuation), the instance which is being evacuated
1188
by this job, and the node to which it is being relocated. In case the
1189
node is already empty, the result will be an empty list (without any
1190
jobs being submitted).
1191

    
1192
And additional parameter ``early_release`` signifies whether to try to
1193
parallelize the evacuations, at the risk of increasing I/O contention
1194
and increasing the chances of data loss, if the primary node of any of
1195
the instances being evacuated is not fully healthy.
1196

    
1197
If the dry-run parameter was specified, then the evacuation jobs were
1198
not actually submitted, and the job IDs will be null.
1199

    
1200

    
1201
``/2/nodes/[node_name]/migrate``
1202
+++++++++++++++++++++++++++++++++
1203

    
1204
Migrates all primary instances from a node.
1205

    
1206
It supports the following commands: ``POST``.
1207

    
1208
``POST``
1209
~~~~~~~~
1210

    
1211
If no mode is explicitly specified, each instances' hypervisor default
1212
migration mode will be used. Query parameters:
1213

    
1214
``live`` (bool)
1215
  If set, use live migration if available.
1216
``mode`` (string)
1217
  Sets migration mode, ``live`` for live migration and ``non-live`` for
1218
  non-live migration. Supported by Ganeti 2.2 and above.
1219

    
1220

    
1221
``/2/nodes/[node_name]/role``
1222
+++++++++++++++++++++++++++++
1223

    
1224
Manages node role.
1225

    
1226
It supports the following commands: ``GET``, ``PUT``.
1227

    
1228
The role is always one of the following:
1229

    
1230
  - drained
1231
  - master
1232
  - master-candidate
1233
  - offline
1234
  - regular
1235

    
1236
``GET``
1237
~~~~~~~
1238

    
1239
Returns the current node role.
1240

    
1241
Example::
1242

    
1243
    "master-candidate"
1244

    
1245
``PUT``
1246
~~~~~~~
1247

    
1248
Change the node role.
1249

    
1250
The request is a string which should be PUT to this URI. The result will
1251
be a job id.
1252

    
1253
It supports the bool ``force`` argument.
1254

    
1255
``/2/nodes/[node_name]/storage``
1256
++++++++++++++++++++++++++++++++
1257

    
1258
Manages storage units on the node.
1259

    
1260
``GET``
1261
~~~~~~~
1262

    
1263
Requests a list of storage units on a node. Requires the parameters
1264
``storage_type`` (one of ``file``, ``lvm-pv`` or ``lvm-vg``) and
1265
``output_fields``. The result will be a job id, using which the result
1266
can be retrieved.
1267

    
1268
``/2/nodes/[node_name]/storage/modify``
1269
+++++++++++++++++++++++++++++++++++++++
1270

    
1271
Modifies storage units on the node.
1272

    
1273
``PUT``
1274
~~~~~~~
1275

    
1276
Modifies parameters of storage units on the node. Requires the
1277
parameters ``storage_type`` (one of ``file``, ``lvm-pv`` or ``lvm-vg``)
1278
and ``name`` (name of the storage unit).  Parameters can be passed
1279
additionally. Currently only ``allocatable`` (bool) is supported. The
1280
result will be a job id.
1281

    
1282
``/2/nodes/[node_name]/storage/repair``
1283
+++++++++++++++++++++++++++++++++++++++
1284

    
1285
Repairs a storage unit on the node.
1286

    
1287
``PUT``
1288
~~~~~~~
1289

    
1290
Repairs a storage unit on the node. Requires the parameters
1291
``storage_type`` (currently only ``lvm-vg`` can be repaired) and
1292
``name`` (name of the storage unit). The result will be a job id.
1293

    
1294
``/2/nodes/[node_name]/tags``
1295
+++++++++++++++++++++++++++++
1296

    
1297
Manages per-node tags.
1298

    
1299
It supports the following commands: ``GET``, ``PUT``, ``DELETE``.
1300

    
1301
``GET``
1302
~~~~~~~
1303

    
1304
Returns a list of tags.
1305

    
1306
Example::
1307

    
1308
    ["tag1", "tag2", "tag3"]
1309

    
1310
``PUT``
1311
~~~~~~~
1312

    
1313
Add a set of tags.
1314

    
1315
The request as a list of strings should be PUT to this URI. The result
1316
will be a job id.
1317

    
1318
It supports the ``dry-run`` argument.
1319

    
1320
``DELETE``
1321
~~~~~~~~~~
1322

    
1323
Deletes tags.
1324

    
1325
In order to delete a set of tags, the DELETE request should be addressed
1326
to URI like::
1327

    
1328
    /tags?tag=[tag]&tag=[tag]
1329

    
1330
It supports the ``dry-run`` argument.
1331

    
1332

    
1333
``/2/os``
1334
+++++++++
1335

    
1336
OS resource.
1337

    
1338
It supports the following commands: ``GET``.
1339

    
1340
``GET``
1341
~~~~~~~
1342

    
1343
Return a list of all OSes.
1344

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

    
1348
Example::
1349

    
1350
    ["debian-etch"]
1351

    
1352
``/2/tags``
1353
+++++++++++
1354

    
1355
Manages cluster tags.
1356

    
1357
It supports the following commands: ``GET``, ``PUT``, ``DELETE``.
1358

    
1359
``GET``
1360
~~~~~~~
1361

    
1362
Returns the cluster tags.
1363

    
1364
Example::
1365

    
1366
    ["tag1", "tag2", "tag3"]
1367

    
1368
``PUT``
1369
~~~~~~~
1370

    
1371
Adds a set of tags.
1372

    
1373
The request as a list of strings should be PUT to this URI. The result
1374
will be a job id.
1375

    
1376
It supports the ``dry-run`` argument.
1377

    
1378

    
1379
``DELETE``
1380
~~~~~~~~~~
1381

    
1382
Deletes tags.
1383

    
1384
In order to delete a set of tags, the DELETE request should be addressed
1385
to URI like::
1386

    
1387
    /tags?tag=[tag]&tag=[tag]
1388

    
1389
It supports the ``dry-run`` argument.
1390

    
1391

    
1392
``/version``
1393
++++++++++++
1394

    
1395
The version resource.
1396

    
1397
This resource should be used to determine the remote API version and to
1398
adapt clients accordingly.
1399

    
1400
It supports the following commands: ``GET``.
1401

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

    
1405
Returns the remote API version. Ganeti 1.2 returned ``1`` and Ganeti 2.0
1406
returns ``2``.
1407

    
1408
.. vim: set textwidth=72 :
1409
.. Local Variables:
1410
.. mode: rst
1411
.. fill-column: 72
1412
.. End: