osc_lib.utils.columns.
get_column_definitions
(attr_map, long_listing)¶Return table headers and column names for a listing table.
An attribute map (attr_map) is a list of table entry definitions and the format of the map is as follows:
Parameters: |
|
---|---|
Returns: | A tuple of a list of table headers and a list of column names. |
osc_lib.utils.columns.
get_columns
(item, attr_map=None)¶Return pair of resource attributes and corresponding display names.
Parameters: |
|
---|---|
Returns: | A pair of tuple of attributes and tuple of display names. (('id', 'name', 'tenant_id', 'foo'), # attributes
('ID', 'Name', 'Project', 'foo') # display names
Both tuples of attributes and display names are sorted by display names in the alphabetical order. Attributes not found in a given attr_map are kept as-is. |
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: |
|
---|
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: |
|
---|
osc_lib.utils.
build_kwargs_dict
(arg_name, value)¶Return a dictionary containing arg_name if value is set.
osc_lib.utils.
calculate_header_and_attrs
(column_headers, attrs, parsed_args)¶Calculate headers and attribute names based on parsed_args.column.
When –column (-c) option is specified, this function calculates column headers and expected API attribute names according to the OSC header/column definitions.
This function also adjusts the content of parsed_args.columns if API attribute names are used in parsed_args.columns. This allows users to specify API attribute names in -c option.
Parameters: |
|
---|---|
Returns: | A tuple of calculated headers and API attribute names. |
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: |
|
---|---|
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: |
|
---|---|
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: |
|
---|---|
Returns: | a string formatted to {‘key1’=[‘value1’, ‘value2’]} with separated by separator |
osc_lib.utils.
format_list
(data, separator=', ')¶Return a formatted strings
Parameters: |
|
---|---|
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: |
|
---|---|
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: |
|
---|
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: |
|
---|
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_type=None)¶Sort items based on sort keys and sort directions given by sort_str.
Parameters: |
|
---|---|
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: |
|
---|---|
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: |
|
---|---|
Return type: | True on success |
Except where otherwise noted, this document is licensed under Creative Commons Attribution 3.0 License. See all OpenStack Legal Documents.