operations.api
Provides API to define operations.
class api.OperationError
api.OperationError
An exception that indicates an error while executing an operation.
class api.OperationResult
api.OperationResult
Stores the result of an operation.
Attributes
attr success
success
Whether the operation succeeded.
attr changed
changed
Whether the operation changed something.
attr initial
initial
The initial state of the host.
attr final
final
The final state of the host.
attr failure_message
failure_message
The failure message, if success is False.
class api.Operation
api.Operation
This class is used to ease the building of operations with consistent output and state tracking.
Attributes
attr internal_use_only
internal_use_only
operation's op variable is defaulted to this value to indicate that it must not be given by the user.
def Operation.nested()
Operation.nested()
Sets whet this operation spawns nested operations. In this case, this operation will not have separate state, and the printing will be handled differently.
Parameters
has_nested: Whether the operation has nested operations.
def Operation.add_nested_result()
Operation.add_nested_result()
Adds initial and final state of a nested operation under the given key into this operation's state dictionaries.
Parameters
key: The key under which to add the nested result.
result: The result to add.
def Operation.desc()
Operation.desc()
Sets the description of the operation, and prints an early status via the logger.
Parameters
description: The new description.
def Operation.defaults()
Operation.defaults()
Sets defaults on the current script. See ScriptWrapper.defaults()
.
def Operation.initial_state()
Operation.initial_state()
Sets the initial state.
def Operation.final_state()
Operation.final_state()
Sets the final state.
def Operation.unchanged()
Operation.unchanged()
Checks whether the initial and final states differ.
Parameters
ignore_none: Set to
True
to not count states where the final value is None.
Returns
bool: Whether the states differ.
def Operation.changed()
Operation.changed()
Checks whether a specific key will change.
Parameters
key: The key to check for changes.
Returns
bool: Whether the states differ.
def Operation.diff()
Operation.diff()
Adds a file to the diffing output.
Parameters
file: The filename which the diff belongs to.
old: The previous content or None if the file didn't exist previously.
new: The new content or None if the file was deleted.
def Operation.failure()
Operation.failure()
Returns a failed operation result.
Returns
OperationResult: The OperationResult for this failed operation.
def Operation.success()
Operation.success()
Returns a successful operation result.
Returns
OperationResult: The OperationResult for this successful operation.
Functions
def api.operation()
api.operation()
Operation function decorator.
Last updated