apiclient Package

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

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()
class keystoneclient.openstack.common.apiclient.base.Resource(manager, info, loaded=False)

Bases: object

Base class for OpenStack resources (tenant, user, etc.).

This is pretty much just a bag for attributes.

HUMAN_ID = False
NAME_ATTR = 'name'
human_id

Human-readable ID which can be used for bash completion.

is_loaded
to_dict()
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.

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)
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.

param client:instance of BaseClient descendant
param method:method of HTTP request
param url:URL of HTTP request
param 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.

param method:method of HTTP request
param url:URL of HTTP request
param 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'

exceptions Module

Exception definitions.

exception keystoneclient.openstack.common.apiclient.exceptions.AmbiguousEndpoints(endpoints=None)

Bases: keystoneclient.openstack.common.apiclient.exceptions.EndpointException

Found more than one matching endpoint in Service Catalog.

exception keystoneclient.openstack.common.apiclient.exceptions.AuthPluginOptionsMissing(opt_names)

Bases: keystoneclient.openstack.common.apiclient.exceptions.AuthorizationFailure

Auth plugin misses some options.

exception keystoneclient.openstack.common.apiclient.exceptions.AuthSystemNotFound(auth_system)

Bases: keystoneclient.openstack.common.apiclient.exceptions.AuthorizationFailure

User has specified a AuthSystem that is not installed.

exception keystoneclient.openstack.common.apiclient.exceptions.AuthorizationFailure

Bases: keystoneclient.openstack.common.apiclient.exceptions.ClientException

Cannot authorize API client.

exception keystoneclient.openstack.common.apiclient.exceptions.BadGateway(message=None, details=None, response=None, request_id=None, url=None, method=None, http_status=None)

Bases: keystoneclient.openstack.common.apiclient.exceptions.HttpServerError

HTTP 502 - Bad Gateway.

The server was acting as a gateway or proxy and received an invalid response from the upstream server.

http_status = 502
message = 'Bad Gateway'
exception keystoneclient.openstack.common.apiclient.exceptions.BadRequest(message=None, details=None, response=None, request_id=None, url=None, method=None, http_status=None)

Bases: keystoneclient.openstack.common.apiclient.exceptions.HTTPClientError

HTTP 400 - Bad Request.

The request cannot be fulfilled due to bad syntax.

http_status = 400
message = 'Bad Request'
exception keystoneclient.openstack.common.apiclient.exceptions.ClientException

Bases: exceptions.Exception

The base exception class for all exceptions this library raises.

exception keystoneclient.openstack.common.apiclient.exceptions.CommandError

Bases: keystoneclient.openstack.common.apiclient.exceptions.ClientException

Error in CLI tool.

exception keystoneclient.openstack.common.apiclient.exceptions.Conflict(message=None, details=None, response=None, request_id=None, url=None, method=None, http_status=None)

Bases: keystoneclient.openstack.common.apiclient.exceptions.HTTPClientError

HTTP 409 - Conflict.

Indicates that the request could not be processed because of conflict in the request, such as an edit conflict.

http_status = 409
message = 'Conflict'
exception keystoneclient.openstack.common.apiclient.exceptions.ConnectionRefused

Bases: keystoneclient.openstack.common.apiclient.exceptions.ClientException

Cannot connect to API service.

exception keystoneclient.openstack.common.apiclient.exceptions.EndpointException

Bases: keystoneclient.openstack.common.apiclient.exceptions.ClientException

Something is rotten in Service Catalog.

exception keystoneclient.openstack.common.apiclient.exceptions.EndpointNotFound

Bases: keystoneclient.openstack.common.apiclient.exceptions.EndpointException

Could not find requested endpoint in Service Catalog.

exception keystoneclient.openstack.common.apiclient.exceptions.ExpectationFailed(message=None, details=None, response=None, request_id=None, url=None, method=None, http_status=None)

Bases: keystoneclient.openstack.common.apiclient.exceptions.HTTPClientError

HTTP 417 - Expectation Failed.

The server cannot meet the requirements of the Expect request-header field.

http_status = 417
message = 'Expectation Failed'
exception keystoneclient.openstack.common.apiclient.exceptions.Forbidden(message=None, details=None, response=None, request_id=None, url=None, method=None, http_status=None)

Bases: keystoneclient.openstack.common.apiclient.exceptions.HTTPClientError

HTTP 403 - Forbidden.

The request was a valid request, but the server is refusing to respond to it.

http_status = 403
message = 'Forbidden'
exception keystoneclient.openstack.common.apiclient.exceptions.GatewayTimeout(message=None, details=None, response=None, request_id=None, url=None, method=None, http_status=None)

Bases: keystoneclient.openstack.common.apiclient.exceptions.HttpServerError

HTTP 504 - Gateway Timeout.

The server was acting as a gateway or proxy and did not receive a timely response from the upstream server.

http_status = 504
message = 'Gateway Timeout'
exception keystoneclient.openstack.common.apiclient.exceptions.Gone(message=None, details=None, response=None, request_id=None, url=None, method=None, http_status=None)

Bases: keystoneclient.openstack.common.apiclient.exceptions.HTTPClientError

HTTP 410 - Gone.

Indicates that the resource requested is no longer available and will not be available again.

http_status = 410
message = 'Gone'
exception keystoneclient.openstack.common.apiclient.exceptions.HTTPClientError(message=None, details=None, response=None, request_id=None, url=None, method=None, http_status=None)

Bases: keystoneclient.openstack.common.apiclient.exceptions.HttpError

Client-side HTTP error.

Exception for cases in which the client seems to have erred.

message = 'HTTP Client Error'
exception keystoneclient.openstack.common.apiclient.exceptions.HTTPRedirection(message=None, details=None, response=None, request_id=None, url=None, method=None, http_status=None)

Bases: keystoneclient.openstack.common.apiclient.exceptions.HttpError

HTTP Redirection.

message = 'HTTP Redirection'
exception keystoneclient.openstack.common.apiclient.exceptions.HttpError(message=None, details=None, response=None, request_id=None, url=None, method=None, http_status=None)

Bases: keystoneclient.openstack.common.apiclient.exceptions.ClientException

The base exception class for all HTTP exceptions.

http_status = 0
message = 'HTTP Error'
exception keystoneclient.openstack.common.apiclient.exceptions.HttpNotImplemented(message=None, details=None, response=None, request_id=None, url=None, method=None, http_status=None)

Bases: keystoneclient.openstack.common.apiclient.exceptions.HttpServerError

HTTP 501 - Not Implemented.

The server either does not recognize the request method, or it lacks the ability to fulfill the request.

http_status = 501
message = 'Not Implemented'
exception keystoneclient.openstack.common.apiclient.exceptions.HttpServerError(message=None, details=None, response=None, request_id=None, url=None, method=None, http_status=None)

Bases: keystoneclient.openstack.common.apiclient.exceptions.HttpError

Server-side HTTP error.

Exception for cases in which the server is aware that it has erred or is incapable of performing the request.

message = 'HTTP Server Error'
exception keystoneclient.openstack.common.apiclient.exceptions.HttpVersionNotSupported(message=None, details=None, response=None, request_id=None, url=None, method=None, http_status=None)

Bases: keystoneclient.openstack.common.apiclient.exceptions.HttpServerError

HTTP 505 - HttpVersion Not Supported.

The server does not support the HTTP protocol version used in the request.

http_status = 505
message = 'HTTP Version Not Supported'
exception keystoneclient.openstack.common.apiclient.exceptions.InternalServerError(message=None, details=None, response=None, request_id=None, url=None, method=None, http_status=None)

Bases: keystoneclient.openstack.common.apiclient.exceptions.HttpServerError

HTTP 500 - Internal Server Error.

A generic error message, given when no more specific message is suitable.

http_status = 500
message = 'Internal Server Error'
exception keystoneclient.openstack.common.apiclient.exceptions.LengthRequired(message=None, details=None, response=None, request_id=None, url=None, method=None, http_status=None)

Bases: keystoneclient.openstack.common.apiclient.exceptions.HTTPClientError

HTTP 411 - Length Required.

The request did not specify the length of its content, which is required by the requested resource.

http_status = 411
message = 'Length Required'
exception keystoneclient.openstack.common.apiclient.exceptions.MethodNotAllowed(message=None, details=None, response=None, request_id=None, url=None, method=None, http_status=None)

Bases: keystoneclient.openstack.common.apiclient.exceptions.HTTPClientError

HTTP 405 - Method Not Allowed.

A request was made of a resource using a request method not supported by that resource.

http_status = 405
message = 'Method Not Allowed'
exception keystoneclient.openstack.common.apiclient.exceptions.MissingArgs(missing)

Bases: keystoneclient.openstack.common.apiclient.exceptions.ClientException

Supplied arguments are not sufficient for calling a function.

exception keystoneclient.openstack.common.apiclient.exceptions.MultipleChoices(message=None, details=None, response=None, request_id=None, url=None, method=None, http_status=None)

Bases: keystoneclient.openstack.common.apiclient.exceptions.HTTPRedirection

HTTP 300 - Multiple Choices.

Indicates multiple options for the resource that the client may follow.

http_status = 300
message = 'Multiple Choices'
exception keystoneclient.openstack.common.apiclient.exceptions.NoUniqueMatch

Bases: keystoneclient.openstack.common.apiclient.exceptions.ClientException

Multiple entities found instead of one.

exception keystoneclient.openstack.common.apiclient.exceptions.NotAcceptable(message=None, details=None, response=None, request_id=None, url=None, method=None, http_status=None)

Bases: keystoneclient.openstack.common.apiclient.exceptions.HTTPClientError

HTTP 406 - Not Acceptable.

The requested resource is only capable of generating content not acceptable according to the Accept headers sent in the request.

http_status = 406
message = 'Not Acceptable'
exception keystoneclient.openstack.common.apiclient.exceptions.NotFound(message=None, details=None, response=None, request_id=None, url=None, method=None, http_status=None)

Bases: keystoneclient.openstack.common.apiclient.exceptions.HTTPClientError

HTTP 404 - Not Found.

The requested resource could not be found but may be available again in the future.

http_status = 404
message = 'Not Found'
exception keystoneclient.openstack.common.apiclient.exceptions.PaymentRequired(message=None, details=None, response=None, request_id=None, url=None, method=None, http_status=None)

Bases: keystoneclient.openstack.common.apiclient.exceptions.HTTPClientError

HTTP 402 - Payment Required.

Reserved for future use.

http_status = 402
message = 'Payment Required'
exception keystoneclient.openstack.common.apiclient.exceptions.PreconditionFailed(message=None, details=None, response=None, request_id=None, url=None, method=None, http_status=None)

Bases: keystoneclient.openstack.common.apiclient.exceptions.HTTPClientError

HTTP 412 - Precondition Failed.

The server does not meet one of the preconditions that the requester put on the request.

http_status = 412
message = 'Precondition Failed'
exception keystoneclient.openstack.common.apiclient.exceptions.ProxyAuthenticationRequired(message=None, details=None, response=None, request_id=None, url=None, method=None, http_status=None)

Bases: keystoneclient.openstack.common.apiclient.exceptions.HTTPClientError

HTTP 407 - Proxy Authentication Required.

The client must first authenticate itself with the proxy.

http_status = 407
message = 'Proxy Authentication Required'
exception keystoneclient.openstack.common.apiclient.exceptions.RequestEntityTooLarge(*args, **kwargs)

Bases: keystoneclient.openstack.common.apiclient.exceptions.HTTPClientError

HTTP 413 - Request Entity Too Large.

The request is larger than the server is willing or able to process.

http_status = 413
message = 'Request Entity Too Large'
exception keystoneclient.openstack.common.apiclient.exceptions.RequestTimeout(message=None, details=None, response=None, request_id=None, url=None, method=None, http_status=None)

Bases: keystoneclient.openstack.common.apiclient.exceptions.HTTPClientError

HTTP 408 - Request Timeout.

The server timed out waiting for the request.

http_status = 408
message = 'Request Timeout'
exception keystoneclient.openstack.common.apiclient.exceptions.RequestUriTooLong(message=None, details=None, response=None, request_id=None, url=None, method=None, http_status=None)

Bases: keystoneclient.openstack.common.apiclient.exceptions.HTTPClientError

HTTP 414 - Request-URI Too Long.

The URI provided was too long for the server to process.

http_status = 414
message = 'Request-URI Too Long'
exception keystoneclient.openstack.common.apiclient.exceptions.RequestedRangeNotSatisfiable(message=None, details=None, response=None, request_id=None, url=None, method=None, http_status=None)

Bases: keystoneclient.openstack.common.apiclient.exceptions.HTTPClientError

HTTP 416 - Requested Range Not Satisfiable.

The client has asked for a portion of the file, but the server cannot supply that portion.

http_status = 416
message = 'Requested Range Not Satisfiable'
exception keystoneclient.openstack.common.apiclient.exceptions.ServiceUnavailable(message=None, details=None, response=None, request_id=None, url=None, method=None, http_status=None)

Bases: keystoneclient.openstack.common.apiclient.exceptions.HttpServerError

HTTP 503 - Service Unavailable.

The server is currently unavailable.

http_status = 503
message = 'Service Unavailable'
exception keystoneclient.openstack.common.apiclient.exceptions.Unauthorized(message=None, details=None, response=None, request_id=None, url=None, method=None, http_status=None)

Bases: keystoneclient.openstack.common.apiclient.exceptions.HTTPClientError

HTTP 401 - Unauthorized.

Similar to 403 Forbidden, but specifically for use when authentication is required and has failed or has not yet been provided.

http_status = 401
message = 'Unauthorized'
exception keystoneclient.openstack.common.apiclient.exceptions.UnprocessableEntity(message=None, details=None, response=None, request_id=None, url=None, method=None, http_status=None)

Bases: keystoneclient.openstack.common.apiclient.exceptions.HTTPClientError

HTTP 422 - Unprocessable Entity.

The request was well-formed but was unable to be followed due to semantic errors.

http_status = 422
message = 'Unprocessable Entity'
exception keystoneclient.openstack.common.apiclient.exceptions.UnsupportedMediaType(message=None, details=None, response=None, request_id=None, url=None, method=None, http_status=None)

Bases: keystoneclient.openstack.common.apiclient.exceptions.HTTPClientError

HTTP 415 - Unsupported Media Type.

The request entity has a media type which the server or resource does not support.

http_status = 415
message = 'Unsupported Media Type'
exception keystoneclient.openstack.common.apiclient.exceptions.UnsupportedVersion

Bases: keystoneclient.openstack.common.apiclient.exceptions.ClientException

User is trying to use an unsupported version of the API.

exception keystoneclient.openstack.common.apiclient.exceptions.ValidationError

Bases: keystoneclient.openstack.common.apiclient.exceptions.ClientException

Error in validation on API client side.

keystoneclient.openstack.common.apiclient.exceptions.from_response(response, method, url)

Returns an instance of HttpError or subclass based on response.

Parameters:
  • response – instance of requests.Response class
  • method – HTTP method used for request
  • url – URL used for request

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=[], optional=[])

Table Of Contents

Previous topic

common Package

Next topic

fixture Package

This Page