Before reading this, please make sure you’re familiar with Command wrappers overview.
We focus here on commands intended for subclassing in command wrapper modules. OpenLMI Scripts defines and uses other kinds of commands internally. But the script developer does not need to know about them.
See also
General and class specific properties in Command properties.
Were already introduced before (see End-point commands). We’ll dive into details here.
Every end-point command allows to verify and transform options parsed by docopt before they are passed to associated function. This can happen in methods:
Taking pre-processed options dictionary as a first argument. Properties affecting this pre-processing can be found in Options pre-processing. This method shall check option values or their combination and raise lmi.scripts.common.errors.LmiInvalidOptions if any inconsistency is discovered.
Example usage:
class FileLister(command.LmiInstanceLister):
DYNAMIC_PROPERTIES = True
def verify_options(self, options):
file_types = { 'all', 'file', 'directory', 'symlink'
, 'fifo', 'device'}
if ( options['--type'] is not None
and options['--type'] not in file_types):
raise errors.LmiInvalidOptions(
'Invalid file type given, must be one of %s' %
file_types)
See also
API doccumentation on verify_options()
Takes verified options dictionary. It modifies this dictionary in arbitrary way in place. Its return value is ignored.
Example usage:
class Lister(command.LmiLister):
COLUMNS = ('Device', 'Name', "ElementName", "Type")
def transform_options(self, options):
"""
Rename 'device' option to 'devices' parameter name for better
readability.
"""
options['<devices>'] = options.pop('<device>')
See also
API documentation on transform_options()
Above methods can be used to process options in a way that any script library function can be called. In case we need more control over what is called or when we want to decide at runtime which function shall be called, we may override execute() method instead. Example of this may be found at Associating a function.
This command invokes associated function on hosts in session, collects results from them and compares them to an expected value. It does not produce any output, when all returned values are expected.
This command class is very useful when wrapping up some CIM class’s method such as LMI_Service::StartService(). Example can be seen in Property descriptions.
Its specific properties are listed in LmiCheckResult properties.
See also
API documentation on LmiCheckResult
Prints tablelike data. It expects associated function to return its result in form:
[row1, row2, ...]
Where rowX is a tuple containing row values. Each such row is list or tuple of the same length. There is a property COLUMNS defining column names [1] (see LmiLister properties). Generator is prefered over a list of rows. If COLUMNS property is omitted, returned value shall take the following form instead:
(columns, data)
Where columns has the same meaning as COLUMNS as a class property and data is the result of previous case [2].
See also
API documentation on LmiLister
Is a variant of LmiLister. Instead of rows being tuples, here they are instances of some CIM class. Instead of using COLUMNS property for specifying columns labels, PROPERTIES is used for the same purpose here. Its primary use is in specifying which properties of instances shall be rendered in which column. This is described in detail in LmiShowInstance and LmiInstanceLister properties.
The expected output of associated function is therefore:
[instance1, instance2, ...]
Again, usage of generators is preferred.
See also
API documentation on LmiInstanceLister
Renders a single instance of some CIM class. It’s rendered in a form of two-column table, where the first column contains property names and the second their corresponding values. Rendering is controlled in the same way as for LmiInstanceLister (see LmiShowInstance and LmiInstanceLister properties).
See also
API documentation on LmiShowInstance
[1] | Having the same length as each row in returned data. |
[2] | Generator or a list of rows. |