Backends¶
Abstract backend.
-
class
cumin.backends.
BaseQuery
(config)[source]¶ Bases:
object
abstract
Query abstract class.All backends query classes must inherit, directly or indirectly, from this one.
-
__init__
(config)[source]¶ Query constructor.
Parameters: config (dict) -- a dictionary with the parsed configuration file.
-
_build
(query_string)[source]¶ Parse the query string according to the grammar and build the query for later execution.
Parameters: query_string (str) -- the query string to be parsed.
-
_execute
()[source]¶ abstract
Execute the already parsed query and return the NodeSet of FQDN hostnames that matches.Returns: with the FQDNs of the matching hosts. Return type: ClusterShell.NodeSet.NodeSet
-
_parse_token
(token)[source]¶ abstract
Recursively interpret the tokens returned by the grammar parsing.Parameters: token (pyparsing.ParseResults) -- a single token returned by the grammar parsing.
-
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: ClusterShell.NodeSet.NodeSet
-
grammar
= NoMatch¶ pyparsing.ParserElement
-- derived classes must define their own pyparsing grammar and set this class attribute accordingly.
-
-
class
cumin.backends.
BaseQueryAggregator
(config)[source]¶ Bases:
cumin.backends.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.-
__init__
(config)[source]¶ Query aggregator constructor, initialize the stack.
Parameters: according to parent cumin.backends.BaseQuery.__init__()
.
-
_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 the bool_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.
- hosts (ClusterShell.NodeSet.NodeSet) -- the hosts to update with the results in
-
_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()
.
-
static
_get_stack_element
()[source]¶ Return an empty stack element.
Returns: the dictionary with an empty stack element. Return type: dict
-
_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.
-
_parse_token
(token)[source]¶ abstract
Re-define abstract method from parent abstract class.Parameters: according to parent cumin.backends.BaseQuery._parse_token()
.
-
execute
(query_string)¶ inherited
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: ClusterShell.NodeSet.NodeSet
-
-
exception
cumin.backends.
InvalidQueryError
[source]¶ Bases:
cumin.CuminError
Custom exception class for invalid queries.
Available backends