Statistics
| Branch: | Tag: | Revision:

root / doc / rapi.rst @ 2cad4b91

History | View | Annotate | Download (10.4 kB)

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

    
4
Documents Ganeti version |version|
5

    
6
.. contents::
7

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

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

    
19
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
Usage examples
54
--------------
55

    
56
You can access the API using your favorite programming language as
57
long as it supports network connections.
58

    
59
Shell
60
+++++
61

    
62
.. highlight:: sh
63

    
64
Using wget::
65

    
66
   wget -q -O - https://CLUSTERNAME:5080/2/info
67

    
68
or curl::
69

    
70
  curl https://CLUSTERNAME:5080/2/info
71

    
72

    
73
Python
74
++++++
75

    
76
.. highlight: python
77

    
78
  import urllib2
79
  f = urllib2.urlopen('https://CLUSTERNAME:5080/2/info')
80
  print f.read()
81

    
82

    
83
JavaScript
84
++++++++++
85

    
86
.. warning:: While it's possible to use JavaScript, it poses several
87
  potential problems, including browser blocking request due to
88
  non-standard ports or different domain names. Fetching the data on
89
  the webserver is easier.
90

    
91
.. highlight:: javascript
92

    
93
::
94

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

    
111
Resources
112
---------
113

    
114
.. highlight:: javascript
115

    
116
``/``
117
+++++
118

    
119
The root resource.
120

    
121
It supports the following commands: ``GET``.
122

    
123
``GET``
124
~~~~~~~
125

    
126
Shows the list of mapped resources.
127

    
128
Returns: a dictionary with 'name' and 'uri' keys for each of them.
129

    
130
``/2``
131
++++++
132

    
133
The ``/2`` resource, the root of the version 2 API.
134

    
135
It supports the following commands: ``GET``.
136

    
137
``GET``
138
~~~~~~~
139

    
140
Show the list of mapped resources.
141

    
142
Returns: a dictionary with ``name`` and ``uri`` keys for each of them.
143

    
144
``/2/info``
145
+++++++++++
146

    
147
Cluster information resource.
148

    
149
It supports the following commands: ``GET``.
150

    
151
``GET``
152
~~~~~~~
153

    
154
Returns cluster information.
155

    
156
Example::
157

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

    
187
``/2/instances``
188
++++++++++++++++
189

    
190
The instances resource.
191

    
192
It supports the following commands: ``GET``, ``POST``.
193

    
194
``GET``
195
~~~~~~~
196

    
197
Returns a list of all available instances.
198

    
199
Example::
200

    
201
    [
202
      {
203
        "name": "web.example.com",
204
        "uri": "\/instances\/web.example.com"
205
      },
206
      {
207
        "name": "mail.example.com",
208
        "uri": "\/instances\/mail.example.com"
209
      }
210
    ]
211

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

    
216
Example::
217

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

    
245

    
246
``POST``
247
~~~~~~~~
248

    
249
Creates an instance.
250

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

    
257
Returns: a job ID that can be used later for polling.
258

    
259
``/2/instances/[instance_name]``
260
++++++++++++++++++++++++++++++++
261

    
262
Instance-specific resource.
263

    
264
It supports the following commands: ``GET``, ``DELETE``.
265

    
266
``GET``
267
~~~~~~~
268

    
269
Returns information about an instance, similar to the bulk output from
270
the instance list.
271

    
272
``DELETE``
273
~~~~~~~~~~
274

    
275
Deletes an instance.
276

    
277
It supports the ``dry-run`` argument.
278

    
279

    
280
``/2/instances/[instance_name]/reboot``
281
+++++++++++++++++++++++++++++++++++++++
282

    
283
Reboots URI for an instance.
284

    
285
It supports the following commands: ``POST``.
286

    
287
``POST``
288
~~~~~~~~
289

    
290
Reboots the instance.
291

    
292
The URI takes optional ``type=hard|soft|full`` and
293
``ignore_secondaries=False|True`` parameters.
294

    
295
It supports the ``dry-run`` argument.
296

    
297

    
298
``/2/instances/[instance_name]/shutdown``
299
+++++++++++++++++++++++++++++++++++++++++
300

    
301
Instance shutdown URI.
302

    
303
It supports the following commands: ``PUT``.
304

    
305
``PUT``
306
~~~~~~~
307

    
308
Shutdowns an instance.
309

    
310
It supports the ``dry-run`` argument.
311

    
312

    
313
``/2/instances/[instance_name]/startup``
314
++++++++++++++++++++++++++++++++++++++++
315

    
316
Instance startup URI.
317

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

    
320
``PUT``
321
~~~~~~~
322

    
323
Startup an instance.
324

    
325
The URI takes an optional ``force=False|True`` parameter to start the
326
instance if even if secondary disks are failing.
327

    
328
It supports the ``dry-run`` argument.
329

    
330

    
331
``/2/instances/[instance_name]/tags``
332
+++++++++++++++++++++++++++++++++++++
333

    
334
Manages per-instance tags.
335

    
336
It supports the following commands: ``GET``, ``PUT``, ``DELETE``.
337

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

    
341
Returns a list of tags.
342

    
343
Example::
344

    
345
    ["tag1", "tag2", "tag3"]
346

    
347
``PUT``
348
~~~~~~~
349

    
350
Add a set of tags.
351

    
352
The request as a list of strings should be ``PUT`` to this URI. The
353
result willl be a job id.
354

    
355
It supports the ``dry-run`` argument.
356

    
357

    
358
``DELETE``
359
~~~~~~~~~~
360

    
361
Delete a tag.
362

    
363
In order to delete a set of tags, the DELETE request should be
364
addressed to URI like::
365

    
366
    /tags?tag=[tag]&tag=[tag]
367

    
368
It supports the ``dry-run`` argument.
369

    
370

    
371
``/2/jobs``
372
+++++++++++
373

    
374
The ``/2/jobs`` resource.
375

    
376
It supports the following commands: ``GET``.
377

    
378
``GET``
379
~~~~~~~
380

    
381
Returns a dictionary of jobs.
382

    
383
Returns: a dictionary with jobs id and uri.
384

    
385
``/2/jobs/[job_id]``
386
++++++++++++++++++++
387

    
388

    
389
Individual job URI.
390

    
391
It supports the following commands: ``GET``, ``DELETE``.
392

    
393
``GET``
394
~~~~~~~
395

    
396
Returns a job status.
397

    
398
Returns: a dictionary with job parameters.
399

    
400
The result includes:
401

    
402
- id: job ID as a number
403
- status: current job status as a string
404
- ops: involved OpCodes as a list of dictionaries for each
405
  opcodes in the job
406
- opstatus: OpCodes status as a list
407
- opresult: OpCodes results as a list of lists
408

    
409
``DELETE``
410
~~~~~~~~~~
411

    
412
Cancel a not-yet-started job.
413

    
414
``/2/nodes``
415
++++++++++++
416

    
417
Nodes resource.
418

    
419
It supports the following commands: ``GET``.
420

    
421
``GET``
422
~~~~~~~
423

    
424
Returns a list of all nodes.
425

    
426
Example::
427

    
428
    [
429
      {
430
        "id": "node1.example.com",
431
        "uri": "\/instances\/node1.example.com"
432
      },
433
      {
434
        "id": "node2.example.com",
435
        "uri": "\/instances\/node2.example.com"
436
      }
437
    ]
438

    
439
If the optional 'bulk' argument is provided and set to 'true' value
440
(i.e '?bulk=1'), the output contains detailed information about nodes
441
as a list.
442

    
443
Example::
444

    
445
    [
446
      {
447
        "pinst_cnt": 1,
448
        "mfree": 31280,
449
        "mtotal": 32763,
450
        "name": "www.example.com",
451
        "tags": [],
452
        "mnode": 512,
453
        "dtotal": 5246208,
454
        "sinst_cnt": 2,
455
        "dfree": 5171712,
456
        "offline": false
457
      },
458
      ...
459
    ]
460

    
461
``/2/nodes/[node_name]/tags``
462
+++++++++++++++++++++++++++++
463

    
464
Manages per-node tags.
465

    
466
It supports the following commands: ``GET``, ``PUT``, ``DELETE``.
467

    
468
``GET``
469
~~~~~~~
470

    
471
Returns a list of tags.
472

    
473
Example::
474

    
475
    ["tag1", "tag2", "tag3"]
476

    
477
``PUT``
478
~~~~~~~
479

    
480
Add a set of tags.
481

    
482
The request as a list of strings should be PUT to this URI. The result
483
will be a job id.
484

    
485
It supports the ``dry-run`` argument.
486

    
487
``DELETE``
488
~~~~~~~~~~
489

    
490
Deletes tags.
491

    
492
In order to delete a set of tags, the DELETE request should be
493
addressed to URI like::
494

    
495
    /tags?tag=[tag]&tag=[tag]
496

    
497
It supports the ``dry-run`` argument.
498

    
499

    
500
``/2/os``
501
+++++++++
502

    
503
OS resource.
504

    
505
It supports the following commands: ``GET``.
506

    
507
``GET``
508
~~~~~~~
509

    
510
Return a list of all OSes.
511

    
512
Can return error 500 in case of a problem. Since this is a costly
513
operation for Ganeti 2.0, it is not recommended to execute it too
514
often.
515

    
516
Example::
517

    
518
    ["debian-etch"]
519

    
520
``/2/tags``
521
+++++++++++
522

    
523
Manages cluster tags.
524

    
525
It supports the following commands: ``GET``, ``PUT``, ``DELETE``.
526

    
527
``GET``
528
~~~~~~~
529

    
530
Returns the cluster tags.
531

    
532
Example::
533

    
534
    ["tag1", "tag2", "tag3"]
535

    
536
``PUT``
537
~~~~~~~
538

    
539
Adds a set of tags.
540

    
541
The request as a list of strings should be PUT to this URI. The result
542
will be a job id.
543

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

    
546

    
547
``DELETE``
548
~~~~~~~~~~
549

    
550
Deletes tags.
551

    
552
In order to delete a set of tags, the DELETE request should be
553
addressed to URI like::
554

    
555
    /tags?tag=[tag]&tag=[tag]
556

    
557
It supports the ``dry-run`` argument.
558

    
559

    
560
``/version``
561
++++++++++++
562

    
563
The version resource.
564

    
565
This resource should be used to determine the remote API version and
566
to adapt clients accordingly.
567

    
568
It supports the following commands: ``GET``.
569

    
570
``GET``
571
~~~~~~~
572

    
573
Returns the remote API version. Ganeti 1.2 returned ``1`` and Ganeti
574
2.0 returns ``2``.