The watcherclient.common.utils Module

class watcherclient.common.utils.HelpFormatter(prog, indent_increment=2, max_help_position=24, width=None)[source]

Bases: argparse.HelpFormatter

start_section(heading)[source]
watcherclient.common.utils.args_array_to_dict(kwargs, key_to_convert)[source]
watcherclient.common.utils.args_array_to_patch(op, attributes, exclude_fields=[])[source]
watcherclient.common.utils.common_filters(limit=None, sort_key=None, sort_dir=None, marker=None)[source]

Generate common filters for any list request.

Parameters
  • limit – maximum number of entities to return.

  • sort_key – field to use for sorting.

  • sort_dir – direction of sorting: ‘asc’ or ‘desc’.

  • marker – The last actionplan UUID of the previous page.

Returns

list of string filters.

watcherclient.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.

watcherclient.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

watcherclient.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.

watcherclient.common.utils.import_versioned_module(version, submodule=None)[source]
watcherclient.common.utils.is_uuid_like(val)[source]

Returns validation of a value as a UUID.

For our purposes, a UUID is a canonical form string: aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa

watcherclient.common.utils.serialize_file_to_dict(filename)[source]
watcherclient.common.utils.split_and_deserialize(string, exclude_fields=[])[source]

Split and try to JSON deserialize a string.

Gets a string with the KEY=VALUE format, split it (using ‘=’ as the separator) and try to JSON deserialize the VALUE.

Returns

A tuple of (key, value).