~ubuntu-cloud-archive/ubuntu/precise/glance/folsom

« back to all changes in this revision

Viewing changes to doc/source/glanceapi.rst

  • Committer: Package Import Robot
  • Author(s): Chuck Short, Chuck Short, Soren Hansen
  • Date: 2012-09-07 12:17:46 UTC
  • mfrom: (1.1.42)
  • Revision ID: package-import@ubuntu.com-20120907121746-a4i0aewhlzb7vw31
Tags: 2012.2~rc1~20120907.129.f0bd856-0ubuntu1
[ Chuck Short ]
* New upstream version.
* drop debian/patches/fix-docs-build.patch. 
* debian/rules: Re-activate tests.
* debain/control: Add depends on python-swiftclient.
* debian/*.usptart: make glance start from runlevel 1 to runlevel
  2. (LP: #820688)

[ Soren Hansen ]
* Update debian/watch to account for symbolically named tarballs and
  use newer URL.
* New snapshot.
* Refresh disable-network-for-docs.patch
* Fix Launchpad URLs in debian/watch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
      License for the specific language governing permissions and limitations
15
15
      under the License.
16
16
 
17
 
The Glance REST API
18
 
===================
19
 
 
20
 
Glance has a RESTful API that exposes both metadata about registered virtual
21
 
machine images and the image data itself.
22
 
 
23
 
A host that runs the ``bin/glance-api`` service is said to be a *Glance API
24
 
Server*.
25
 
 
26
 
Assume there is a Glance API server running at the URL
27
 
``http://glance.example.com``.
28
 
 
29
 
Let's walk through how a user might request information from this server.
30
 
 
31
 
Requesting a List of Public VM Images
32
 
-------------------------------------
33
 
 
34
 
We want to see a list of available virtual machine images that the Glance
35
 
server knows about.
36
 
 
37
 
We issue a ``GET`` request to ``http://glance.example.com/images/`` to retrieve
38
 
this list of available *public* images. The data is returned as a JSON-encoded
 
17
Using Glance's Public APIs
 
18
==========================
 
19
 
 
20
Glance fully implements versions 1.0, 1.1 and 2.0 of the OpenStack Images API.
 
21
The Images API specification is developed alongside Glance, but is not
 
22
considered part of the Glance project.
 
23
 
 
24
Authentication
 
25
--------------
 
26
 
 
27
Glance depends on Keystone and the OpenStack Identity API to handle
 
28
authentication of clients. You must obtain an authentication token from
 
29
Keystone using and send it along with all API requests to Glance through
 
30
the ``X-Auth-Token`` header. Glance will communicate back to Keystone to
 
31
verify the token validity and obtain your identity credentials.
 
32
 
 
33
See :doc:`authentication` for more information on integrating with Keystone.
 
34
 
 
35
Using v1.X
 
36
----------
 
37
 
 
38
For the purpose of examples, assume there is a Glance API server running
 
39
at the URL ``http://glance.example.com`` on the default port 80.
 
40
 
 
41
List Available Images
 
42
*********************
 
43
 
 
44
We want to see a list of available images that the authenticated user has
 
45
access to. This includes images owned by the user, images shared with the user
 
46
and public images.
 
47
 
 
48
We issue a ``GET`` request to ``http://glance.example.com/v1/images`` to
 
49
retrieve this list of available images. The data is returned as a JSON-encoded
39
50
mapping in the following format::
40
51
 
41
52
  {'images': [
42
 
    {'uri': 'http://glance.example.com/images/71c675ab-d94f-49cd-a114-e12490b328d9',
 
53
    {'uri': 'http://glance.example.com/v1/images/71c675ab-d94f-49cd-a114-e12490b328d9',
43
54
     'name': 'Ubuntu 10.04 Plain',
44
55
     'disk_format': 'vhd',
45
56
     'container_format': 'ovf',
46
57
     'size': '5368709120'}
47
58
    ...]}
48
59
 
49
 
.. note::
50
 
 
51
 
  All images returned from the above `GET` request are *public* images
52
 
 
53
 
 
54
 
Requesting Detailed Metadata on Public VM Images
55
 
------------------------------------------------
56
 
 
57
 
We want to see more detailed information on available virtual machine images
58
 
that the Glance server knows about.
59
 
 
60
 
We issue a ``GET`` request to ``http://glance.example.com/images/detail`` to
61
 
retrieve this list of available *public* images. The data is returned as a
 
60
 
 
61
List Available Images in More Detail
 
62
************************************
 
63
 
 
64
We want to see a more detailed list of available images that the authenticated
 
65
user has access to. This includes images owned by the user, images shared with
 
66
the user and public images.
 
67
 
 
68
We issue a ``GET`` request to ``http://glance.example.com/v1/images/detail`` to
 
69
retrieve this list of available images. The data is returned as a
62
70
JSON-encoded mapping in the following format::
63
71
 
64
72
  {'images': [
65
 
    {'uri': 'http://glance.example.com/images/71c675ab-d94f-49cd-a114-e12490b328d9',
 
73
    {'uri': 'http://glance.example.com/v1/images/71c675ab-d94f-49cd-a114-e12490b328d9',
66
74
     'name': 'Ubuntu 10.04 Plain 5GB',
67
75
     'disk_format': 'vhd',
68
76
     'container_format': 'ovf',
81
89
 
82
90
.. note::
83
91
 
84
 
  All images returned from the above `GET` request are *public* images
85
 
 
86
92
  All timestamps returned are in UTC
87
93
 
88
94
  The `updated_at` timestamp is the timestamp when an image's metadata
106
112
  The `owner` field is a string which may either be null or which will
107
113
  indicate the owner of the image
108
114
 
109
 
Filtering Images Returned via ``GET /images`` and ``GET /images/detail``
110
 
------------------------------------------------------------------------
 
115
Filtering Images Lists
 
116
**********************
111
117
 
112
 
Both the ``GET /images`` and ``GET /images/detail`` requests take query
 
118
Both the ``GET /v1/images`` and ``GET /v1/images/detail`` requests take query
113
119
parameters that serve to filter the returned list of images. The following
114
120
list details these query parameters.
115
121
 
156
162
  Results will be sorted in the direction ``DIR``. Accepted values are ``asc``
157
163
  for ascending or ``desc`` (default) for descending.
158
164
 
159
 
 
160
 
Requesting Detailed Metadata on a Specific Image
161
 
------------------------------------------------
 
165
Retrieve Image Metadata
 
166
***********************
162
167
 
163
168
We want to see detailed information for a specific virtual machine image
164
169
that the Glance server knows about.
165
170
 
166
 
We have queried the Glance server for a list of public images and the
 
171
We have queried the Glance server for a list of images and the
167
172
data returned includes the `uri` field for each available image. This
168
173
`uri` field value contains the exact location needed to get the metadata
169
174
for a specific image.
170
175
 
171
176
Continuing the example from above, in order to get metadata about the
172
 
first public image returned, we can issue a ``HEAD`` request to the Glance
 
177
first image returned, we can issue a ``HEAD`` request to the Glance
173
178
server for the image's URI.
174
179
 
175
180
We issue a ``HEAD`` request to
176
 
``http://glance.example.com/images/71c675ab-d94f-49cd-a114-e12490b328d9`` to
 
181
``http://glance.example.com/v1/images/71c675ab-d94f-49cd-a114-e12490b328d9`` to
177
182
retrieve complete metadata for that image. The metadata is returned as a
178
183
set of HTTP headers that begin with the prefix ``x-image-meta-``. The
179
184
following shows an example of the HTTP headers returned from the above
180
185
``HEAD`` request::
181
186
 
182
 
  x-image-meta-uri              http://glance.example.com/images/71c675ab-d94f-49cd-a114-e12490b328d9
 
187
  x-image-meta-uri              http://glance.example.com/v1/images/71c675ab-d94f-49cd-a114-e12490b328d9
183
188
  x-image-meta-name             Ubuntu 10.04 Plain 5GB
184
189
  x-image-meta-disk_format      vhd
185
190
  x-image-meta-container_format ovf
218
223
  be null or which will indicate the owner of the image
219
224
 
220
225
 
221
 
Retrieving a Virtual Machine Image
222
 
----------------------------------
 
226
Retrieve Raw Image Data
 
227
***********************
223
228
 
224
229
We want to retrieve that actual raw data for a specific virtual machine image
225
230
that the Glance server knows about.
226
231
 
227
 
We have queried the Glance server for a list of public images and the
 
232
We have queried the Glance server for a list of images and the
228
233
data returned includes the `uri` field for each available image. This
229
234
`uri` field value contains the exact location needed to get the metadata
230
235
for a specific image.
231
236
 
232
237
Continuing the example from above, in order to get metadata about the
233
 
first public image returned, we can issue a ``HEAD`` request to the Glance
 
238
first image returned, we can issue a ``HEAD`` request to the Glance
234
239
server for the image's URI.
235
240
 
236
241
We issue a ``GET`` request to
237
 
``http://glance.example.com/images/71c675ab-d94f-49cd-a114-e12490b328d9`` to
 
242
``http://glance.example.com/v1/images/71c675ab-d94f-49cd-a114-e12490b328d9`` to
238
243
retrieve metadata for that image as well as the image itself encoded
239
244
into the response body.
240
245
 
242
247
prefix ``x-image-meta-``. The following shows an example of the HTTP headers
243
248
returned from the above ``GET`` request::
244
249
 
245
 
  x-image-meta-uri              http://glance.example.com/images/71c675ab-d94f-49cd-a114-e12490b328d9
 
250
  x-image-meta-uri              http://glance.example.com/v1/images/71c675ab-d94f-49cd-a114-e12490b328d9
246
251
  x-image-meta-name             Ubuntu 10.04 Plain 5GB
247
252
  x-image-meta-disk_format      vhd
248
253
  x-image-meta-container_format ovf
288
293
  `application/octet-stream`.
289
294
 
290
295
 
291
 
Adding a New Virtual Machine Image
292
 
----------------------------------
 
296
Add a New Image
 
297
***************
293
298
 
294
299
We have created a new virtual machine image in some way (created a
295
300
"golden image" or snapshotted/backed up an existing image) and we
303
308
at ``glance.example.com``, we issue a ``POST`` request to add an image to
304
309
Glance::
305
310
 
306
 
  POST http://glance.example.com/images/
 
311
  POST http://glance.example.com/v1/images
307
312
 
308
313
The metadata about the image is sent to Glance in HTTP headers. The body
309
314
of the HTTP request to the Glance API will be the MIME-encoded disk
310
315
image data.
311
316
 
312
317
 
313
 
Adding Image Metadata in HTTP Headers
314
 
*************************************
 
318
**Image Metadata in HTTP Headers**
315
319
 
316
320
Glance will view as image metadata any HTTP header that it receives in a
317
321
``POST`` request where the header key is prefixed with the strings
396
400
  a public image, meaning that any user may view its metadata and may read
397
401
  the disk image from Glance.
398
402
 
399
 
  When not present, the image is assumed to be *not public* and specific to
 
403
  When not present, the image is assumed to be *not public* and owned by
400
404
  a user.
401
405
 
402
406
* ``x-image-meta-min-ram``
444
448
  of image properties.
445
449
 
446
450
 
447
 
Updating an Image
448
 
*****************
 
451
Update an Image
 
452
***************
449
453
 
450
454
Glance will view as image metadata any HTTP header that it receives in a
451
455
``PUT`` request where the header key is prefixed with the strings
462
466
See more about image statuses here: :doc:`Image Statuses <statuses>`
463
467
 
464
468
 
465
 
Requesting Image Memberships
466
 
----------------------------
 
469
List Image Memberships
 
470
**********************
467
471
 
468
472
We want to see a list of the other system tenants (or users, if
469
473
"owner_is_tenant" is False) that may access a given virtual machine image that
471
475
append ``/members`` to it, and issue a ``GET`` request on the resulting URL.
472
476
 
473
477
Continuing from the example above, in order to get the memberships for the
474
 
first public image returned, we can issue a ``GET`` request to the Glance
 
478
first image returned, we can issue a ``GET`` request to the Glance
475
479
server for
476
 
``http://glance.example.com/images/71c675ab-d94f-49cd-a114-e12490b328d9/members``
 
480
``http://glance.example.com/v1/images/71c675ab-d94f-49cd-a114-e12490b328d9/members``
477
481
.  What we will get back is JSON data such as the following::
478
482
 
479
483
  {'members': [
486
490
`true`.
487
491
 
488
492
 
489
 
Requesting Shared Images
490
 
------------------------
 
493
List Shared Images
 
494
******************
491
495
 
492
496
We want to see a list of images which are shared with a given tenant.  We issue
493
 
a ``GET`` request to ``http://glance.example.com/shared-images/tenant1``.  We
 
497
a ``GET`` request to ``http://glance.example.com/v1/shared-images/tenant1``.  We
494
498
will get back JSON data such as the following::
495
499
 
496
500
  {'shared_images': [
503
507
`can_share` field is `true`.
504
508
 
505
509
 
506
 
Adding a Member to an Image
507
 
---------------------------
 
510
Add a Member to an Image
 
511
************************
508
512
 
509
513
We want to authorize a tenant to access a private image.  We issue a ``PUT``
510
514
request to
511
 
``http://glance.example.com/images/71c675ab-d94f-49cd-a114-e12490b328d9/members/tenant1``
 
515
``http://glance.example.com/v1/images/71c675ab-d94f-49cd-a114-e12490b328d9/members/tenant1``
512
516
.  With no body, this will add the membership to the image, leaving existing
513
517
memberships unmodified and defaulting new memberships to have `can_share`
514
518
set to `false`. We may also optionally attach a body of the following form::
522
526
will return a 204 ("No Content") status code.
523
527
 
524
528
 
525
 
Removing a Member from an Image
526
 
-------------------------------
 
529
Remove a Member from an Image
 
530
*****************************
527
531
 
528
532
We want to revoke a tenant's right to access a private image.  We issue a
529
 
``DELETE`` request to ``http://glance.example.com/images/1/members/tenant1``.
 
533
``DELETE`` request to ``http://glance.example.com/v1/images/1/members/tenant1``.
530
534
This query will return a 204 ("No Content") status code.
531
535
 
532
536
 
533
 
Replacing a Membership List for an Image
534
 
----------------------------------------
 
537
Replace a Membership List for an Image
 
538
**************************************
535
539
 
536
540
The full membership list for a given image may be replaced.  We issue a ``PUT``
537
541
request to
538
 
``http://glance.example.com/images/71c675ab-d94f-49cd-a114-e12490b328d9/members``
 
542
``http://glance.example.com/v1/images/71c675ab-d94f-49cd-a114-e12490b328d9/members``
539
543
with a body of the following form::
540
544
 
541
545
  {'memberships': [