libcloud.common.openstack module

Common utilities for OpenStack

class libcloud.common.openstack.OpenStackBaseConnection(user_id, key, secure=True, host=None, port=None, timeout=None, proxy_url=None, ex_force_base_url=None, ex_force_auth_url=None, ex_force_auth_version=None, ex_force_auth_token=None, ex_token_scope='project', ex_domain_name='Default', ex_tenant_name=None, ex_tenant_domain_id='default', ex_force_service_type=None, ex_force_service_name=None, ex_force_service_region=None, ex_force_microversion=None, ex_auth_cache=None, retry_delay=None, backoff=None)[source]

Bases: ConnectionUserAndKey

Base class for OpenStack connections.

Parameters:
  • user_id (str) – User name to use when authenticating

  • key (str) – Secret to use when authenticating.

  • secure (bool) – Use HTTPS? (True by default.)

  • ex_force_base_url (str) – Base URL for connection requests. If not specified, this will be determined by authenticating.

  • ex_force_auth_url (str) – Base URL for authentication requests.

  • ex_force_auth_version (str) – Authentication version to use. If not specified, defaults to AUTH_API_VERSION.

  • ex_force_auth_token (str) – Authentication token to use for connection requests. If specified, the connection will not attempt to authenticate, and the value of ex_force_base_url will be used to determine the base request URL. If ex_force_auth_token is passed in, ex_force_base_url must also be provided.

  • token_scope (str) – Whether to scope a token to a “project”, a “domain” or “unscoped”.

  • ex_domain_name (str) – When authenticating, provide this domain name to the identity service. A scoped token will be returned. Some cloud providers require the domain name to be provided at authentication time. Others will use a default domain if none is provided.

  • ex_tenant_name (str) – When authenticating, provide this tenant name to the identity service. A scoped token will be returned. Some cloud providers require the tenant name to be provided at authentication time. Others will use a default tenant if none is provided.

  • ex_tenant_domain_id (str) – When authenticating, provide this tenant domain id to the identity service. A scoped token will be returned. Some cloud providers require the tenant domain id to be provided at authentication time. Others will use a default tenant domain id if none is provided.

  • ex_force_service_type (str) – Service type to use when selecting an service. If not specified, a provider specific default will be used.

  • ex_force_service_name (str) – Service name to use when selecting an service. If not specified, a provider specific default will be used.

  • ex_force_service_region (str) – Region to use when selecting an service. If not specified, a provider specific default will be used.

  • ex_auth_cache (OpenStackAuthenticationCache) – External cache where authentication tokens are stored for reuse by other processes. Tokens are always cached in memory on the driver instance. To share tokens among multiple drivers, processes, or systems, pass a cache here.

Initialize user_id and key; set secure to an int based on passed value.

accept_format = None
add_default_headers(headers)[source]

Adds default headers (such as Authorization, X-Foo-Bar) to the passed headers

Should return a dictionary.

auth_token: str = None
auth_token_expires = None
auth_url: str = None
auth_user_info = None
get_auth_class()[source]

Retrieve identity / authentication class instance.

Return type:

OpenStackIdentityConnection

get_endpoint()[source]

Selects the endpoint to use based on provider specific values, or overrides passed in by the user when setting up the driver.

Returns:

url of the relevant endpoint for the driver

get_service_catalog()[source]
get_service_name()[source]

Gets the service name used to look up the endpoint in the service catalog.

Returns:

name of the service in the catalog

morph_action_hook(action)[source]

Here we strip any duplicated leading or trailing slashes to prevent typos and other issues where some APIs don’t correctly handle double slashes.

Keep in mind that in some situations, “/” is a valid path name so we have a module flag which disables this behavior (https://github.com/apache/libcloud/issues/1529).

request(action, params=None, data='', headers=None, method='GET', raw=False)[source]

Request a given action.

Basically a wrapper around the connection object’s request that does some helpful pre-processing.

Parameters:
  • action (str) – A path. This can include arguments. If included, any extra parameters are appended to the existing ones.

  • params (dict) – Optional mapping of additional parameters to send. If None, leave as an empty dict.

  • data (unicode) – A body of data to send with the request.

  • headers (dict) – Extra headers to add to the request None, leave as an empty dict.

  • method (str) – An HTTP method such as “GET” or “POST”.

  • raw (bool) – True to perform a “raw” request aka only send the headers and use the rawResponseCls class. This is used with storage API when uploading a file.

  • stream (bool) – True to return an iterator in Response.iter_content and allow streaming of the response data (for downloading large files)

  • retry_failed – True if failed requests should be retried. This argument can override module level constant and environment variable value on per-request basis.

Returns:

An Response instance.

Return type:

Response instance

service_catalog = None
service_name = None
service_region = None
service_type = None
class libcloud.common.openstack.OpenStackDriverMixin(ex_force_base_url=None, ex_force_auth_url=None, ex_force_auth_version=None, ex_force_auth_token=None, ex_token_scope='project', ex_domain_name='Default', ex_tenant_name=None, ex_tenant_domain_id='default', ex_force_service_type=None, ex_force_service_name=None, ex_force_service_region=None, ex_auth_cache=None, ex_force_microversion=None, *args, **kwargs)[source]

Bases: object

openstack_connection_kwargs()[source]

Returns certain ex_* parameters for this connection.

Return type:

dict

exception libcloud.common.openstack.OpenStackException(value: str, http_code: int, driver: BaseDriver | None = None)[source]

Bases: ProviderError

class libcloud.common.openstack.OpenStackResponse(response, connection)[source]

Bases: Response

Parameters:
  • response (httplib.HTTPResponse) – HTTP response object. (optional)

  • connection (Connection) – Parent connection object.

has_content_type(content_type)[source]
node_driver = None
parse_body()[source]

Parse response body.

Override in a provider’s subclass.

Returns:

Parsed body.

Return type:

str

parse_error()[source]

Parse the error messages.

Override in a provider’s subclass.

Returns:

Parsed error.

Return type:

str

success()[source]

Determine if our request was successful.

The meaning of this can be arbitrary; did we receive OK status? Did the node get created? Were we authenticated?

Return type:

bool

Returns:

True or False