runway.cfngin.plan module¶
CFNgin plan, plan components, and functions for interacting with a plan.
- class runway.cfngin.plan.Graph[source]¶
Bases:
object
Graph represents a graph of steps.
The
Graph
helps organize the steps needed to execute a particular action for a set ofrunway.cfngin.stack.Stack
objects. When initialized with a set of steps, it will first build a Directed Acyclic Graph from the steps and their dependencies.Example
>>> dag = DAG() >>> a = Step("a", fn=deploy) >>> b = Step("b", fn=deploy) >>> dag.add_step(a) >>> dag.add_step(b) >>> dag.connect(a, b)
- __init__(steps: dict[str, Step] | None = None, dag: DAG | None = None) None [source]¶
Instantiate class.
- Parameters:
steps – Dict with key of step name and value of
Step
for steps to initialize the Graph with. Note that if this is provided, a pre-configuredrunway.cfngin.dag.DAG
that already includes these steps should also be provided..dag – An optional
runway.cfngin.dag.DAG
object. If one is not provided, a new one will be initialized.
- add_step(step: Step, add_dependencies: bool = False, add_dependents: bool = False) None [source]¶
Add a step to the graph.
- Parameters:
step – The step to be added.
add_dependencies – Connect steps that need to be completed before this step.
add_dependents – Connect steps that require this step.
- add_step_if_not_exists(step: Step, add_dependencies: bool = False, add_dependents: bool = False) None [source]¶
Try to add a step to the graph.
Can be used when failure to add is acceptable.
- Parameters:
step – The step to be added.
add_dependencies – Connect steps that need to be completed before this step.
add_dependents – Connect steps that require this step.
- add_steps(steps: list[Step]) None [source]¶
Add a list of steps.
- Parameters:
steps – The step to be added.
- connect(step: str, dep: str) None [source]¶
Connect a dependency to a step.
- Parameters:
step – Step name to add a dependency to.
dep – Name of dependent step.
- dumps(indent: int | None = None) str [source]¶
Output the graph as a json serialized string for storage.
- Parameters:
indent – Number of spaces for each indentation.
- filtered(step_names: list[str]) Graph [source]¶
Return a “filtered” version of this graph.
- Parameters:
step_names – Steps to filter.
- classmethod from_dict(graph_dict: dict[str, list[str]] | dict[str, set[str]] | OrderedDict[str, set[str]], context: CfnginContext) Graph [source]¶
Create a Graph from a graph dict.
- Parameters:
graph_dict – The dictionary used to create the graph.
context – Required to init stacks.
- classmethod from_steps(steps: list[Step]) Graph [source]¶
Create a Graph from Steps.
- Parameters:
steps – Steps used to create the graph.
- pop(step: Step, default: Any = None) Any [source]¶
Remove a step from the graph.
- Parameters:
step – The step to remove from the graph.
default – Returned if the step could not be popped
- transitive_reduction() None [source]¶
Perform a transitive reduction on the underlying DAG.
The transitive reduction of a graph is a graph with as few edges as possible with the same reachability as the original graph.
- class runway.cfngin.plan.Plan[source]¶
Bases:
object
A convenience class for working on a Graph.
- context¶
Context object.
- Type:
CfnginContext | None
- __init__(description: str, graph: Graph, context: CfnginContext | None = None, reverse: bool = False, require_unlocked: bool = True) None [source]¶
Initialize class.
- Parameters:
description – Description of what the plan is going to do.
graph – Local graph used for the plan.
context – Context object.
reverse – Transpose the graph for walking in reverse.
require_unlocked – Require the persistent graph to be unlocked before executing steps.
- dump(*, directory: str, context: CfnginContext, provider: Provider | None = None) Any [source]¶
Output the rendered blueprint for all stacks in the plan.
- Parameters:
directory – Directory where files will be created.
context – Current CFNgin context.
provider – Provider to use when resolving the blueprints.
- execute(*args: Any, **kwargs: Any) None [source]¶
Walk each step in the underlying graph.
- Raises:
PersistentGraphLocked – Raised if the persistent graph is locked prior to execution and this session did not lock it.
PlanFailed – Raised if any of the steps fail.
- outline(level: int = 20, message: str = '') None [source]¶
Print an outline of the actions the plan is going to take.
The outline will represent the rough ordering of the steps that will be taken.
- Parameters:
level – a valid log level that should be used to log the outline
message – a message that will be logged to the user after the outline has been logged.
- class runway.cfngin.plan.Step[source]¶
Bases:
object
State machine for executing generic actions related to stacks.
- fn¶
Function to run to execute the step. This function will be ran multiple times until the step is “done”.
- Type:
Callable[…, Any] | None
- logger¶
Logger for logging messages about the step.
- Type:
PrefixAdaptor
- watch_func¶
Function that will be called to “tail” the step action.
- Type:
Callable[…, Any] | None
- __init__(stack: Stack, *, fn: Callable[[...], Any] | None = None, watch_func: Callable[[...], Any] | None = None) None [source]¶
Instantiate class.
- Parameters:
stack – The stack associated with this step
fn – Function to run to execute the step. This function will be ran multiple times until the step is “done”.
watch_func – Function that will be called to “tail” the step action.
- property done: bool¶
Return True if the step is finished.
To be
True
, status must be either COMPLETE, SKIPPED or FAILED)
- classmethod from_persistent_graph(graph_dict: dict[str, list[str]] | dict[str, set[str]] | OrderedDict[str, set[str]], context: CfnginContext, fn: Callable[..., Status] | None = None, watch_func: Callable[..., Any] | None = None) list[Step] [source]¶
Create a steps for a persistent graph dict.
- Parameters:
graph_dict – A graph dict.
context – Context object. Required to initialize a “fake”
runway.cfngin.stack.Stack
.requires – Stacks that this stack depends on.
fn – The function to run to execute the step. This function will be ran multiple times until the step is “done”.
watch_func – an optional function that will be called to “tail” the step action.
- classmethod from_stack_name(stack_name: str, context: CfnginContext, requires: list[str] | set[str] | None = None, fn: Callable[..., Status] | None = None, watch_func: Callable[..., Any] | None = None) Step [source]¶
Create a step using only a stack name.
- Parameters:
stack_name – Name of a CloudFormation stack.
context – Context object. Required to initialize a “fake”
runway.cfngin.stack.Stack
.requires – Stacks that this stack depends on.
fn – The function to run to execute the step. This function will be ran multiple times until the step is “done”.
watch_func – an optional function that will be called to “tail” the step action.