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()
-
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.
-
-
class
deployer.inspection.inspector.NodeIterator(node_iterator_func)¶ Generator object which yields the nodes in a collection.
-
call_action(name, *a, **kw)¶ Call a certain action on all the nodes.
-
filter(filter)¶ Apply filter on this node iterator, and return a new iterator instead. filter should be a Filter instance.
-
prefer_isolation(index)¶ For nodes that are not yet isoleted. (SimpleNodes, or normal Nodes nested in there.) yield the isolations with this index. Otherwise, nodes are yielded unmodified.
-
-
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.
-
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.