Statistics
| Branch: | Tag: | Revision:

root / doc / rapi.rst @ d8260842

History | View | Annotate | Download (13.5 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
Protocol
20
--------
21

    
22
The protocol used is JSON_ over HTTP designed after the REST_
23
principle.
24

    
25
.. _JSON: http://www.json.org/
26
.. _REST: http://en.wikipedia.org/wiki/Representational_State_Transfer
27

    
28
Generic parameters
29
------------------
30

    
31
A few parameter mean the same thing across all resources which implement it.
32

    
33
``bulk``
34
++++++++
35

    
36
Bulk-mode means that for the resources which usually return just a
37
list of child resources (e.g. ``/2/instances`` which returns just
38
instance names), the output will instead contain detailed data for all
39
these subresources. This is more efficient than query-ing the
40
sub-resources themselves.
41

    
42
``dry-run``
43
+++++++++++
44

    
45
The optional *dry-run* argument, if provided and set to a positive
46
integer value (e.g. ``?dry-run=1``), signals to Ganeti that the job
47
should not be executed, only the pre-execution checks will be done.
48

    
49
This is useful in trying to determine (without guarantees though, as
50
in the meantime the cluster state could have changed) if the operation
51
is likely to succeed or at least start executing.
52

    
53
``force``
54
+++++++++++
55

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

    
59
Usage examples
60
--------------
61

    
62
You can access the API using your favorite programming language as
63
long as it supports network connections.
64

    
65
Shell
66
+++++
67

    
68
.. highlight:: sh
69

    
70
Using wget::
71

    
72
   wget -q -O - https://CLUSTERNAME:5080/2/info
73

    
74
or curl::
75

    
76
  curl https://CLUSTERNAME:5080/2/info
77

    
78

    
79
Python
80
++++++
81

    
82
.. highlight: python
83

    
84
  import urllib2
85
  f = urllib2.urlopen('https://CLUSTERNAME:5080/2/info')
86
  print f.read()
87

    
88

    
89
JavaScript
90
++++++++++
91

    
92
.. warning:: While it's possible to use JavaScript, it poses several
93
  potential problems, including browser blocking request due to
94
  non-standard ports or different domain names. Fetching the data on
95
  the webserver is easier.
96

    
97
.. highlight:: javascript
98

    
99
::
100

    
101
  var url = 'https://CLUSTERNAME:5080/2/info';
102
  var info;
103
  var xmlreq = new XMLHttpRequest();
104
  xmlreq.onreadystatechange = function () {
105
    if (xmlreq.readyState != 4) return;
106
    if (xmlreq.status == 200) {
107
      info = eval("(" + xmlreq.responseText + ")");
108
      alert(info);
109
    } else {
110
      alert('Error fetching cluster info');
111
    }
112
    xmlreq = null;
113
  };
114
  xmlreq.open('GET', url, true);
115
  xmlreq.send(null);
116

    
117
Resources
118
---------
119

    
120
.. highlight:: javascript
121

    
122
``/``
123
+++++
124

    
125
The root resource.
126

    
127
It supports the following commands: ``GET``.
128

    
129
``GET``
130
~~~~~~~
131

    
132
Shows the list of mapped resources.
133

    
134
Returns: a dictionary with 'name' and 'uri' keys for each of them.
135

    
136
``/2``
137
++++++
138

    
139
The ``/2`` resource, the root of the version 2 API.
140

    
141
It supports the following commands: ``GET``.
142

    
143
``GET``
144
~~~~~~~
145

    
146
Show the list of mapped resources.
147

    
148
Returns: a dictionary with ``name`` and ``uri`` keys for each of them.
149

    
150
``/2/info``
151
+++++++++++
152

    
153
Cluster information resource.
154

    
155
It supports the following commands: ``GET``.
156

    
157
``GET``
158
~~~~~~~
159

    
160
Returns cluster information.
161

    
162
Example::
163

    
164
  {
165
    "config_version": 2000000,
166
    "name": "cluster",
167
    "software_version": "2.0.0~beta2",
168
    "os_api_version": 10,
169
    "export_version": 0,
170
    "candidate_pool_size": 10,
171
    "enabled_hypervisors": [
172
      "fake"
173
    ],
174
    "hvparams": {
175
      "fake": {}
176
     },
177
    "default_hypervisor": "fake",
178
    "master": "node1.example.com",
179
    "architecture": [
180
      "64bit",
181
      "x86_64"
182
    ],
183
    "protocol_version": 20,
184
    "beparams": {
185
      "default": {
186
        "auto_balance": true,
187
        "vcpus": 1,
188
        "memory": 128
189
       }
190
      }
191
    }
192

    
193
``/2/instances``
194
++++++++++++++++
195

    
196
The instances resource.
197

    
198
It supports the following commands: ``GET``, ``POST``.
199

    
200
``GET``
201
~~~~~~~
202

    
203
Returns a list of all available instances.
204

    
205
Example::
206

    
207
    [
208
      {
209
        "name": "web.example.com",
210
        "uri": "\/instances\/web.example.com"
211
      },
212
      {
213
        "name": "mail.example.com",
214
        "uri": "\/instances\/mail.example.com"
215
      }
216
    ]
217

    
218
If the optional *bulk* argument is provided and set to a true value
219
(i.e ``?bulk=1``), the output contains detailed information about
220
instances as a list.
221

    
222
Example::
223

    
224
    [
225
      {
226
         "status": "running",
227
         "disk_usage": 20480,
228
         "nic.bridges": [
229
           "xen-br0"
230
          ],
231
         "name": "web.example.com",
232
         "tags": ["tag1", "tag2"],
233
         "beparams": {
234
           "vcpus": 2,
235
           "memory": 512
236
         },
237
         "disk.sizes": [
238
             20480
239
         ],
240
         "pnode": "node1.example.com",
241
         "nic.macs": ["01:23:45:67:89:01"],
242
         "snodes": ["node2.example.com"],
243
         "disk_template": "drbd",
244
         "admin_state": true,
245
         "os": "debian-etch",
246
         "oper_state": true
247
      },
248
      ...
249
    ]
250

    
251

    
252
``POST``
253
~~~~~~~~
254

    
255
Creates an instance.
256

    
257
If the optional *dry-run* argument is provided and set to a positive
258
integer valu (e.g. ``?dry-run=1``), the job will not be actually
259
executed, only the pre-execution checks will be done. Query-ing the
260
job result will return, in both dry-run and normal case, the list of
261
nodes selected for the instance.
262

    
263
Returns: a job ID that can be used later for polling.
264

    
265
``/2/instances/[instance_name]``
266
++++++++++++++++++++++++++++++++
267

    
268
Instance-specific resource.
269

    
270
It supports the following commands: ``GET``, ``DELETE``.
271

    
272
``GET``
273
~~~~~~~
274

    
275
Returns information about an instance, similar to the bulk output from
276
the instance list.
277

    
278
``DELETE``
279
~~~~~~~~~~
280

    
281
Deletes an instance.
282

    
283
It supports the ``dry-run`` argument.
284

    
285

    
286
``/2/instances/[instance_name]/info``
287
+++++++++++++++++++++++++++++++++++++++
288

    
289
It supports the following commands: ``GET``.
290

    
291
``GET``
292
~~~~~~~
293

    
294
Requests detailed information about the instance. An optional parameter,
295
``static`` (bool), can be set to return only static information from the
296
configuration without querying the instance's nodes. The result will be a job
297
id.
298

    
299

    
300
``/2/instances/[instance_name]/reboot``
301
+++++++++++++++++++++++++++++++++++++++
302

    
303
Reboots URI for an instance.
304

    
305
It supports the following commands: ``POST``.
306

    
307
``POST``
308
~~~~~~~~
309

    
310
Reboots the instance.
311

    
312
The URI takes optional ``type=hard|soft|full`` and
313
``ignore_secondaries=False|True`` parameters.
314

    
315
It supports the ``dry-run`` argument.
316

    
317

    
318
``/2/instances/[instance_name]/shutdown``
319
+++++++++++++++++++++++++++++++++++++++++
320

    
321
Instance shutdown URI.
322

    
323
It supports the following commands: ``PUT``.
324

    
325
``PUT``
326
~~~~~~~
327

    
328
Shutdowns an instance.
329

    
330
It supports the ``dry-run`` argument.
331

    
332

    
333
``/2/instances/[instance_name]/startup``
334
++++++++++++++++++++++++++++++++++++++++
335

    
336
Instance startup URI.
337

    
338
It supports the following commands: ``PUT``.
339

    
340
``PUT``
341
~~~~~~~
342

    
343
Startup an instance.
344

    
345
The URI takes an optional ``force=False|True`` parameter to start the
346
instance if even if secondary disks are failing.
347

    
348
It supports the ``dry-run`` argument.
349

    
350

    
351
``/2/instances/[instance_name]/replace-disks``
352
++++++++++++++++++++++++++++++++++++++++++++++
353

    
354
Replaces disks on an instance.
355

    
356
It supports the following commands: ``POST``.
357

    
358
``POST``
359
~~~~~~~~
360

    
361
Takes the parameters ``mode`` (one of ``replace_on_primary``,
362
``replace_on_secondary``, ``replace_new_secondary`` or ``replace_auto``),
363
``disks`` (comma separated list of disk indexes), ``remote_node`` and
364
``iallocator``.
365

    
366

    
367
``/2/instances/[instance_name]/tags``
368
+++++++++++++++++++++++++++++++++++++
369

    
370
Manages per-instance tags.
371

    
372
It supports the following commands: ``GET``, ``PUT``, ``DELETE``.
373

    
374
``GET``
375
~~~~~~~
376

    
377
Returns a list of tags.
378

    
379
Example::
380

    
381
    ["tag1", "tag2", "tag3"]
382

    
383
``PUT``
384
~~~~~~~
385

    
386
Add a set of tags.
387

    
388
The request as a list of strings should be ``PUT`` to this URI. The
389
result willl be a job id.
390

    
391
It supports the ``dry-run`` argument.
392

    
393

    
394
``DELETE``
395
~~~~~~~~~~
396

    
397
Delete a tag.
398

    
399
In order to delete a set of tags, the DELETE request should be
400
addressed to URI like::
401

    
402
    /tags?tag=[tag]&tag=[tag]
403

    
404
It supports the ``dry-run`` argument.
405

    
406

    
407
``/2/jobs``
408
+++++++++++
409

    
410
The ``/2/jobs`` resource.
411

    
412
It supports the following commands: ``GET``.
413

    
414
``GET``
415
~~~~~~~
416

    
417
Returns a dictionary of jobs.
418

    
419
Returns: a dictionary with jobs id and uri.
420

    
421
``/2/jobs/[job_id]``
422
++++++++++++++++++++
423

    
424

    
425
Individual job URI.
426

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

    
429
``GET``
430
~~~~~~~
431

    
432
Returns a job status.
433

    
434
Returns: a dictionary with job parameters.
435

    
436
The result includes:
437

    
438
- id: job ID as a number
439
- status: current job status as a string
440
- ops: involved OpCodes as a list of dictionaries for each
441
  opcodes in the job
442
- opstatus: OpCodes status as a list
443
- opresult: OpCodes results as a list of lists
444

    
445
``DELETE``
446
~~~~~~~~~~
447

    
448
Cancel a not-yet-started job.
449

    
450
``/2/nodes``
451
++++++++++++
452

    
453
Nodes resource.
454

    
455
It supports the following commands: ``GET``.
456

    
457
``GET``
458
~~~~~~~
459

    
460
Returns a list of all nodes.
461

    
462
Example::
463

    
464
    [
465
      {
466
        "id": "node1.example.com",
467
        "uri": "\/instances\/node1.example.com"
468
      },
469
      {
470
        "id": "node2.example.com",
471
        "uri": "\/instances\/node2.example.com"
472
      }
473
    ]
474

    
475
If the optional 'bulk' argument is provided and set to 'true' value
476
(i.e '?bulk=1'), the output contains detailed information about nodes
477
as a list.
478

    
479
Example::
480

    
481
    [
482
      {
483
        "pinst_cnt": 1,
484
        "mfree": 31280,
485
        "mtotal": 32763,
486
        "name": "www.example.com",
487
        "tags": [],
488
        "mnode": 512,
489
        "dtotal": 5246208,
490
        "sinst_cnt": 2,
491
        "dfree": 5171712,
492
        "offline": false
493
      },
494
      ...
495
    ]
496

    
497
``/2/nodes/[node_name]/evacuate``
498
+++++++++++++++++++++++++++++++++
499

    
500
Evacuates all secondary instances off a node.
501

    
502
It supports the following commands: ``POST``.
503

    
504
``POST``
505
~~~~~~~~
506

    
507
To evacuate a node, either one of the ``iallocator`` or ``remote_node``
508
parameters must be passed:
509

    
510
    evacuate?iallocator=[iallocator]
511
    evacuate?remote_node=[nodeX.example.com]
512

    
513
``/2/nodes/[node_name]/migrate``
514
+++++++++++++++++++++++++++++++++
515

    
516
Migrates all primary instances from a node.
517

    
518
It supports the following commands: ``POST``.
519

    
520
``POST``
521
~~~~~~~~
522

    
523
No parameters are required, but ``live`` can be set to a boolean value.
524

    
525
    migrate?live=[0|1]
526

    
527
``/2/nodes/[node_name]/role``
528
+++++++++++++++++++++++++++++
529

    
530
Manages node role.
531

    
532
It supports the following commands: ``GET``, ``PUT``.
533

    
534
The role is always one of the following:
535

    
536
  - drained
537
  - master
538
  - master-candidate
539
  - offline
540
  - regular
541

    
542
``GET``
543
~~~~~~~
544

    
545
Returns the current node role.
546

    
547
Example::
548

    
549
    "master-candidate"
550

    
551
``PUT``
552
~~~~~~~
553

    
554
Change the node role.
555

    
556
The request is a string which should be PUT to this URI. The result will be a
557
job id.
558

    
559
It supports the ``force`` argument.
560

    
561
``/2/nodes/[node_name]/storage``
562
++++++++++++++++++++++++++++++++
563

    
564
Manages storage units on the node.
565

    
566
``GET``
567
~~~~~~~
568

    
569
Requests a list of storage units on a node. Requires the parameters
570
``storage_type`` (one of ``file``, ``lvm-pv`` or ``lvm-vg``) and
571
``output_fields``. The result will be a job id, using which the result can be
572
retrieved.
573

    
574
``/2/nodes/[node_name]/storage/modify``
575
+++++++++++++++++++++++++++++++++++++++
576

    
577
Modifies storage units on the node.
578

    
579
``PUT``
580
~~~~~~~
581

    
582
Modifies parameters of storage units on the node. Requires the parameters
583
``storage_type`` (one of ``file``, ``lvm-pv`` or ``lvm-vg``) and ``name`` (name
584
of the storage unit).  Parameters can be passed additionally. Currently only
585
``allocatable`` (bool) is supported. The result will be a job id.
586

    
587
``/2/nodes/[node_name]/storage/repair``
588
+++++++++++++++++++++++++++++++++++++++
589

    
590
Repairs a storage unit on the node.
591

    
592
``PUT``
593
~~~~~~~
594

    
595
Repairs a storage unit on the node. Requires the parameters ``storage_type``
596
(currently only ``lvm-vg`` can be repaired) and ``name`` (name of the storage
597
unit). The result will be a job id.
598

    
599
``/2/nodes/[node_name]/tags``
600
+++++++++++++++++++++++++++++
601

    
602
Manages per-node tags.
603

    
604
It supports the following commands: ``GET``, ``PUT``, ``DELETE``.
605

    
606
``GET``
607
~~~~~~~
608

    
609
Returns a list of tags.
610

    
611
Example::
612

    
613
    ["tag1", "tag2", "tag3"]
614

    
615
``PUT``
616
~~~~~~~
617

    
618
Add a set of tags.
619

    
620
The request as a list of strings should be PUT to this URI. The result
621
will be a job id.
622

    
623
It supports the ``dry-run`` argument.
624

    
625
``DELETE``
626
~~~~~~~~~~
627

    
628
Deletes tags.
629

    
630
In order to delete a set of tags, the DELETE request should be
631
addressed to URI like::
632

    
633
    /tags?tag=[tag]&tag=[tag]
634

    
635
It supports the ``dry-run`` argument.
636

    
637

    
638
``/2/os``
639
+++++++++
640

    
641
OS resource.
642

    
643
It supports the following commands: ``GET``.
644

    
645
``GET``
646
~~~~~~~
647

    
648
Return a list of all OSes.
649

    
650
Can return error 500 in case of a problem. Since this is a costly
651
operation for Ganeti 2.0, it is not recommended to execute it too
652
often.
653

    
654
Example::
655

    
656
    ["debian-etch"]
657

    
658
``/2/tags``
659
+++++++++++
660

    
661
Manages cluster tags.
662

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

    
665
``GET``
666
~~~~~~~
667

    
668
Returns the cluster tags.
669

    
670
Example::
671

    
672
    ["tag1", "tag2", "tag3"]
673

    
674
``PUT``
675
~~~~~~~
676

    
677
Adds a set of tags.
678

    
679
The request as a list of strings should be PUT to this URI. The result
680
will be a job id.
681

    
682
It supports the ``dry-run`` argument.
683

    
684

    
685
``DELETE``
686
~~~~~~~~~~
687

    
688
Deletes tags.
689

    
690
In order to delete a set of tags, the DELETE request should be
691
addressed to URI like::
692

    
693
    /tags?tag=[tag]&tag=[tag]
694

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

    
697

    
698
``/version``
699
++++++++++++
700

    
701
The version resource.
702

    
703
This resource should be used to determine the remote API version and
704
to adapt clients accordingly.
705

    
706
It supports the following commands: ``GET``.
707

    
708
``GET``
709
~~~~~~~
710

    
711
Returns the remote API version. Ganeti 1.2 returned ``1`` and Ganeti
712
2.0 returns ``2``.