CedarBackup2.cli._ActionSet

Package CedarBackup2 :: Module cli :: Class _ActionSet |
[hide private]
[frames] | no frames]

# Class _ActionSet

source code

    object --+
             |
            _ActionSet

Class representing a set of local actions to be executed.

This class does four different things. First, it ensures that the actions specified on the command-line are sensible. The command-line can only list either built-in actions or extended actions specified in configuration. Also, certain actions (in NONCOMBINE_ACTIONS) cannot be combined with other actions.

Second, the class enforces an execution order on the specified actions. Any time actions are combined on the command line (either built-in actions or extended actions), we must make sure they get executed in a sensible order.

Third, the class ensures that any pre-action or post-action hooks are scheduled and executed appropriately. Hooks are configured by building a dictionary mapping between hook action name and command. Pre-action hooks are executed immediately before their associated action, and post-action hooks are executed immediately after their associated action.

Finally, the class properly interleaves local and managed actions so that the same action gets executed first locally and then on managed peers.

Instance Methods | [hide private]
__init__(self, actions, extensions, options, peers, managed, local) Constructor for the `_ActionSet` class. | source code
executeActions(self, configPath, options, config) Executes all actions and extended actions, in the proper order. | source code
Inherited from `object`: `__delattr__`, `__format__`, `__getattribute__`, `__hash__`, `__new__`, `__reduce__`, `__reduce_ex__`, `__repr__`, `__setattr__`, `__sizeof__`, `__str__`, `__subclasshook__`

Static Methods | [hide private]
_deriveExtensionNames(extensions) Builds a list of extended actions that are available in configuration. | source code
_buildHookMaps(hooks) Build two mappings from action name to configured `ActionHook`. | source code
_buildFunctionMap(extensions) Builds a mapping from named action to action function. | source code
_buildIndexMap(extensions) Builds a mapping from action name to proper execution index. | source code
_buildActionMap(managed, local, extensionNames, functionMap, indexMap, preHookMap, postHookMap, peerMap) Builds a mapping from action name to list of action items. | source code
_buildPeerMap(options, peers) Build a mapping from action name to list of remote peers. | source code
_deriveHooks(action, preHookDict, postHookDict) Derive pre- and post-action hooks, if any, associated with named action. | source code
_validateActions(actions, extensionNames) Validate that the set of specified actions is sensible. | source code
_buildActionSet(actions, actionMap) Build set of actions to be executed. | source code
_getRemoteUser(options, remotePeer) Gets the remote user associated with a remote peer. | source code
_getRshCommand(options, remotePeer) Gets the RSH command associated with a remote peer. | source code
_getCbackCommand(options, remotePeer) Gets the cback command associated with a remote peer. | source code
_getManagedActions(options, remotePeer) Gets the managed actions list associated with a remote peer. | source code

Properties | [hide private]
Inherited from `object`: `__class__`

Method Details | [hide private]

### __init__(self, actions, extensions, options, peers, managed, local) (Constructor) | source code
Constructor for the `_ActionSet` class. This is kind of ugly, because the constructor has to set up a lot of data before being able to do anything useful. The following data structures are initialized based on the input: `extensionNames`: List of extensions available in configuration `preHookMap`: Mapping from action name to pre `ActionHook` `preHookMap`: Mapping from action name to post `ActionHook` `functionMap`: Mapping from action name to Python function `indexMap`: Mapping from action name to execution index `peerMap`: Mapping from action name to set of `RemotePeer` `actionMap`: Mapping from action name to `_ActionItem` Once these data structures are set up, the command line is validated to make sure only valid actions have been requested, and in a sensible combination. Then, all of the data is used to build `self.actionSet`, the set action items to be executed by `executeActions()`. This list might contain either `_ActionItem` or `_ManagedActionItem`. Parameters: `actions` - Names of actions specified on the command-line. `extensions` - Extended action configuration (i.e. config.extensions) `options` - Options configuration (i.e. config.options) `peers` - Peers configuration (i.e. config.peers) `managed` - Whether to include managed actions in the set `local` - Whether to include local actions in the set Raises: `ValueError` - If one of the specified actions is invalid. Overrides: object.__init__

### executeActions(self, configPath, options, config) | source code
Executes all actions and extended actions, in the proper order. Each action (whether built-in or extension) is executed in an identical manner. The built-in actions will use only the options and config values. We also pass in the config path so that extension modules can re-parse configuration if they want to, to add in extra information. Parameters: `configPath` - Path to configuration file on disk. `options` - Command-line options to be passed to action functions. `config` - Parsed configuration to be passed to action functions. Raises: `Exception` - If there is a problem executing the actions.

### _deriveExtensionNames(extensions) Static Method | source code
Builds a list of extended actions that are available in configuration. Parameters: `extensions` - Extended action configuration (i.e. config.extensions) Returns: List of extended action names.

### _buildHookMaps(hooks) Static Method | source code
Build two mappings from action name to configured `ActionHook`. Parameters: `hooks` - List of pre- and post-action hooks (i.e. config.options.hooks) Returns: Tuple of (pre hook dictionary, post hook dictionary).

### _buildFunctionMap(extensions) Static Method | source code
Builds a mapping from named action to action function. Parameters: `extensions` - Extended action configuration (i.e. config.extensions) Returns: Dictionary mapping action to function.

### _buildIndexMap(extensions) Static Method | source code
Builds a mapping from action name to proper execution index. If extensions configuration is `None`, or there are no configured extended actions, the ordering dictionary will only include the built-in actions and their standard indices. Otherwise, if the extensions order mode is `None` or `"index"`, actions will scheduled by explicit index; and if the extensions order mode is `"dependency"`, actions will be scheduled using a dependency graph. Parameters: `extensions` - Extended action configuration (i.e. config.extensions) Returns: Dictionary mapping action name to integer execution index.

### _buildActionMap(managed, local, extensionNames, functionMap, indexMap, preHookMap, postHookMap, peerMap) Static Method | source code
Builds a mapping from action name to list of action items. We build either `_ActionItem` or `_ManagedActionItem` objects here. In most cases, the mapping from action name to `_ActionItem` is 1:1. The exception is the "all" action, which is a special case. However, a list is returned in all cases, just for consistency later. Each `_ActionItem` will be created with a proper function reference and index value for execution ordering. The mapping from action name to `_ManagedActionItem` is always 1:1. Each managed action item contains a list of peers which the action should be executed. Parameters: `managed` - Whether to include managed actions in the set `local` - Whether to include local actions in the set `extensionNames` - List of valid extended action names `functionMap` - Dictionary mapping action name to Python function `indexMap` - Dictionary mapping action name to integer execution index `preHookMap` - Dictionary mapping action name to pre hooks (if any) for the action `postHookMap` - Dictionary mapping action name to post hooks (if any) for the action `peerMap` - Dictionary mapping action name to list of remote peers on which to execute the action Returns: Dictionary mapping action name to list of `_ActionItem` objects.

### _buildPeerMap(options, peers) Static Method | source code
Build a mapping from action name to list of remote peers. There will be one entry in the mapping for each managed action. If there are no managed peers, the mapping will be empty. Only managed actions will be listed in the mapping. Parameters: `options` - Option configuration (i.e. config.options) `peers` - Peers configuration (i.e. config.peers)

### _deriveHooks(action, preHookDict, postHookDict) Static Method | source code
Derive pre- and post-action hooks, if any, associated with named action. Parameters: `action` - Name of action to look up `preHookDict` - Dictionary mapping pre-action hooks to action name `postHookDict` - Dictionary mapping post-action hooks to action name @return Tuple (preHook, postHook) per mapping, with None values if there is no hook.

### _validateActions(actions, extensionNames) Static Method | source code
Validate that the set of specified actions is sensible. Any specified action must either be a built-in action or must be among the extended actions defined in configuration. The actions from within NONCOMBINE_ACTIONS may not be combined with other actions. Parameters: `actions` - Names of actions specified on the command-line. `extensionNames` - Names of extensions specified in configuration. Raises: `ValueError` - If one or more configured actions are not valid.

### _buildActionSet(actions, actionMap) Static Method | source code
Build set of actions to be executed. The set of actions is built in the proper order, so `executeActions` can spin through the set without thinking about it. Since we've already validated that the set of actions is sensible, we don't take any precautions here to make sure things are combined properly. If the action is listed, it will be "scheduled" for execution. Parameters: `actions` - Names of actions specified on the command-line. `actionMap` - Dictionary mapping action name to `_ActionItem` object. Returns: Set of action items in proper order.

### _getRemoteUser(options, remotePeer) Static Method | source code
Gets the remote user associated with a remote peer. Use peer's if possible, otherwise take from options section. Parameters: `options` - OptionsConfig object, as from config.options `remotePeer` - Configuration-style remote peer object. Returns: Name of remote user associated with remote peer.

### _getRshCommand(options, remotePeer) Static Method | source code
Gets the RSH command associated with a remote peer. Use peer's if possible, otherwise take from options section. Parameters: `options` - OptionsConfig object, as from config.options `remotePeer` - Configuration-style remote peer object. Returns: RSH command associated with remote peer.

### _getCbackCommand(options, remotePeer) Static Method | source code
Gets the cback command associated with a remote peer. Use peer's if possible, otherwise take from options section. Parameters: `options` - OptionsConfig object, as from config.options `remotePeer` - Configuration-style remote peer object. Returns: cback command associated with remote peer.

### _getManagedActions(options, remotePeer) Static Method | source code
Gets the managed actions list associated with a remote peer. Use peer's if possible, otherwise take from options section. Parameters: `options` - OptionsConfig object, as from config.options `remotePeer` - Configuration-style remote peer object. Returns: Set of managed actions associated with remote peer.