keystoneauth1.session module

class keystoneauth1.session.NoOpSemaphore

Bases: object

Empty context manager for use as a default semaphore.

class keystoneauth1.session.RequestTiming(method, url, elapsed)

Bases: object

Contains timing information for an HTTP interaction.

elapsed = None

Elapsed time information

method = None

HTTP method used for the call (GET, POST, etc)

url = None

URL against which the call was made

class keystoneauth1.session.Session(auth=None, session=None, original_ip=None, verify=True, cert=None, timeout=None, user_agent=None, redirect=30, additional_headers=None, app_name=None, app_version=None, additional_user_agent=None, discovery_cache=None, split_loggers=None, collect_timing=False, rate_semaphore=None, connect_retries=0)

Bases: object

Maintains client communication state and common functionality.

As much as possible the parameters to this class reflect and are passed directly to the requests library.

Parameters
  • auth (keystoneauth1.plugin.BaseAuthPlugin) – An authentication plugin to authenticate the session with. (optional, defaults to None)

  • session (requests.Session) – A requests session object that can be used for issuing requests. (optional)

  • original_ip (str) – The original IP of the requesting user which will be sent to identity service in a ‘Forwarded’ header. (optional)

  • verify – The verification arguments to pass to requests. These are of the same form as requests expects, so True or False to verify (or not) against system certificates or a path to a bundle or CA certs to check against or None for requests to attempt to locate and use certificates. (optional, defaults to True)

  • cert – A client certificate to pass to requests. These are of the same form as requests expects. Either a single filename containing both the certificate and key or a tuple containing the path to the certificate then a path to the key. (optional)

  • timeout (float) – A timeout to pass to requests. This should be a numerical value indicating some amount (or fraction) of seconds or 0 for no timeout. (optional, defaults to 0)

  • user_agent (str) – A User-Agent header string to use for the request. If not provided, a default of DEFAULT_USER_AGENT is used, which contains the keystoneauth1 version as well as those of the requests library and which Python is being used. When a non-None value is passed, it will be prepended to the default.

  • redirect (int/bool) – Controls the maximum number of redirections that can be followed by a request. Either an integer for a specific count or True/False for forever/never. (optional, default to 30)

  • additional_headers (dict) – Additional headers that should be attached to every request passing through the session. Headers of the same name specified per request will take priority.

  • app_name (str) – The name of the application that is creating the session. This will be used to create the user_agent.

  • app_version (str) – The version of the application creating the session. This will be used to create the user_agent.

  • additional_user_agent (list) – A list of tuple of name, version that will be added to the user agent. This can be used by libraries that are part of the communication process.

  • discovery_cache (dict) – A dict to be used for caching of discovery information. This is normally managed transparently, but if the user wants to share a single cache across multiple sessions that do not share an auth plugin, it can be provided here. (optional, defaults to None which means automatically manage)

  • split_loggers (bool) – Split the logging of requests across multiple loggers instead of just one. Defaults to False.

  • collect_timing (bool) – Whether or not to collect per-method timing information for each API call. (optional, defaults to False)

  • rate_semaphore – Semaphore to be used to control concurrency and rate limiting of requests. (optional, defaults to no concurrency or rate control)

  • connect_retries (int) – the maximum number of retries that should be attempted for connection errors. (optional, defaults to 0 - never retry).

property adapters
delete(url, **kwargs)

Perform a DELETE request.

This calls request() with method set to DELETE.

get(url, **kwargs)

Perform a GET request.

This calls request() with method set to GET.

get_all_version_data(auth=None, interface='public', region_name=None, service_type=None, **kwargs)

Get version data for all services in the catalog.

Parameters
  • auth (keystoneauth1.plugin.BaseAuthPlugin) – The auth plugin to use for token. Overrides the plugin on the session. (optional)

  • interface – Type of endpoint to get version data for. Can be a single value or a list of values. A value of None indicates that all interfaces should be queried. (optional, defaults to public)

  • region_name (string) – Region of endpoints to get version data for. A valueof None indicates that all regions should be queried. (optional, defaults to None)

  • service_type (string) – Limit the version data to a single service. (optional, defaults to None)

Returns

A dictionary keyed by region_name with values containing dictionaries keyed by interface with values being a list of ~keystoneauth1.discover.VersionData.

get_api_major_version(auth=None, **kwargs)

Get the major API version as provided by the auth plugin.

Parameters

auth (keystoneauth1.plugin.BaseAuthPlugin) – The auth plugin to use for token. Overrides the plugin on the session. (optional)

Raises

keystoneauth1.exceptions.auth_plugins.MissingAuthPlugin – if a plugin is not available.

Returns

The major version of the API of the service discovered.

Return type

tuple or None

get_auth_connection_params(auth=None, **kwargs)

Return auth connection params as provided by the auth plugin.

An auth plugin may specify connection parameters to the request like providing a client certificate for communication.

We restrict the values that may be returned from this function to prevent an auth plugin overriding values unrelated to connection parmeters. The values that are currently accepted are:

  • cert: a path to a client certificate, or tuple of client certificate and key pair that are used with this request.

  • verify: a boolean value to indicate verifying SSL certificates against the system CAs or a path to a CA file to verify with.

These values are passed to the requests library and further information on accepted values may be found there.

Parameters

auth (keystoneauth1.plugin.BaseAuthPlugin) – The auth plugin to use for tokens. Overrides the plugin on the session. (optional)

Raises
Returns

Authentication headers or None for failure.

Return type

dict

get_auth_headers(auth=None, **kwargs)

Return auth headers as provided by the auth plugin.

Parameters

auth (keystoneauth1.plugin.BaseAuthPlugin) – The auth plugin to use for token. Overrides the plugin on the session. (optional)

Raises
Returns

Authentication headers or None for failure.

Return type

dict

get_endpoint(auth=None, **kwargs)

Get an endpoint as provided by the auth plugin.

Parameters

auth (keystoneauth1.plugin.BaseAuthPlugin) – The auth plugin to use for token. Overrides the plugin on the session. (optional)

Raises

keystoneauth1.exceptions.auth_plugins.MissingAuthPlugin – if a plugin is not available.

Returns

An endpoint if available or None.

Return type

string

get_endpoint_data(auth=None, **kwargs)

Get endpoint data as provided by the auth plugin.

Parameters

auth (keystoneauth1.plugin.BaseAuthPlugin) – The auth plugin to use for token. Overrides the plugin on the session. (optional)

Raises
Returns

Endpoint data if available or None.

Return type

keystoneauth1.discover.EndpointData

get_project_id(auth=None)

Return the authenticated project_id as provided by the auth plugin.

Parameters

auth (keystoneauth1.plugin.BaseAuthPlugin) – The auth plugin to use for token. Overrides the plugin on the session. (optional)

Raises
Returns

Current project_id or None if not supported by plugin.

Return type

str

get_timings()

Return collected API timing information.

Returns

List of RequestTiming objects.

get_token(auth=None)

Return a token as provided by the auth plugin.

Parameters

auth (keystoneauth1.plugin.BaseAuthPlugin) – The auth plugin to use for token. Overrides the plugin on the session. (optional)

Raises

Warning

DEPRECATED: This assumes that the only header that is used to authenticate a message is X-Auth-Token. This may not be correct. Use get_auth_headers() instead.

Returns

A valid token.

Return type

string

get_user_id(auth=None)

Return the authenticated user_id as provided by the auth plugin.

Parameters

auth (keystoneauth1.plugin.BaseAuthPlugin) – The auth plugin to use for token. Overrides the plugin on the session. (optional)

Raises
Returns

Current user_id or None if not supported by plugin.

Return type

str

head(url, **kwargs)

Perform a HEAD request.

This calls request() with method set to HEAD.

invalidate(auth=None)

Invalidate an authentication plugin.

Parameters

auth (keystoneauth1.plugin.BaseAuthPlugin) – The auth plugin to invalidate. Overrides the plugin on the session. (optional)

mount(scheme, adapter)
patch(url, **kwargs)

Perform a PATCH request.

This calls request() with method set to PATCH.

post(url, **kwargs)

Perform a POST request.

This calls request() with method set to POST.

put(url, **kwargs)

Perform a PUT request.

This calls request() with method set to PUT.

request(url, method, json=None, original_ip=None, user_agent=None, redirect=None, authenticated=None, endpoint_filter=None, auth=None, requests_auth=None, raise_exc=True, allow_reauth=True, log=True, endpoint_override=None, connect_retries=None, logger=None, allow=None, client_name=None, client_version=None, microversion=None, microversion_service_type=None, status_code_retries=0, retriable_status_codes=None, rate_semaphore=None, global_request_id=None, connect_retry_delay=None, status_code_retry_delay=None, **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.

Arguments that are not handled are passed through to the requests library.

Parameters
  • url (str) – Path or fully qualified URL of HTTP request. If only a path is provided then endpoint_filter must also be provided such that the base URL can be determined. If a fully qualified URL is provided then endpoint_filter will be ignored.

  • method (str) – The http method to use. (e.g. ‘GET’, ‘POST’)

  • original_ip (str) – Mark this request as forwarded for this ip. (optional)

  • headers (dict) – Headers to be included in the request. (optional)

  • json – Some data to be represented as JSON. (optional)

  • user_agent (str) – A user_agent to use for the request. If present will override one present in headers. (optional)

  • redirect (int/bool) – the maximum number of redirections that can be followed by a request. Either an integer for a specific count or True/False for forever/never. (optional)

  • connect_retries (int) – the maximum number of retries that should be attempted for connection errors. (optional, defaults to None - never retry).

  • authenticated (bool) – True if a token should be attached to this request, False if not or None for attach if an auth_plugin is available. (optional, defaults to None)

  • endpoint_filter (dict) – Data to be provided to an auth plugin with which it should be able to determine an endpoint to use for this request. If not provided then URL is expected to be a fully qualified URL. (optional)

  • endpoint_override (str) – The URL to use instead of looking up the endpoint in the auth plugin. This will be ignored if a fully qualified URL is provided but take priority over an endpoint_filter. This string may contain the values %(project_id)s and %(user_id)s to have those values replaced by the project_id/user_id of the current authentication. (optional)

  • auth (keystoneauth1.plugin.BaseAuthPlugin) – The auth plugin to use when authenticating this request. This will override the plugin that is attached to the session (if any). (optional)

  • requests_auth (requests.auth.AuthBase) – A requests library auth plugin that cannot be passed via kwarg because the auth kwarg collides with our own auth plugins. (optional)

  • raise_exc (bool) – If True then raise an appropriate exception for failed HTTP requests. If False then return the request object. (optional, default True)

  • allow_reauth (bool) – Allow fetching a new token and retrying the request on receiving a 401 Unauthorized response. (optional, default True)

  • log (bool) – If True then log the request and response data to the debug log. (optional, default True)

  • logger (logging.Logger) – The logger object to use to log request and responses. If not provided the keystoneauth1.session default logger will be used.

  • allow (dict) – Extra filters to pass when discovering API versions. (optional)

  • microversion – Microversion to send for this request. microversion can be given as a string or a tuple. (optional)

  • microversion_service_type (str) – The service_type to be sent in the microversion header, if a microversion is given. Defaults to the value of service_type from endpoint_filter if one exists. If endpoint_filter is not provided or does not have a service_type, microversion is given and microversion_service_type is not provided, an exception will be raised.

  • status_code_retries (int) – the maximum number of retries that should be attempted for retriable HTTP status codes (optional, defaults to 0 - never retry).

  • retriable_status_codes (list) – list of HTTP status codes that should be retried (optional, defaults to HTTP 503, has no effect when status_code_retries is 0).

  • rate_semaphore – Semaphore to be used to control concurrency and rate limiting of requests. (optional, defaults to no concurrency or rate control)

  • global_request_id – Value for the X-Openstack-Request-Id header.

  • connect_retry_delay (float) – Delay (in seconds) between two connect retries (if enabled). By default exponential retry starting with 0.5 seconds up to a maximum of 60 seconds is used.

  • status_code_retry_delay (float) – Delay (in seconds) between two status code retries (if enabled). By default exponential retry starting with 0.5 seconds up to a maximum of 60 seconds is used.

  • kwargs

    any other parameter that can be passed to requests.Session.request() (such as headers). Except:

    • data will be overwritten by the data in the json param.

    • allow_redirects is ignored as redirects are handled by the session.

Raises

keystoneauth1.exceptions.base.ClientException – For connection failure, or to indicate an error response code.

Returns

The response to the request.

reset_timings()

Clear API timing information.

user_agent = None
class keystoneauth1.session.TCPKeepAliveAdapter(pool_connections=10, pool_maxsize=10, max_retries=0, pool_block=False)

Bases: requests.adapters.HTTPAdapter

The custom adapter used to set TCP Keep-Alive on all connections.

This Adapter also preserves the default behaviour of Requests which disables Nagle’s Algorithm. See also: https://blogs.msdn.com/b/windowsazurestorage/archive/2010/06/25/nagle-s-algorithm-is-not-friendly-towards-small-requests.aspx

init_poolmanager(*args, **kwargs)

Initializes a urllib3 PoolManager.

This method should not be called from user code, and is only exposed for use when subclassing the HTTPAdapter.

Parameters
  • connections – The number of urllib3 connection pools to cache.

  • maxsize – The maximum number of connections to save in the pool.

  • block – Block when no free connections are available.

  • pool_kwargs – Extra keyword arguments used to initialize the Pool Manager.