keystoneclient.openstack.common.apiclient package

Submodules

keystoneclient.openstack.common.apiclient.auth module

class keystoneclient.openstack.common.apiclient.auth.BaseAuthPlugin(auth_system=None, **kwargs)

Bases: object

Base class for authentication plugins.

An authentication plugin needs to override at least the authenticate method to be a valid plugin.

classmethod add_common_opts(parser)

Add options that are common for several plugins.

classmethod add_opts(parser)

Populate the parser with the options for this plugin.

auth_system = None
authenticate(http_client)

Authenticate using plugin defined method.

The method usually analyses self.opts and performs a request to authentication server.

Parameters:http_client (HTTPClient) – client object that needs authentication
Raises:AuthorizationFailure
common_opt_names = ['auth_system', 'username', 'password', 'tenant_name', 'token', 'auth_url']
static get_opt(opt_name, args)

Return option name and value.

Parameters:
  • opt_name – name of the option, e.g., “username”
  • args – parsed arguments
opt_names = []
parse_opts(args)

Parse the actual auth-system options if any.

This method is expected to populate the attribute self.opts with a dict containing the options and values needed to make authentication.

sufficient_options()

Check if all required options are present.

Raises:AuthPluginOptionsMissing
token_and_endpoint(endpoint_type, service_type)

Return token and endpoint.

Parameters:
  • service_type (string) – Service type of the endpoint
  • endpoint_type (string) – Type of endpoint. Possible values: public or publicURL, internal or internalURL, admin or adminURL
Returns:

tuple of token and endpoint strings

Raises:

EndpointException

keystoneclient.openstack.common.apiclient.auth.discover_auth_systems()

Discover the available auth-systems.

This won’t take into account the old style auth-systems.

keystoneclient.openstack.common.apiclient.auth.load_auth_system_opts(parser)

Load options needed by the available auth-systems into a parser.

This function will try to populate the parser with options from the available plugins.

keystoneclient.openstack.common.apiclient.auth.load_plugin(auth_system)
keystoneclient.openstack.common.apiclient.auth.load_plugin_from_args(args)

Load required plugin and populate it with options.

Try to guess auth system if it is not specified. Systems are tried in alphabetical order.

Raises:AuthPluginOptionsMissing

keystoneclient.openstack.common.apiclient.base module

Base utilities to build API operation managers and objects on top of.

class keystoneclient.openstack.common.apiclient.base.BaseManager(client)

Bases: keystoneclient.openstack.common.apiclient.base.HookableMixin

Basic manager type providing common operations.

Managers interact with a particular type of API (servers, flavors, images, etc.) and provide CRUD operations for them.

resource_class = None
class keystoneclient.openstack.common.apiclient.base.CrudManager(client)

Bases: keystoneclient.openstack.common.apiclient.base.BaseManager

Base manager class for manipulating entities.

Children of this class are expected to define a collection_key and key.

  • collection_key: Usually a plural noun by convention (e.g. entities); used to refer collections in both URL’s (e.g. /v3/entities) and JSON objects containing a list of member resources (e.g. {‘entities’: [{}, {}, {}]}).
  • key: Usually a singular noun by convention (e.g. entity); used to refer to an individual member of the collection.
build_url(base_url=None, **kwargs)

Builds a resource URL for the given kwargs.

Given an example collection where collection_key = ‘entities’ and key = ‘entity’, the following URL’s could be generated.

By default, the URL will represent a collection of entities, e.g.:

/entities

If kwargs contains an entity_id, then the URL will represent a specific member, e.g.:

/entities/{entity_id}
Parameters:base_url – if provided, the generated URL will be appended to it
collection_key = None
create(**kwargs)
delete(**kwargs)
find(base_url=None, **kwargs)

Find a single item with attributes matching **kwargs.

Parameters:base_url – if provided, the generated URL will be appended to it
get(**kwargs)
head(**kwargs)
key = None
list(base_url=None, **kwargs)

List the collection.

Parameters:base_url – if provided, the generated URL will be appended to it
put(base_url=None, **kwargs)

Update an element.

Parameters:base_url – if provided, the generated URL will be appended to it
update(**kwargs)
class keystoneclient.openstack.common.apiclient.base.Extension(name, module)

Bases: keystoneclient.openstack.common.apiclient.base.HookableMixin

Extension descriptor.

SUPPORTED_HOOKS = ('__pre_parse_args__', '__post_parse_args__')
manager_class = None
class keystoneclient.openstack.common.apiclient.base.HookableMixin

Bases: object

Mixin so classes can register and run hooks.

classmethod add_hook(hook_type, hook_func)

Add a new hook of specified type.

Parameters:
  • cls – class that registers hooks
  • hook_type – hook type, e.g., ‘__pre_parse_args__’
  • hook_func – hook function
classmethod run_hooks(hook_type, *args, **kwargs)

Run all hooks of specified type.

Parameters:
  • cls – class that registers hooks
  • hook_type – hook type, e.g., ‘__pre_parse_args__’
  • args – args to be passed to every hook function
  • kwargs – kwargs to be passed to every hook function
class keystoneclient.openstack.common.apiclient.base.ManagerWithFind(client)

Bases: keystoneclient.openstack.common.apiclient.base.BaseManager

Manager with additional find()/findall() methods.

find(**kwargs)

Find a single item with attributes matching **kwargs.

This isn’t very efficient: it loads the entire list then filters on the Python side.

findall(**kwargs)

Find all items with attributes matching **kwargs.

This isn’t very efficient: it loads the entire list then filters on the Python side.

list()
keystoneclient.openstack.common.apiclient.base.getid(obj)

Return id if argument is a Resource.

Abstracts the common pattern of allowing both an object or an object’s ID (UUID) as a parameter when dealing with relationships.

keystoneclient.openstack.common.apiclient.client module

OpenStack Client interface. Handles the REST calls and responses.

class keystoneclient.openstack.common.apiclient.client.BaseClient(http_client, extensions=None)

Bases: object

Top-level object to access the OpenStack API.

This client uses HTTPClient to send requests. HTTPClient will handle a bunch of issues such as authentication.

cached_endpoint = None
client_request(method, url, **kwargs)
delete(url, **kwargs)
endpoint_type = None
get(url, **kwargs)
static get_class(api_name, version, version_map)

Returns the client class for the requested API version

Parameters:
  • api_name – the name of the API, e.g. ‘compute’, ‘image’, etc
  • version – the requested API version
  • version_map – a dict of client classes keyed by version
Return type:

a client class for the requested API version

head(url, **kwargs)
last_request_id
patch(url, **kwargs)
post(url, **kwargs)
put(url, **kwargs)
service_type = None
class keystoneclient.openstack.common.apiclient.client.HTTPClient(auth_plugin, region_name=None, endpoint_type='publicURL', original_ip=None, verify=True, cert=None, timeout=None, timings=False, keyring_saver=None, debug=False, user_agent=None, http=None)

Bases: object

This client handles sending HTTP requests to OpenStack servers.

Features:

  • share authentication information between several clients to different services (e.g., for compute and image clients);
  • reissue authentication request for expired tokens;
  • encode/decode JSON bodies;
  • raise exceptions on HTTP errors;
  • pluggable authentication;
  • store authentication information in a keyring;
  • store time spent for requests;
  • register clients for particular services, so one can use http_client.identity or http_client.compute;
  • log requests and responses in a format that is easy to copy-and-paste into terminal and send the same request with curl.
add_client(base_client_instance)

Add a new instance of BaseClient descendant.

self will store a reference to base_client_instance.

Example:

>>> def test_clients():
...     from keystoneclient.auth import keystone
...     from openstack.common.apiclient import client
...     auth = keystone.KeystoneAuthPlugin(
...         username="user", password="pass", tenant_name="tenant",
...         auth_url="http://auth:5000/v2.0")
...     openstack_client = client.HTTPClient(auth)
...     # create nova client
...     from novaclient.v1_1 import client
...     client.Client(openstack_client)
...     # create keystone client
...     from keystoneclient.v2_0 import client
...     client.Client(openstack_client)
...     # use them
...     openstack_client.identity.tenants.list()
...     openstack_client.compute.servers.list()
authenticate()
client_request(client, method, url, **kwargs)

Send an http request using client‘s endpoint and specified url.

If request was rejected as unauthorized (possibly because the token is expired), issue one authorization attempt and send the request once again.

Parameters:
  • client – instance of BaseClient descendant
  • method – method of HTTP request
  • url – URL of HTTP request
  • kwargs – any other parameter that can be passed to HTTPClient.request
static concat_url(endpoint, url)

Concatenate endpoint and final URL.

E.g., “http://keystone/v2.0/” and “/tokens” are concatenated to “http://keystone/v2.0/tokens”.

Parameters:
  • endpoint – the base URL
  • url – the final URL
get_timings()
request(method, url, **kwargs)

Send an http request with the specified characteristics.

Wrapper around requests.Session.request to handle tasks such as setting headers, JSON encoding/decoding, and error handling.

Parameters:
  • method – method of HTTP request
  • url – URL of HTTP request
  • kwargs – any other parameter that can be passed to requests.Session.request (such as headers) or json that will be encoded as JSON and used as data argument
reset_timings()
serialize(kwargs)
user_agent = 'keystoneclient.openstack.common.apiclient'

keystoneclient.openstack.common.apiclient.exceptions module

Exception definitions.

keystoneclient.openstack.common.apiclient.fake_client module

A fake server that “responds” to API methods with pre-canned responses.

All of these responses come from the spec, so if for some reason the spec’s wrong the tests might raise AssertionError. I’ve indicated in comments the places where actual behavior differs from the spec.

class keystoneclient.openstack.common.apiclient.fake_client.FakeHTTPClient(*args, **kwargs)

Bases: keystoneclient.openstack.common.apiclient.client.HTTPClient

assert_called(method, url, body=None, pos=-1)

Assert than an API method was just called.

assert_called_anytime(method, url, body=None)

Assert than an API method was called anytime in the test.

authenticate()
clear_callstack()
client_request(client, method, url, **kwargs)
class keystoneclient.openstack.common.apiclient.fake_client.TestResponse(data)

Bases: requests.models.Response

Wrap requests.Response and provide a convenient initialization.

keystoneclient.openstack.common.apiclient.fake_client.assert_has_keys(dct, required=None, optional=None)

keystoneclient.openstack.common.apiclient.utils module

keystoneclient.openstack.common.apiclient.utils.find_resource(manager, name_or_id, **find_args)

Look for resource in a given manager.

Used as a helper for the _find_* methods. Example:

def _find_hypervisor(cs, hypervisor):
    #Get a hypervisor by name or ID.
    return cliutils.find_resource(cs.hypervisors, hypervisor)

Module contents