2014-10-10 19:30:37 -05:00
|
|
|
=======================
|
|
|
|
Using the V3 Client API
|
|
|
|
=======================
|
2013-12-20 13:24:03 +00:00
|
|
|
|
|
|
|
Introduction
|
|
|
|
============
|
|
|
|
|
|
|
|
The main concepts in the Identity v3 API are:
|
|
|
|
|
2014-10-10 19:42:06 -05:00
|
|
|
* :py:mod:`~keystoneclient.v3.credentials`
|
2015-03-24 17:57:25 +00:00
|
|
|
* :py:mod:`~keystoneclient.v3.domain_configs`
|
2014-10-10 19:42:06 -05:00
|
|
|
* :py:mod:`~keystoneclient.v3.domains`
|
|
|
|
* :py:mod:`~keystoneclient.v3.endpoints`
|
|
|
|
* :py:mod:`~keystoneclient.v3.groups`
|
|
|
|
* :py:mod:`~keystoneclient.v3.policies`
|
|
|
|
* :py:mod:`~keystoneclient.v3.projects`
|
|
|
|
* :py:mod:`~keystoneclient.v3.regions`
|
|
|
|
* :py:mod:`~keystoneclient.v3.role_assignments`
|
|
|
|
* :py:mod:`~keystoneclient.v3.roles`
|
|
|
|
* :py:mod:`~keystoneclient.v3.services`
|
|
|
|
* :py:mod:`~keystoneclient.v3.tokens`
|
|
|
|
* :py:mod:`~keystoneclient.v3.users`
|
2013-12-20 13:24:03 +00:00
|
|
|
|
2014-06-12 14:30:07 -05:00
|
|
|
The :py:mod:`keystoneclient.v3.client` API lets you query and make changes
|
2013-12-20 13:24:03 +00:00
|
|
|
through ``managers``. For example, to manipulate a project (formerly
|
|
|
|
called tenant), you interact with a
|
2014-06-12 14:30:07 -05:00
|
|
|
:py:class:`keystoneclient.v3.projects.ProjectManager` object.
|
2013-12-20 13:24:03 +00:00
|
|
|
|
|
|
|
You obtain access to managers through attributes of a
|
2014-06-12 14:30:07 -05:00
|
|
|
:py:class:`keystoneclient.v3.client.Client` object. For example, the
|
2013-12-20 13:24:03 +00:00
|
|
|
``projects`` attribute of a ``Client`` object is a projects manager::
|
|
|
|
|
|
|
|
>>> from keystoneclient.v3 import client
|
|
|
|
>>> keystone = client.Client(...)
|
|
|
|
>>> keystone.projects.list() # List projects
|
|
|
|
|
|
|
|
While it is possible to instantiate a
|
2014-06-12 14:30:07 -05:00
|
|
|
:py:class:`keystoneclient.v3.client.Client` object (as done above for
|
2013-12-20 13:24:03 +00:00
|
|
|
clarity), the recommended approach is to use the discovery mechanism
|
2014-06-12 14:30:07 -05:00
|
|
|
provided by the :py:class:`keystoneclient.client.Client` class. The
|
|
|
|
appropriate class will be instantiated depending on the API versions
|
|
|
|
available::
|
2013-12-20 13:24:03 +00:00
|
|
|
|
|
|
|
>>> from keystoneclient import client
|
|
|
|
>>> keystone =
|
|
|
|
... client.Client(auth_url='http://localhost:5000', ...)
|
|
|
|
>>> type(keystone)
|
|
|
|
<class 'keystoneclient.v3.client.Client'>
|
|
|
|
|
|
|
|
One can force the use of a specific version of the API, either by
|
|
|
|
using the ``version`` keyword argument::
|
|
|
|
|
|
|
|
>>> from keystoneclient import client
|
|
|
|
>>> keystone = client.Client(auth_url='http://localhost:5000',
|
|
|
|
version=(2,), ...)
|
|
|
|
>>> type(keystone)
|
|
|
|
<class 'keystoneclient.v2_0.client.Client'>
|
|
|
|
>>> keystone = client.Client(auth_url='http://localhost:5000',
|
|
|
|
version=(3,), ...)
|
|
|
|
>>> type(keystone)
|
|
|
|
<class 'keystoneclient.v3.client.Client'>
|
|
|
|
|
|
|
|
Or by specifying directly the specific API version authentication URL
|
|
|
|
as the auth_url keyword argument::
|
|
|
|
|
|
|
|
>>> from keystoneclient import client
|
|
|
|
>>> keystone =
|
|
|
|
... client.Client(auth_url='http://localhost:5000/v2.0', ...)
|
|
|
|
>>> type(keystone)
|
|
|
|
<class 'keystoneclient.v2_0.client.Client'>
|
|
|
|
>>> keystone =
|
|
|
|
... client.Client(auth_url='http://localhost:5000/v3', ...)
|
|
|
|
>>> type(keystone)
|
|
|
|
<class 'keystoneclient.v3.client.Client'>
|
|
|
|
|
2014-06-12 14:30:07 -05:00
|
|
|
Upon successful authentication, a :py:class:`keystoneclient.v3.client.Client`
|
2013-12-20 13:24:03 +00:00
|
|
|
object is returned (when using the Identity v3 API). Authentication and
|
|
|
|
examples of common tasks are provided below.
|
|
|
|
|
|
|
|
You can generally expect that when the client needs to propagate an
|
|
|
|
exception it will raise an instance of subclass of
|
2016-02-28 10:59:51 -06:00
|
|
|
:class:`keystoneclient.exceptions.ClientException`.
|
2013-12-20 13:24:03 +00:00
|
|
|
|
2014-10-11 09:55:23 -05:00
|
|
|
Authenticating Using Sessions
|
|
|
|
=============================
|
2013-12-20 13:24:03 +00:00
|
|
|
|
2014-10-11 09:55:23 -05:00
|
|
|
Instantiate a :py:class:`keystoneclient.v3.client.Client` using a
|
2016-02-28 10:44:44 -06:00
|
|
|
:py:class:`~keystoneauth1.session.Session` to provide the authentication
|
2014-10-11 09:55:23 -05:00
|
|
|
plugin, SSL/TLS certificates, and other data::
|
|
|
|
|
2016-02-28 10:44:44 -06:00
|
|
|
>>> from keystoneauth1.identity import v3
|
|
|
|
>>> from keystoneauth1 import session
|
2014-10-11 09:55:23 -05:00
|
|
|
>>> from keystoneclient.v3 import client
|
|
|
|
>>> auth = v3.Password(auth_url='https://my.keystone.com:5000/v3',
|
|
|
|
... user_id='myuserid',
|
|
|
|
... password='mypassword',
|
|
|
|
... project_id='myprojectid')
|
|
|
|
>>> sess = session.Session(auth=auth)
|
|
|
|
>>> keystone = client.Client(session=sess)
|
|
|
|
|
|
|
|
For more information on Sessions refer to: `Using Sessions`_.
|
|
|
|
|
|
|
|
.. _`Using Sessions`: using-sessions.html
|
|
|
|
|
2016-06-15 12:51:04 +00:00
|
|
|
Getting Metadata Responses
|
|
|
|
==========================
|
|
|
|
|
|
|
|
Instantiating :py:class:`keystoneclient.v3.client.Client` using
|
|
|
|
`include_metadata=True` will cause manager response to return
|
|
|
|
:py:class:`keystoneclient.base.Response` instead of just the data.
|
|
|
|
The metadata property will be available directly to the
|
|
|
|
:py:class:`keystoneclient.base.Response` and the response data will
|
|
|
|
be available as property `data` to it.
|
|
|
|
|
|
|
|
>>> from keystoneauth1.identity import v3
|
|
|
|
>>> from keystoneauth1 import session
|
|
|
|
>>> from keystoneclient.v3 import client
|
|
|
|
>>> auth = v3.Password(auth_url='https://my.keystone.com:5000/v3',
|
|
|
|
... user_id='myuserid',
|
|
|
|
... password='mypassword',
|
|
|
|
... project_id='myprojectid')
|
|
|
|
>>> sess = session.Session(auth=auth)
|
|
|
|
>>> keystone = client.Client(session=sess, include_metadata=True)
|
|
|
|
>>> resp = keystone.projects.list()
|
|
|
|
>>> resp.request_ids[0]
|
|
|
|
req-1234-5678-...
|
|
|
|
>>> resp.data
|
|
|
|
[<Project ...>, <Project ...>, ...]
|
|
|
|
|
2014-10-11 09:55:23 -05:00
|
|
|
Non-Session Authentication (deprecated)
|
|
|
|
=======================================
|
|
|
|
|
|
|
|
The *deprecated* way to authenticate is to pass the username, the user's domain
|
|
|
|
name (which will default to 'Default' if it is not specified), and a
|
2013-12-20 13:24:03 +00:00
|
|
|
password::
|
|
|
|
|
|
|
|
>>> from keystoneclient import client
|
|
|
|
>>> auth_url = 'http://localhost:5000'
|
|
|
|
>>> username = 'adminUser'
|
|
|
|
>>> user_domain_name = 'Default'
|
|
|
|
>>> password = 'secreetword'
|
|
|
|
>>> keystone = client.Client(auth_url=auth_url, version=(3,),
|
|
|
|
... username=username, password=password,
|
|
|
|
... user_domain_name=user_domain_name)
|
|
|
|
|
2016-02-28 10:44:44 -06:00
|
|
|
A :py:class:`~keystoneauth1.session.Session` should be passed to the Client
|
2014-10-11 09:55:23 -05:00
|
|
|
instead. Using a Session you're not limited to authentication using a username
|
|
|
|
and password but can take advantage of other more secure authentication
|
|
|
|
methods.
|
|
|
|
|
2013-12-20 13:24:03 +00:00
|
|
|
You may optionally specify a domain or project (along with its project
|
|
|
|
domain name), to obtain a scoped token::
|
|
|
|
|
|
|
|
>>> from keystoneclient import client
|
|
|
|
>>> auth_url = 'http://localhost:5000'
|
|
|
|
>>> username = 'adminUser'
|
|
|
|
>>> user_domain_name = 'Default'
|
|
|
|
>>> project_name = 'demo'
|
|
|
|
>>> project_domain_name = 'Default'
|
|
|
|
>>> password = 'secreetword'
|
|
|
|
>>> keystone = client.Client(auth_url=auth_url, version=(3,),
|
|
|
|
... username=username, password=password,
|
|
|
|
... user_domain_name=user_domain_name,
|
|
|
|
... project_name=project_name,
|
|
|
|
... project_domain_name=project_domain_name)
|