ironicclient.common.utils module¶
- class ironicclient.common.utils.HelpFormatter(prog, indent_increment=2, max_help_position=24, width=None)[source]¶
Bases:
argparse.HelpFormatter
- ironicclient.common.utils.args_array_to_dict(kwargs, key_to_convert)[source]¶
Convert the value in a dictionary entry to a dictionary.
From the kwargs dictionary, converts the value of the key_to_convert entry from a list of key-value pairs to a dictionary.
- Parameters
kwargs – a dictionary
key_to_convert – the key (in kwargs), whose value is expected to be a list of key=value strings. This value will be converted to a dictionary.
- Returns
kwargs, the (modified) dictionary
- ironicclient.common.utils.bool_argument_value(arg_name, bool_str, strict=True, default=False)[source]¶
Returns the Boolean represented by bool_str.
Returns the Boolean value for the argument named arg_name. The value is represented by the string bool_str. If the string is an invalid Boolean string: if strict is True, a CommandError exception is raised; otherwise the default value is returned.
- Parameters
arg_name – The name of the argument
bool_str – The string representing a Boolean value
strict – Used if the string is invalid. If True, raises an exception. If False, returns the default value.
default – The default value to return if the string is invalid and not strict
- Returns
the Boolean value represented by bool_str or the default value if bool_str is invalid and strict is False
- Raises
CommandError – if bool_str is an invalid Boolean string
- ironicclient.common.utils.check_for_invalid_fields(fields, valid_fields)[source]¶
Check for invalid fields.
- Parameters
fields – A list of fields specified by the user.
valid_fields – A list of valid fields.
- Raises
CommandError – If invalid fields were specified by the user.
- ironicclient.common.utils.common_filters(marker=None, limit=None, sort_key=None, sort_dir=None, fields=None, detail=False)[source]¶
Generate common filters for any list request.
- Parameters
marker – entity ID from which to start returning entities.
limit – maximum number of entities to return.
sort_key – field to use for sorting.
sort_dir – direction of sorting: ‘asc’ or ‘desc’.
fields – a list with a specified set of fields of the resource to be returned.
detail – Boolean, True to return detailed information. This parameter can be used for resources which accept ‘detail’ as a URL parameter.
- Returns
list of string filters.
- ironicclient.common.utils.common_params_for_list(args, fields, field_labels)[source]¶
Generate ‘params’ dict that is common for every ‘list’ command.
- Parameters
args – arguments from command line.
fields – possible fields for sorting.
field_labels – possible field labels for sorting.
- Returns
a dict with params to pass to the client method.
- ironicclient.common.utils.convert_list_props_to_comma_separated(data, props=None)[source]¶
Convert the list-type properties to comma-separated strings
- Parameters
data – the input dict object.
props – the properties whose values will be converted. Default to None to convert all list-type properties of the input.
- Returns
the result dict instance.
- ironicclient.common.utils.define_command(subparsers, command, callback, cmd_mapper)[source]¶
Define a command in the subparsers collection.
- Parameters
subparsers – subparsers collection where the command will go
command – command name
callback – function that will be used to process the command
- ironicclient.common.utils.define_commands_from_module(subparsers, command_module, cmd_mapper)[source]¶
Add do_ methods in a module and add as commands into a subparsers.
- ironicclient.common.utils.get_from_stdin(info_desc)[source]¶
Read information from stdin.
- Parameters
info_desc – A string description of the desired information
- Raises
InvalidAttribute if there was a problem reading from stdin
- Returns
the string that was read from stdin
- ironicclient.common.utils.handle_json_arg(json_arg, info_desc)[source]¶
Read a JSON argument from stdin, file or string.
- Parameters
json_arg – May be a file name containing the JSON, a JSON string, or ‘-’ indicating that the argument should be read from standard input.
info_desc – A string description of the desired information
- Returns
A list or dictionary parsed from JSON.
- Raises
InvalidAttribute if the argument cannot be parsed.
- ironicclient.common.utils.handle_json_or_file_arg(json_arg)[source]¶
Attempts to read JSON argument from file or string.
- Parameters
json_arg – May be a file name containing the YAML or JSON, or a JSON string.
- Returns
A list or dictionary parsed from JSON.
- Raises
InvalidAttribute if the argument cannot be parsed.
- ironicclient.common.utils.key_value_pairs_to_dict(key_value_pairs)[source]¶
Convert a list of key-value pairs to a dictionary.
- Parameters
key_value_pairs – a list of strings, each string is in the form <key>=<value>
- Returns
a dictionary, possibly empty
- ironicclient.common.utils.make_configdrive(path)[source]¶
Make the config drive file.
- Parameters
path – The directory containing the config drive files.
- Returns
A gzipped and base64 encoded configdrive string.
- ironicclient.common.utils.poll(timeout, poll_interval, poll_delay_function, timeout_message)[source]¶