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

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

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

Using metaclass: SessionCommandMetaClass.

classmethod cim_namespace()

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()

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()

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

execute_on_connection(connection, *args, **kwargs)

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.

  • connection ( – 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)

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.

  • 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)

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

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

Exit code of application.

Return type:


process_session_results(session, results)

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.

  • 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)

Executes an action on single host and collects results.

  • connection ( – Connection to a single host.
  • args (list) – Positional arguments for associated function.
  • kwargs (dictionary) – Keyword arguments for associated function.

Column names and item list as a pair.

Return type: