osc_lib package¶
Subpackages¶
- osc_lib.api package
- osc_lib.cli package
- osc_lib.command package
- osc_lib.tests package
- Subpackages
- Submodules
- osc_lib.tests.fakes module
- osc_lib.tests.test_clientmanager module
- osc_lib.tests.test_logs module
- osc_lib.tests.test_shell module
- osc_lib.tests.test_utils module
- osc_lib.tests.utils module
- Module contents
Submodules¶
osc_lib.clientmanager module¶
Manage access to the clients, including authenticating when needed.
-
class
osc_lib.clientmanager.
ClientCache
(factory)¶ Bases:
object
Descriptor class for caching created client handles.
-
class
osc_lib.clientmanager.
ClientManager
(cli_options=None, api_version=None, pw_func=None, app_name=None, app_version=None)¶ Bases:
object
Manages access to API clients, including authentication.
-
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_service_available
(service_type)¶ Check if a service type is in the current Service Catalog
-
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.
-
validate_scope
()¶
-
osc_lib.exceptions module¶
Exception definitions.
-
exception
osc_lib.exceptions.
AuthorizationFailure
¶ Bases:
exceptions.Exception
-
exception
osc_lib.exceptions.
BadRequest
(code, message=None, details=None)¶ Bases:
osc_lib.exceptions.ClientException
HTTP 400 - Bad request: you sent some malformed data.
-
http_status
= 400¶
-
message
= 'Bad request'¶
-
-
exception
osc_lib.exceptions.
ClientException
(code, message=None, details=None)¶ Bases:
exceptions.Exception
The base exception class for all exceptions this library raises.
-
exception
osc_lib.exceptions.
CommandError
¶ Bases:
exceptions.Exception
-
exception
osc_lib.exceptions.
Conflict
(code, message=None, details=None)¶ Bases:
osc_lib.exceptions.ClientException
HTTP 409 - Conflict
-
http_status
= 409¶
-
message
= 'Conflict'¶
-
-
exception
osc_lib.exceptions.
EndpointNotFound
¶ Bases:
exceptions.Exception
Could not find Service or Region in Service Catalog.
-
exception
osc_lib.exceptions.
Forbidden
(code, message=None, details=None)¶ Bases:
osc_lib.exceptions.ClientException
HTTP 403 - Forbidden: not authorized to access to this resource.
-
http_status
= 403¶
-
message
= 'Forbidden'¶
-
-
exception
osc_lib.exceptions.
HTTPNotImplemented
(code, message=None, details=None)¶ Bases:
osc_lib.exceptions.ClientException
HTTP 501 - Not Implemented: server does not support this operation.
-
http_status
= 501¶
-
message
= 'Not Implemented'¶
-
-
exception
osc_lib.exceptions.
InvalidValue
¶ Bases:
exceptions.Exception
An argument value is not valid: wrong type, out of range, etc
-
message
= 'Supplied value is not valid'¶
-
-
exception
osc_lib.exceptions.
NoTokenLookupException
¶ Bases:
exceptions.Exception
This does not support looking up endpoints from an existing token.
-
exception
osc_lib.exceptions.
NotFound
(code, message=None, details=None)¶ Bases:
osc_lib.exceptions.ClientException
HTTP 404 - Not found
-
http_status
= 404¶
-
message
= 'Not found'¶
-
-
exception
osc_lib.exceptions.
OverLimit
(code, message=None, details=None)¶ Bases:
osc_lib.exceptions.ClientException
HTTP 413 - Over limit: reached the API limits for this time period.
-
http_status
= 413¶
-
message
= 'Over limit'¶
-
-
exception
osc_lib.exceptions.
PluginAttributeError
¶ Bases:
exceptions.Exception
A plugin threw an AttributeError while being lazily loaded.
Bases:
osc_lib.exceptions.ClientException
HTTP 401 - Unauthorized: bad credentials.
-
exception
osc_lib.exceptions.
UnsupportedVersion
¶ Bases:
exceptions.Exception
The user is trying to use an unsupported version of the API
osc_lib.i18n module¶
osc_lib.logs module¶
Application logging
-
osc_lib.logs.
get_loggers
()¶
-
osc_lib.logs.
log_level_from_config
(config)¶
-
osc_lib.logs.
log_level_from_options
(options)¶
-
osc_lib.logs.
log_level_from_string
(level_string)¶
-
osc_lib.logs.
set_warning_filter
(log_level)¶
osc_lib.session module¶
Subclass of keystoneauth1.session
osc_lib.shell module¶
Command-line interface to the OpenStack APIs
-
class
osc_lib.shell.
OpenStackShell
(description=None, version=None, command_manager=None, stdin=None, stdout=None, stderr=None, interactive_app_factory=None, deferred_help=False)¶ Bases:
cliff.app.App
-
CONSOLE_MESSAGE_FORMAT
= '%(levelname)s: %(name)s %(message)s'¶
-
build_option_parser
(description, version)¶
-
clean_up
(cmd, result, err)¶
-
close_profile
()¶
-
configure_logging
()¶ Configure logging for the app.
-
init_profile
()¶
-
initialize_app
(argv)¶ Global app init bits:
- set up API versions
- validate authentication info
- authenticate against Identity if requested
-
interact
()¶
-
log
= <logging.Logger object>¶
-
prepare_to_run_command
(cmd)¶ Set up auth and API versions
-
run
(argv)¶
-
run_subcommand
(argv)¶
-
timing_data
= []¶
-
-
osc_lib.shell.
main
(argv=None)¶
-
osc_lib.shell.
prompt_for_password
(prompt=None)¶ Prompt user for a password
Prompt for a password if stdin is a tty.
osc_lib.utils module¶
Common client utilities
-
osc_lib.utils.
backward_compat_col_lister
(column_headers, columns, column_map)¶ Convert the column headers to keep column backward compatibility.
Replace the new column name of column headers by old name, so that the column headers can continue to support to show the old column name by –column/-c option with old name, like: volume list -c ‘Display Name’
Parameters: - column_headers – The column headers to be output in list command.
- columns – The columns to be output.
- column_map – The key of map is old column name, the value is new column name, like: {‘old_col’: ‘new_col’}
-
osc_lib.utils.
backward_compat_col_showone
(show_object, columns, column_map)¶ Convert the output object to keep column backward compatibility.
Replace the new column name of output object by old name, so that the object can continue to support to show the old column name by –column/-c option with old name, like: volume show -c ‘display_name’
Parameters: - show_object – The object to be output in create/show commands.
- columns – The columns to be output.
- column_map – The key of map is old column name, the value is new column name, like: {‘old_col’: ‘new_col’}
-
osc_lib.utils.
build_kwargs_dict
(arg_name, value)¶ Return a dictionary containing arg_name if value is set.
-
osc_lib.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.
-
osc_lib.utils.
find_min_match
(items, sort_attr, **kwargs)¶ Find all resources meeting the given minimum constraints
Parameters: - items – A List of objects to consider
- sort_attr – Attribute to sort the resulting list
- kwargs – A dict of attributes and their minimum values
Return type: A list of resources osrted by sort_attr that meet the minimums
-
osc_lib.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.
-
osc_lib.utils.
format_dict
(data)¶ Return a formatted string of key value pairs
Parameters: data – a dict Return type: a string formatted to key=’value’
-
osc_lib.utils.
format_dict_of_list
(data, separator='; ')¶ Return a formatted string of key value pair
Parameters: - data – a dict, key is string, value is a list of string, for example: {u’public’: [u‘2001:db8::8’, u‘172.24.4.6’]}
- separator – the separator to use between key/value pair (default: ‘; ‘)
Returns: a string formatted to {‘key1’=[‘value1’, ‘value2’]} with separated by separator
-
osc_lib.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
-
osc_lib.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
-
osc_lib.utils.
format_size
(size)¶ Display size of a resource in a human readable format
Parameters: size (string) – The size of the resource in bytes. Returns: Returns the size in human-friendly format Rtype string: This function converts the size (provided in bytes) of a resource into a human-friendly format such as K, M, G, T, P, E, Z
-
osc_lib.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
-
osc_lib.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
-
osc_lib.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).
-
osc_lib.utils.
get_field
(item, field)¶
-
osc_lib.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
-
osc_lib.utils.
get_password
(stdin, prompt=None, confirm=True)¶
-
osc_lib.utils.
is_ascii
(string)¶
-
osc_lib.utils.
read_blob_file_contents
(blob_file)¶
-
osc_lib.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
-
osc_lib.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
-
osc_lib.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