openstackclient.common package

Submodules

openstackclient.common.availability_zone module

Availability Zone action implementations

class openstackclient.common.availability_zone.ListAvailabilityZone(app, app_args, cmd_name=None)

Bases: openstackclient.common.command.Lister

List availability zones and their status

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

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=None, api_version=None, verify=True, pw_func=None)

Bases: object

Manages access to API clients, including authentication.

PLUGIN_INTERFACE_VERSION = '2'
auth_ref

Dereference will trigger an auth if it hasn’t already

get_configuration()
get_endpoint_for_service_type(service_type, region_name=None, interface='public')

Return the endpoint URL for the service type.

is_network_endpoint_enabled()

Check if the network endpoint is enabled

setup_auth(required_scope=True)

Set up authentication

Parameters:required_scope – indicate whether a scoped token is required

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.command module

class openstackclient.common.command.Command(app, app_args, cmd_name=None)

Bases: cliff.command.Command

log = <logging.Logger object at 0x7f3047db7890>
run(parsed_args)
class openstackclient.common.command.CommandMeta

Bases: abc.ABCMeta

class openstackclient.common.command.Lister(app, app_args, cmd_name=None)

Bases: openstackclient.common.command.Command, cliff.lister.Lister

log = <logging.Logger object at 0x7f3047db7a90>
class openstackclient.common.command.ShowOne(app, app_args, cmd_name=None)

Bases: openstackclient.common.command.Command, cliff.show.ShowOne

log = <logging.Logger object at 0x7f3047db7c10>

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.configuration module

Configuration action implementations

class openstackclient.common.configuration.ShowConfiguration(app, app_args, cmd_name=None)

Bases: openstackclient.common.command.ShowOne

Display configuration details

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

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, cmd_name=None)

Bases: openstackclient.common.command.Lister

List API extensions

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

openstackclient.common.limits module

Limits Action Implementation

class openstackclient.common.limits.ShowLimits(app, app_args, cmd_name=None)

Bases: openstackclient.common.command.Lister

Show compute and block storage limits

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

openstackclient.common.logs module

Application logging

class openstackclient.common.logs.LogConfigurator(options)

Bases: object

configure(cloud_config)
openstackclient.common.logs.get_loggers()
openstackclient.common.logs.log_level_from_config(config)
openstackclient.common.logs.log_level_from_options(options)
openstackclient.common.logs.log_level_from_string(level_string)
openstackclient.common.logs.set_warning_filter(log_level)

openstackclient.common.module module

Module action implementation

class openstackclient.common.module.ListCommand(app, app_args, cmd_name=None)

Bases: openstackclient.common.command.Lister

List recognized commands by group

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

Bases: openstackclient.common.command.ShowOne

List module versions

auth_required = False
get_parser(prog_name)
log = <logging.Logger object at 0x7f3047c68890>
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.MultiKeyValueAction(option_strings, dest, nargs=None, required_keys=None, optional_keys=None, **kwargs)

Bases: argparse.Action

A custom action to parse arguments as key1=value1,key2=value2 pairs

Ensure that dest is a list. The list will finally contain multiple dicts, with key=value pairs in them.

NOTE: The arguments string should be a comma separated key-value pairs. And comma(‘,’) and equal(‘=’) may not be used in the key or value.

class openstackclient.common.parseractions.NonNegativeAction(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 check whether the value is non-negative or not

Ensures the value is >= 0.

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, cmd_name=None)

Bases: openstackclient.common.command.Command

Set quotas for project or class

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

Bases: openstackclient.common.command.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 0x7f30476f8e50>
take_action(parsed_args)

openstackclient.common.session module

Subclass of keystoneauth1.session

class openstackclient.common.session.TimingSession(**kwargs)

Bases: keystoneauth1.session.Session

A Session that supports collection of timing data per Method URL

get_timings()
request(url, method, **kwargs)

Wrap the usual request() method with the timers

reset_timings()

openstackclient.common.timing module

Timing Implementation

class openstackclient.common.timing.Timing(app, app_args, cmd_name=None)

Bases: openstackclient.common.command.Lister

Show timing data

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

openstackclient.common.utils module

Common client utilities

openstackclient.common.utils.build_kwargs_dict(arg_name, value)

Return a dictionary containing arg_name if value is set.

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
Return type:a string formatted to key=’value’
openstackclient.common.utils.format_list(data, separator=', ')

Return a formatted strings

Parameters:
  • data – a list of strings
  • separator – the separator to use between strings (default: ‘, ‘)
Return type:

a string formatted based on separator

openstackclient.common.utils.format_list_of_dicts(data)

Return a formatted string of key value pairs for each dict

Parameters:data – a list of dicts
Return type:a string formatted to key=’value’ with dicts separated by new line
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=None, formatters=None)

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 and 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=None, formatters=None)

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.is_ascii(string)
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
Returns:

sorted items

openstackclient.common.utils.wait_for_delete(manager, res_id, status_field='status', error_status=['error'], exception_name=['NotFound'], sleep_time=5, timeout=300, callback=None)

Wait for resource deletion

Parameters:
  • manager – the manager from which we can get the resource
  • res_id – the resource id to watch
  • status_field – the status attribute in the returned resource object, this is used to check for error states while the resource is being deleted
  • error_status – a list of status strings for error
  • exception_name – a list of exception strings for deleted case
  • sleep_time – wait this long between checks (seconds)
  • timeout – check until this long (seconds)
  • callback – called per sleep cycle, useful to display progress; this function is passed a progress value during each iteration of the wait loop
Return type:

True on success, False if the resource has gone to error state or the timeout has been reached

openstackclient.common.utils.wait_for_status(status_f, res_id, status_field='status', success_status=['active'], error_status=['error'], 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
  • status_field – the status attribute in the returned resource object
  • success_status – a list of status strings for successful completion
  • error_status – a list of status strings for error
  • sleep_time – wait this long (seconds)
  • callback – called per sleep cycle, useful to display progress
Return type:

True on success

Module contents