ironicclient.common.utils module¶
- class ironicclient.common.utils.ListCommandArgs(*args, **kwargs)[source]¶
Bases:
ProtocolProtocol for parsed args passed to list commands (marker, limit, etc).
- detail: bool¶
- fields: list[list[str]] | None¶
- limit: int | None¶
- marker: str | None¶
- sort_dir: str | None¶
- sort_key: str | None¶
- ironicclient.common.utils.args_array_to_dict(kwargs: dict[str, Any], key_to_convert: str) dict[str, Any][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.args_array_to_patch(op: str, attributes: list[str]) list[dict[str, Any]][source]¶
- ironicclient.common.utils.bool_argument_value(arg_name: str, bool_str: str, strict: bool = True, default: bool = False) bool[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: list[str] | None, valid_fields: list[str]) None[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: str | None = None, limit: int | None = None, sort_key: str | None = None, sort_dir: str | None = None, fields: list[str] | None = None, detail: bool = False, project: str | None = None, public: bool | None = None) list[str][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: ListCommandArgs, fields: list[str], field_labels: list[str]) dict[str, Any][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: dict[str, Any], props: list[str] | None = None) dict[str, Any][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.format_hash(data: dict[str, Any] | None, prefix: str = '') str | None[source]¶
- ironicclient.common.utils.get_from_stdin(info_desc: str) str[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.get_json_data(data: bytes) dict[str, Any] | list[Any] | None[source]¶
Check if the binary data is JSON and parse it if so.
- Parameters:
data – Raw bytes to parse (e.g. response body).
- Returns:
Parsed dict or list if valid JSON, otherwise None.
- ironicclient.common.utils.handle_json_arg(json_arg: str, info_desc: str) list[Any] | dict[str, Any] | None[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, or None if json_arg is empty (e.g. after reading from stdin with no input).
- Raises:
InvalidAttribute if the argument cannot be parsed.
- ironicclient.common.utils.handle_json_or_file_arg(json_arg: str) list[Any] | dict[str, Any][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: list[str] | None) dict[str, Any][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: str) bytes[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: int | float, poll_interval: int | float, poll_delay_function: Callable[[int | float], Any] | None, timeout_message: str | Callable[[], str]) Iterator[int][source]¶