OpenStack¶
OpenStack backend.
- cumin.backends.openstack.grammar()[source]¶
Define the query grammar.
Backus-Naur form (BNF) of the grammar:
<grammar> ::= "*" | <items> <items> ::= <item> | <item> <whitespace> <items> <item> ::= <key>:<value>
Given that the pyparsing library defines the grammar in a BNF-like style, for the details of the tokens not specified above check directly the source code.
- Returns:
the grammar parser.
- Return type:
- cumin.backends.openstack._get_keystone_session(config, project=None)[source]¶
Return a new keystone session based on configuration.
- cumin.backends.openstack._get_nova_client(config, project)[source]¶
Return a new nova client tailored to the given project.
- Parameters:
- Returns:
the novaclient Client instance, already authenticated.
- Return type:
novaclient.client.Client
- class cumin.backends.openstack.OpenStackQuery(config)[source]¶
Bases:
BaseQuery
OpenStackQuery query builder.
Query VMs deployed in an OpenStack infrastructure using the API. This is an optional backend, its dependencies will not be installed automatically, see the Installation section of the documentation for more details.
Each query can specify multiple parameters to filter the hosts selection in the form
key:value
.The special
project
key allow to filter by the OpenStack project name:project:project_name
. If not specified all the visible and enabled projects will be queried.Any other
key:value
pair will be passed as is to the OpenStack Compute API list-servers. Multiple filters can be added separated by space. The value can be enclosed in single or double quotes:name:"host1.*\.domain" image:UUID
By default the filters
status:ACTIVE
andvm_state:ACTIVE
are also added, but will be overridden if specified in the query.To mix multiple selections the general grammar must be used with multiple subqueries:
O{project:project1} or O{project:project2}
The special query
*
is a shortcut to select all hosts in all OpenStack projects.See the example configuration in
doc/examples/config.yaml
for all the OpenStack-related parameters that can be set.
Some query examples:
All hosts in all OpenStack projects:
*
All hosts in a specific OpenStack project:
project:project_name
Filter hosts using any parameter allowed by the OpenStack list-servers API:
name:host1 image:UUID
See OpenStack Compute API list-servers for more details. Multiple filters can be added separated by space. The value can be enclosed in single or double quotes. If theproject
key is not specified the hosts will be selected from all projects.To mix multiple selections the general grammar must be used with multiple subqueries:
O{project:project1} or O{project:project2}
Override parent class constructor for specific setup.
- Parameters:
according to parent
cumin.backends.BaseQuery.__init__()
.
- grammar = {Group:('*') | {Group:(Combine:({W:(-.0-9_a-z){2,...} ':'} {quoted string using single or double quotes | W:(!-'*-z|~)}))}...}¶
load the grammar parser only once in a singleton-like way.
- Type:
- _get_default_search_params()[source]¶
Return the default search parameters dictionary and set the project, if configured.
- Returns:
the dictionary with the default search parameters.
- Return type:
- _build(query_string)[source]¶
Override parent class _build method to reset the search parameters.
- Parameters:
according to parent
cumin.backends.BaseQuery._build()
.
- _execute()[source]¶
Concrete implementation of parent abstract method.
- Parameters:
according to parent
cumin.backends.BaseQuery._execute()
.- Returns:
with the FQDNs of the matching hosts.
- Return type:
- _parse_token(token)[source]¶
Concrete implementation of parent abstract method.
- Parameters:
according to parent
cumin.backends.BaseQuery._parse_token()
.- Raises:
cumin.backends.InvalidQueryError -- on internal parsing error.
- _get_projects()[source]¶
Get all the project names from keystone API, filtering out the special admin project. Is a generator.
- Yields:
str -- the project name for all the selected projects.
- cumin.backends.openstack.GRAMMAR_PREFIX = 'O'¶
the prefix associate to this grammar, to register this backend into the general grammar. Required by the backend auto-loader in
cumin.grammar.get_registered_backends()
.- Type:
- cumin.backends.openstack.query_class¶
Required by the backend auto-loader in
cumin.grammar.get_registered_backends()
.