Merge "Adds basic examples of v2 API usage"

This commit is contained in:
Jenkins 2015-02-05 22:44:16 +00:00 committed by Gerrit Code Review
commit ffcb324efc
2 changed files with 78 additions and 0 deletions

77
doc/source/apiv2.rst Normal file
View File

@ -0,0 +1,77 @@
Python API v2
=============
To create a client::
from keystoneclient.auth.identity import v2 as identity
from keystoneclient import session
from glanceclient import Client
auth = identity.Password(auth_url=AUTH_URL,
username=USERNAME,
password=PASSWORD,
tenant_name=PROJECT_ID)
sess = session.Session(auth=auth)
token = auth.get_token(sess)
glance = Client('2', endpoint=OS_IMAGE_ENDPOINT, token=token)
Create
------
Create a new image::
image = glance.images.create(name="myNewImage")
glance.images.upload(image.id, open('/tmp/myimage.iso', 'rb'))
Show
----
Describe a specific image::
glance.images.get(image.id)
Update
------
Update a specific image::
# update with a list of image attribute names and their new values
glance.images.update(image.id, name="myNewImageName")
Delete
------
Delete specified image(s)::
glance.images.delete(image.id)
List
----
List images you can access::
for image in glance.images.list():
print image
Download
--------
Download a specific image::
d = glance.images.data(image.id)
Share an Image
--------------
Share a specific image with a tenant::
glance.image_members.create(image_id, member_id)
Remove a Share
--------------
Remove a shared image from a tenant::
glance.image_members.delete(image_id, member_id)
List Sharings
-------------
Describe sharing permissions by image or tenant::
glance.image_members.list(image_id)

View File

@ -15,6 +15,7 @@ In order to use the python api directly, you must first obtain an auth token and
f.write(chunk)
>>> image.delete()
For an API v2 example see also :doc:`apiv2`.
Command-line Tool
=================