The nova.openstack.common.cliutils
Module¶
-
exception
MissingArgs
(missing)¶ Bases:
exceptions.Exception
Supplied arguments are not sufficient for calling a function.
-
add_arg
(func, *args, **kwargs)¶ Bind CLI arguments to a shell.py do_foo function.
-
arg
(*args, **kwargs)¶ Decorator for CLI args.
Example:
>>> @arg("name", help="Name of the new entity") ... def entity_create(args): ... pass
-
env
(*args, **kwargs)¶ Returns the first environment variable set.
If all are empty, defaults to ‘’ or keyword arg default.
-
exit
(msg='')¶
-
get_password
(max_password_prompts=3)¶ Read password from TTY.
-
get_service_type
(f)¶ Retrieves service type from function.
-
isunauthenticated
(func)¶ Checks if the function does not require authentication.
Mark such functions with the @unauthenticated decorator.
Returns: bool
-
pretty_choice_list
(l)¶
-
print_dict
(dct, dict_property='Property', wrap=0, dict_value='Value')¶ Print a dict as a table of two columns.
Parameters: - dct – dict to print
- dict_property – name of the first column
- wrap – wrapping for the second column
- dict_value – header label for the value (second) column
-
print_list
(objs, fields, formatters=None, sortby_index=0, mixed_case_fields=None, field_labels=None)¶ Print a list or objects as a table, one row per object.
Parameters: - objs – iterable of
Resource
- fields – attributes that correspond to columns, in order
- formatters – dict of callables for field formatting
- sortby_index – index of the field for sorting table rows
- mixed_case_fields – fields corresponding to object attributes that have mixed case names (e.g., ‘serverId’)
- field_labels – Labels to use in the heading of the table, default to fields.
- objs – iterable of
-
service_type
(stype)¶ Adds ‘service_type’ attribute to decorated function.
Usage:
@service_type('volume') def mymethod(f): ...
-
unauthenticated
(func)¶ Adds ‘unauthenticated’ attribute to decorated function.
Usage:
>>> @unauthenticated ... def mymethod(f): ... pass
-
validate_args
(fn, *args, **kwargs)¶ Check that the supplied args are sufficient for calling a function.
>>> validate_args(lambda a: None) Traceback (most recent call last): ... MissingArgs: Missing argument(s): a >>> validate_args(lambda a, b, c, d: None, 0, c=1) Traceback (most recent call last): ... MissingArgs: Missing argument(s): b, d
Parameters: - fn – the function to check
- arg – the positional arguments supplied
- kwargs – the keyword arguments supplied