The inspection module contains a set of utilities for introspection of the deployment tree. This can be either from inside an action, or externally to reflect on a given tree.
Suppose that we already have the following node instantiated:
from deployer.node import Node class Setup(Node): def say_hello(self): self.hosts.run('echo "Hello world"') setup = Setup()
Now we can ask for the list of actions that this node has:
from deployer.inspection import Inspector insp = Inspector(setup) print insp.get_actions() print insp.get_childnodes()
- Suppose that you have a huge deployment tree, covering dozens of projects, each having both a staging and production set-up, and all of them are doing a git checkout. Now you want to list all the current checkouts of all the repositories on all your machines. This is easy by traversing the nodes, filtering on the type gitnode and calling git show in there.
- Suppose you have an nginx node, which generates the configuration according to the childnodes in there. One childnode could for instance define a back-end, another one could define the location of static files, etc... By using this inspection module, you cat find the childnodes that contain a configuration section and combine these.
- Internally, the whole interactive shell is also using quite a lot of reflection.
Reflexion/introspection on a deployer.node.Node
Types for displaying the
Nodeaddress in a tree. It’s an options for Inspector.get_path()
A list of names.
A list of
A list of nodes.
Introspection of a
Actionwith this name or raise
Return a list of
Actioninstances for the actions in this node.
Parameters: include_private (bool) – Include actions starting with an underscore.
Return the childnode with this name or raise
Return a list of childnodes.
- include_private (bool) – ignore names starting with underscore.
- verify_parent (bool) – check that the parent matches the current node.
Return the name of this node.
Note: when a node is nested in a parent node, the name becomes the attribute name of this node in the parent.
Return the parent
Return a (name1, name2, ...) tuple, defining the path from the root until here.
Parameters: path_type (
PathType) – Path formatting.
Return the attributes that are properties.
This are the members of this node that were wrapped in
@property:returns: A list of
Returns the property with this name or raise AttributeError. :returns:
Return the attributes that are
Returns the Action object that wraps the Query with this name or raise AttributeError.
Return the root
Nodeof the tree.
Truewhen this node has an action called
Truewhen this node has a childnode called
Truewhen the attribute
nameis a @property.
Truewhen the attribute
nameof this node is a Query.
Truewhen this node implements
deployer.node.suppress_action_result()has been applied to this action.
Filters for NodeIterator¶
NodeIterator is the iterator that
Inspector.walk() returns. It supports
filtering to limit the yielded nodes according to certain conditions.
A filter is a
Filter instance or an AND or OR operation of several
filters. For instance:
from deployer.inspection.filters import HasAction, PublicOnly Inspector(node).walk(HasAction('my_action') & PublicOnly & ~ InGroup(Staging))
Base class for
Filter on public nodes.
Filter on private nodes.
Filter on the nodes which are an instance of this
Parameters: node_class – A
Filter on the nodes which implement this action.