Defines command class used to choose other commands depending on profile and class requirements.
- class lmi.scripts.common.command.select.LmiSelectCommand(app, cmd_name, parent=None)¶
Base class for command selectors. It does not process command line arguments. Thery are passed unchanged to selected command whose requirements are met. Its doc string is not interpreted in any way.
If there are more hosts, conditions are evaluated per each. They are then split into groups, each fulfilling particular condition. Associated commands are then invoked on these groups separately.
class MySelect(LmiSelectCommand): SELECT = [ ( 'OpenLMI-Hardware >= 0.4.2' , 'lmi.scripts.hardware.current.Cmd'), ('OpenLMI-Hardware', 'lmi.scripts.hardware.pre042.Cmd') ] DEFAULT = MissingHwProviderCmd
Using metaclass: meta.SelectMetaClass.
- eval_expr(expr, hosts, cache=None)¶
Evaluate expression on group of hosts.
- expr (string) – Expression to evaluate.
- hosts (list) – Group of hosts that shall be checked.
- cache (dictionary) – Optional cache object speeding up evaluation by reducing number of queries to broker.
Subset of hosts satisfying expr.
- classmethod get_conditionals()¶
Get the expressions with associated commands. This shall be overriden by a subclass.
Returns: Pair of (expressions, default). Where expressions is a list of pairs (condition, command). And default is the same as command used in case no condition is satisfied. Return type: list
Try to get usage of any command satisfying some expression.
Raises: Same exceptions as select_cmds().
Iterate over command factories with associated sessions and execute them with unchanged args.
Generator of command factories with associated groups of hosts. It evaluates given expressions on session. In this process all expressions from get_conditionals() are checked in a row. Host satisfying some expression is added to group associated with it and is excluded from processing following expressions.
cache (dictionary) – Optional cache object speeding up the evaluation by reducing number of queries to broker.
Pairs in form (command_factory, session_proxy).
if no condition is satisfied for at least one host. Note that this exception is raised at the end of evaluation. This lets you choose whether you want to process satisfied hosts - by processing the generator at once. Or whether you want to be sure it is satisfied by all of them - you turn the generator into a list.
if no successful connection was done.