command.session

Defines a base class for all command classes operating upon a Session object.

class lmi.scripts.common.command.session.LmiSessionCommand(*args, **kwargs)[source]

Base class for end-point commands operating upon a session object.

Using metaclass: SessionCommandMetaClass.

classmethod cim_namespace()[source]

This returns default cim namespace, the connection object will be nested into before being passed to associated function. It can be overriden in few ways:

  1. by setting [CIM] Namespace option in configuration
  2. by giving --namespace argument on command line to the lmi meta-command
  3. by setting NAMESPACE property in declaration of command

Higher number means higher priority.

classmethod connection_timeout()[source]

Returns maximum number of seconds the client shall wait for broker’s reply. Defaults to None which means that it’s up to the connection object itself to decide. It can be oveririden with CONNECTION_TIMEOUT property in declaration of command.

classmethod dest_pos_args_count()[source]

There is a namespace/connection object passed as the first positional argument.

execute_on_connection(connection, *args, **kwargs)[source]

Wraps the execute() method with connection adjustments. Connection object is not usually passed directly to associated function. Mostly it’s the namespace object that is expected. This method checks, whether the namespace object is desired and modifies connection accordingly.

Parameters:
  • connection (lmi.shell.LMIConnection) – Connection to single host.
  • args (list) – Arguments handed over to associated function.
  • kwargs (dictionary) – Keyword arguments handed over to associated function.
process_host_result(hostname, success, result)[source]

Called from process_session() after single host gets processed. By default this prints obtained result with default formatter if the execution was successful. Children of this class may want to override this.

Parameters:
  • hostname (string) – Name of host involved.
  • success (boolean) – Whether the action on host succeeded.
  • result – Either the value returned by associated function upon a successful invocation or an exception.
process_session(session, args, kwargs)[source]

Process each host of given session, call the associated command function, collect results and print it to standard output.

Parameters:
  • session (Session) – Session object with set of hosts.
  • args (list) – Positional arguments to pass to associated function in command library.
  • kwargs (dictionary) – Keyword arguments as a dictionary.
Returns:

Exit code of application.

Return type:

integer

process_session_results(session, results)[source]

Called at the end of process_session()‘s execution. It’s supposed to do any summary work upon results from all hosts. By default it just prints errors in a form of list.

Parameters:
  • session (lmi.scripts.common.session.Session) – Session object.
  • results (dictionary) –

    Dictionary of form:

    { 'hostname' : (success_flag, result), ... }
    

    where result is either an exception or returned value of associated function, depending on success_flag. See the process_host_result().

take_action(connection, args, kwargs)[source]

Executes an action on single host and collects results.

Parameters:
  • connection (lmi.shell.LMIConnection) – Connection to a single host.
  • args (list) – Positional arguments for associated function.
  • kwargs (dictionary) – Keyword arguments for associated function.
Returns:

Column names and item list as a pair.

Return type:

tuple