openstackclient.common package

Submodules

openstackclient.common.clientmanager module

Manage access to the clients, including authenticating when needed.

class openstackclient.common.clientmanager.ClientCache(factory)

Bases: object

Descriptor class for caching created client handles.

class openstackclient.common.clientmanager.ClientManager(cli_options, api_version=None, verify=True, pw_func=None)

Bases: object

Manages access to API clients, including authentication.

auth_ref

Dereference will trigger an auth if it hasn’t already

get_endpoint_for_service_type(service_type, region_name=None)

Return the endpoint URL for the service type.

setup_auth()

Set up authentication

This is deferred until authentication is actually attempted because it gets in the way of things that do not require auth.

openstackclient.common.clientmanager.build_plugin_option_parser(parser)

Add plugin options to the parser

openstackclient.common.clientmanager.get_plugin_modules(group)

Find plugin entry points

openstackclient.common.commandmanager module

Modify cliff.CommandManager

class openstackclient.common.commandmanager.CommandManager(namespace, convert_underscores=True)

Bases: cliff.commandmanager.CommandManager

Add additional functionality to cliff.CommandManager

Load additional command groups after initialization Add _command_group() methods

add_command_group(group=None)

Adds another group of command entrypoints

get_command_groups()

Returns a list of the loaded command groups

get_command_names(group=None)

Returns a list of commands loaded for the specified group

load_commands(namespace)

openstackclient.common.exceptions module

Exception definitions.

exception openstackclient.common.exceptions.AuthorizationFailure

Bases: exceptions.Exception

exception openstackclient.common.exceptions.BadRequest(code, message=None, details=None)

Bases: openstackclient.common.exceptions.ClientException

HTTP 400 - Bad request: you sent some malformed data.

http_status = 400
message = 'Bad request'
exception openstackclient.common.exceptions.ClientException(code, message=None, details=None)

Bases: exceptions.Exception

The base exception class for all exceptions this library raises.

exception openstackclient.common.exceptions.CommandError

Bases: exceptions.Exception

exception openstackclient.common.exceptions.Conflict(code, message=None, details=None)

Bases: openstackclient.common.exceptions.ClientException

HTTP 409 - Conflict

http_status = 409
message = 'Conflict'
exception openstackclient.common.exceptions.EndpointNotFound

Bases: exceptions.Exception

Could not find Service or Region in Service Catalog.

exception openstackclient.common.exceptions.Forbidden(code, message=None, details=None)

Bases: openstackclient.common.exceptions.ClientException

HTTP 403 - Forbidden: not authorized to access to this resource.

http_status = 403
message = 'Forbidden'
exception openstackclient.common.exceptions.HTTPNotImplemented(code, message=None, details=None)

Bases: openstackclient.common.exceptions.ClientException

HTTP 501 - Not Implemented: server does not support this operation.

http_status = 501
message = 'Not Implemented'
exception openstackclient.common.exceptions.NoTokenLookupException

Bases: exceptions.Exception

This does not support looking up endpoints from an existing token.

exception openstackclient.common.exceptions.NotFound(code, message=None, details=None)

Bases: openstackclient.common.exceptions.ClientException

HTTP 404 - Not found

http_status = 404
message = 'Not found'
exception openstackclient.common.exceptions.OverLimit(code, message=None, details=None)

Bases: openstackclient.common.exceptions.ClientException

HTTP 413 - Over limit: reached the API limits for this time period.

http_status = 413
message = 'Over limit'
exception openstackclient.common.exceptions.Unauthorized(code, message=None, details=None)

Bases: openstackclient.common.exceptions.ClientException

HTTP 401 - Unauthorized: bad credentials.

http_status = 401
message = 'Unauthorized'
exception openstackclient.common.exceptions.UnsupportedVersion

Bases: exceptions.Exception

The user is trying to use an unsupported version of the API

openstackclient.common.exceptions.from_response(response, body)

Return an instance of a ClientException based on an httplib2 response.

Usage:

resp, body = http.request(...)
if resp.status != 200:
    raise exception_from_response(resp, body)

openstackclient.common.extension module

Extension action implementations

class openstackclient.common.extension.ListExtension(app, app_args)

Bases: cliff.lister.Lister

List API extensions

get_parser(prog_name)
log = <logging.Logger object at 0x7fb2d3f03710>
take_action(parsed_args)

openstackclient.common.limits module

Limits Action Implementation

class openstackclient.common.limits.ShowLimits(app, app_args)

Bases: cliff.lister.Lister

Show compute and volume limits

get_parser(prog_name)
log = <logging.Logger object at 0x7fb2d3934390>
take_action(parsed_args)

openstackclient.common.module module

Module action implementation

class openstackclient.common.module.ListCommand(app, app_args)

Bases: cliff.lister.Lister

List recognized commands by group

auth_required = False
log = <logging.Logger object at 0x7fb2d38ad390>
take_action(parsed_args)
class openstackclient.common.module.ListModule(app, app_args)

Bases: cliff.show.ShowOne

List module versions

auth_required = False
get_parser(prog_name)
log = <logging.Logger object at 0x7fb2d38ad590>
take_action(parsed_args)

openstackclient.common.parseractions module

argparse Custom Actions

class openstackclient.common.parseractions.KeyValueAction(option_strings, dest, nargs=None, const=None, default=None, type=None, choices=None, required=False, help=None, metavar=None)

Bases: argparse.Action

A custom action to parse arguments as key=value pairs

Ensures that dest is a dict

class openstackclient.common.parseractions.RangeAction(option_strings, dest, nargs=None, const=None, default=None, type=None, choices=None, required=False, help=None, metavar=None)

Bases: argparse.Action

A custom action to parse a single value or a range of values

Parses single integer values or a range of integer values delimited by a colon and returns a tuple of integers: ‘4’ sets dest to (4, 4) ‘6:9’ sets dest to (6, 9)

openstackclient.common.quota module

Quota action implementations

class openstackclient.common.quota.SetQuota(app, app_args)

Bases: cliff.command.Command

Set quotas for project or class

get_parser(prog_name)
log = <logging.Logger object at 0x7fb2d3863b90>
take_action(parsed_args)
class openstackclient.common.quota.ShowQuota(app, app_args)

Bases: cliff.show.ShowOne

Show quotas for project or class

get_compute_volume_quota(client, parsed_args)
get_network_quota(parsed_args)
get_parser(prog_name)
log = <logging.Logger object at 0x7fb2d3863750>
take_action(parsed_args)

openstackclient.common.timing module

Timing Implementation

class openstackclient.common.timing.Timing(app, app_args)

Bases: cliff.lister.Lister

Show timing data

log = <logging.Logger object at 0x7fb2d402d750>
take_action(parsed_args)

openstackclient.common.utils module

Common client utilities

openstackclient.common.utils.env(*vars, **kwargs)

Search for the first defined of possibly many env vars

Returns the first environment variable defined in vars, or returns the default defined in kwargs.

openstackclient.common.utils.find_resource(manager, name_or_id, **kwargs)

Helper for the _find_* methods.

Parameters:
  • manager – A client manager class
  • name_or_id – The resource we are trying to find
  • kwargs – To be used in calling .find()
Return type:

The found resource

This method will attempt to find a resource in a variety of ways. Primarily .get() methods will be called with name_or_id as an integer value, and tried again as a string value.

If both fail, then a .find() is attempted, which is essentially calling a .list() function with a ‘name’ query parameter that is set to name_or_id.

Lastly, if any kwargs are passed in, they will be treated as additional query parameters. This is particularly handy in the case of finding resources in a domain.

openstackclient.common.utils.format_dict(data)

Return a formatted string of key value pairs

Parameters:
  • data – a dict
  • format – optional formatting hints
Return type:

a string formatted to key=’value’

openstackclient.common.utils.format_list(data)

Return a formatted strings

Parameters:data – a list of strings
Return type:a string formatted to a,b,c
openstackclient.common.utils.get_client_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

openstackclient.common.utils.get_dict_properties(item, fields, mixed_case_fields=[], formatters={})

Return a tuple containing the item properties.

Parameters:
  • item – a single dict resource
  • fields – tuple of strings with the desired field names
  • mixed_case_fields – tuple of field names to preserve case
  • formatters – dictionary mapping field names to callables to format the values
openstackclient.common.utils.get_effective_log_level()

Returns the lowest logging level considered by logging handlers

Retrieve an return the smallest log level set among the root logger’s handlers (in case of multiple handlers).

openstackclient.common.utils.get_field(item, field)
openstackclient.common.utils.get_item_properties(item, fields, mixed_case_fields=[], formatters={})

Return a tuple containing the item properties.

Parameters:
  • item – a single item resource (e.g. Server, Project, etc)
  • fields – tuple of strings with the desired field names
  • mixed_case_fields – tuple of field names to preserve case
  • formatters – dictionary mapping field names to callables to format the values
openstackclient.common.utils.get_password(stdin, prompt=None, confirm=True)
openstackclient.common.utils.read_blob_file_contents(blob_file)
openstackclient.common.utils.sort_items(items, sort_str)

Sort items based on sort keys and sort directions given by sort_str.

Parameters:
  • items – a list or generator object of items
  • sort_str – a string defining the sort rules, the format is

‘<key1>:[direction1],<key2>:[direction2]...’, direction can be ‘asc’ for ascending or ‘desc’ for descending, if direction is not given, it’s ascending by default :return: sorted items

openstackclient.common.utils.string_to_bool(arg)
openstackclient.common.utils.wait_for_status(status_f, res_id, status_field='status', success_status=['active'], sleep_time=5, callback=None)

Wait for status change on a resource during a long-running operation

Parameters:
  • status_f – a status function that takes a single id argument
  • res_id – the resource id to watch
  • success_status – a list of status strings for successful completion
  • status_field – the status attribute in the returned resource object
  • sleep_time – wait this long (seconds)
  • callback – called per sleep cycle, useful to display progress
Return type:

True on success

Module contents