Backends
Abstract backend.
- exception cumin.backends.InvalidQueryError[source]
Bases:
CuminErrorCustom exception class for invalid queries.
- class cumin.backends.BaseQuery(config)[source]
Bases:
objectabstractQuery abstract class.All backends query classes must inherit, directly or indirectly, from this one.
Query constructor.
- Parameters:
config (dict) -- a dictionary with the parsed configuration file.
- grammar = NoMatch
derived classes must define their own pyparsing grammar and set this class attribute accordingly.
- Type:
- execute(query_string)[source]
Build and execute the query, return the NodeSet of FQDN hostnames that matches.
- Parameters:
query_string (str) -- the query string to be parsed and executed.
- Returns:
with the FQDNs of the matching hosts.
- Return type:
- abstract _execute()[source]
Execute the already parsed query and return the NodeSet of FQDN hostnames that matches.
- Returns:
with the FQDNs of the matching hosts.
- Return type:
- abstract _parse_token(token)[source]
Recursively interpret the tokens returned by the grammar parsing.
- Parameters:
token (pyparsing.ParseResults) -- a single token returned by the grammar parsing.
- class cumin.backends.BaseQueryAggregator(config)[source]
Bases:
BaseQueryabstractQuery aggregator abstract class.Add to
cumin.backends.BaseQuerythe capability of aggregating query subgroups and sub tokens into a unified result using common boolean operators for sets:and,or,and notandxor. The class has a stack-like structure that must be populated by the derived classes while building the query. On execution the stack is traversed and the results are aggreagated together based on subgroups and boolean operators.Query aggregator constructor, initialize the stack.
- Parameters:
according to parent
cumin.backends.BaseQuery.__init__().
- _build(query_string)[source]
Override parent method to reset the stack and log it.
- Parameters:
according to parent
cumin.backends.BaseQuery._build().
- _execute()[source]
Concrete implementation of parent abstract method.
- Parameters:
according to parent
cumin.backends.BaseQuery._execute().
- abstract _parse_token(token)[source]
Re-define abstract method from parent abstract class.
- Parameters:
according to parent
cumin.backends.BaseQuery._parse_token().
- static _get_stack_element()[source]
Return an empty stack element.
- Returns:
the dictionary with an empty stack element.
- Return type:
- _loop_stack(hosts, stack_element)[source]
Loop the stack generated while parsing the query and aggregate the results.
- Parameters:
hosts (ClusterShell.NodeSet.NodeSet) -- the hosts to be updated with the current stack element results. This object is updated in place by reference.
stack_element (dict) -- the stack element to iterate.
- _aggregate_hosts(hosts, element_hosts, bool_operator)[source]
Aggregate hosts according to their boolean operator.
- Parameters:
hosts (ClusterShell.NodeSet.NodeSet) -- the hosts to update with the results in
element_hostsaccording to thebool_operator. This object is updated in place by reference.element_hosts (ClusterShell.NodeSet.NodeSet) -- the additional hosts to aggregate to the results based on the
bool_operator.bool_operator (str, None) -- the boolean operator to apply while aggregating the two NodeSet. It must be
Nonewhen adding the first hosts.
Available backends
- Direct
- KnownHosts
- OpenStack
- PuppetDB
CATEGORIESOPERATORSParsedStringgrammar()PuppetDBQueryPuppetDBQuery.base_url_templatePuppetDBQuery.endpointsPuppetDBQuery.category_prefixesPuppetDBQuery.grammarPuppetDBQuery.endpointPuppetDBQuery._open_subgroup()PuppetDBQuery._close_subgroup()PuppetDBQuery._get_grouped_tokens()PuppetDBQuery._build()PuppetDBQuery._execute()PuppetDBQuery._add_category()PuppetDBQuery._add_hosts()PuppetDBQuery._parse_token()PuppetDBQuery._get_resource_query()PuppetDBQuery._get_special_resource_query()PuppetDBQuery._get_query_string()PuppetDBQuery._add_bool()PuppetDBQuery._api_call()
GRAMMAR_PREFIXquery_class