Backends¶
Abstract backend.
- exception cumin.backends.InvalidQueryError[source]¶
Bases:
CuminError
Custom exception class for invalid queries.
- class cumin.backends.BaseQuery(config)[source]¶
Bases:
object
abstract
Query 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:
BaseQuery
abstract
Query aggregator abstract class.Add to
cumin.backends.BaseQuery
the capability of aggregating query subgroups and sub tokens into a unified result using common boolean operators for sets:and
,or
,and not
andxor
. 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_hosts
according 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
None
when adding the first hosts.
Available backends
- Direct
- KnownHosts
- OpenStack
- PuppetDB
CATEGORIES
OPERATORS
ParsedString
grammar()
PuppetDBQuery
PuppetDBQuery.base_url_template
PuppetDBQuery.endpoints
PuppetDBQuery.category_prefixes
PuppetDBQuery.grammar
PuppetDBQuery.endpoint
PuppetDBQuery._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_PREFIX
query_class