summaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2015-02-05 22:44:16 +0000
committerGerrit Code Review <review@openstack.org>2015-02-05 22:44:16 +0000
commitffcb324efc3d85d743a83a6a3ad6ebd9dc457627 (patch)
tree28ef767fa9aa44d2691bf8b3db8914d90fc30847 /doc
parentce5e1f0d48e3a849e63f17dfd038a229413ddb0a (diff)
parent35c9b6520222e05bff35d341bb7057faace99458 (diff)
downloadpython-glanceclient-ffcb324efc3d85d743a83a6a3ad6ebd9dc457627.tar.gz
Merge "Adds basic examples of v2 API usage"
Diffstat (limited to 'doc')
-rw-r--r--doc/source/apiv2.rst77
-rw-r--r--doc/source/index.rst1
2 files changed, 78 insertions, 0 deletions
diff --git a/doc/source/apiv2.rst b/doc/source/apiv2.rst
new file mode 100644
index 0000000..ef6fb71
--- /dev/null
+++ b/doc/source/apiv2.rst
@@ -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)
+
diff --git a/doc/source/index.rst b/doc/source/index.rst
index 06f4e0b..d2a16e5 100644
--- a/doc/source/index.rst
+++ b/doc/source/index.rst
@@ -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
=================