Inspection¶
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()
Some usecases:
- 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.
Inspector¶
Reflexion/introspection on a deployer.node.Node
-
class
deployer.inspection.inspector.PathType¶ Types for displaying the
Nodeaddress in a tree. It’s an options for Inspector.get_path()-
NAME_ONLY= 'NAME_ONLY'¶ A list of names.
-
NODE_AND_NAME= 'NODE_AND_NAME'¶ A list of
(Node, name)tuples.
-
NODE_ONLY= 'NODE_ONLY'¶ A list of nodes.
-
-
class
deployer.inspection.inspector.Inspector(node)¶ Introspection of a
Nodeinstance.-
get_action(name)¶ Return the
Actionwith this name or raiseAttributeError.
-
get_actions(include_private=True)¶ Return a list of
Actioninstances for the actions in this node.Parameters: include_private (bool) – Include actions starting with an underscore.
-
get_childnode(name)¶ Return the childnode with this name or raise
AttributeError.
-
get_childnodes(include_private=True, verify_parent=True)¶ Return a list of childnodes.
Parameters: - include_private (bool) – ignore names starting with underscore.
- verify_parent (bool) – check that the parent matches the current node.
-
get_group()¶ Return the
deployer.groups.Groupto which this node belongs.
-
get_name()¶ 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.
-
get_parent()¶ Return the parent
Nodeor raiseAttributeError.
-
get_path(path_type='NAME_ONLY')¶ Return a (name1, name2, ...) tuple, defining the path from the root until here.
Parameters: path_type ( PathType) – Path formatting.
-
get_properties(include_private=True)¶ Return the attributes that are properties.
This are the members of this node that were wrapped in
@property:returns: A list ofActioninstances.
-
get_property(name)¶ Returns the property with this name or raise AttributeError. :returns:
Actioninstance.
-
get_queries(include_private=True)¶ Return the attributes that are
deployer.query.Queryinstances.
-
get_query(name)¶ Returns the Action object that wraps the Query with this name or raise AttributeError.
Returns: An Actioninstance.
-
get_root()¶ Return the root
Nodeof the tree.
-
has_action(name)¶ Returns
Truewhen this node has an action calledname.
-
has_childnode(name)¶ Returns
Truewhen this node has a childnode calledname.
-
has_property(name)¶ Returns
Truewhen the attributenameis a @property.
-
has_query(name)¶ Returns
Truewhen the attributenameof this node is a Query.
-
is_callable()¶ Return
Truewhen this node implements__call__.
-
suppress_result_for_action(name)¶ Truewhendeployer.node.suppress_action_result()has been applied to this action.
-
walk(filter=None)¶ Recursively walk (topdown) through the nodes and yield them.
It does not split
SimpleNodesnodes in several isolations.Parameters: filter – A filters.Filterinstance.Returns: A NodeIteratorinstance.
-
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))
-
class
deployer.inspection.filters.Filter¶ Base class for
Inspector.walkfilters.
-
deployer.inspection.filters.PublicOnly= PublicOnly¶ Filter on public nodes.
-
deployer.inspection.filters.PrivateOnly= PrivateOnly¶ Filter on private nodes.
-
class
deployer.inspection.filters.IsInstance(node_class)¶ Filter on the nodes which are an instance of this
Nodeclass.Parameters: node_class – A deployer.node.Nodesubclass.
-
class
deployer.inspection.filters.HasAction(action_name)¶ Filter on the nodes which implement this action.
-
class
deployer.inspection.filters.InGroup(group)¶ Filter nodes that are in this group.
Parameters: group – A deployer.groups.Groupsubclass.