OpenStack

OpenStack backend.

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

str

class cumin.backends.openstack.OpenStackQuery(config)[source]

Bases: cumin.backends.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 and vm_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 the project 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}

__init__(config)[source]

Override parent class constructor for specific setup.

Parameters

according to parent cumin.backends.BaseQuery.__init__().

_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

ClusterShell.NodeSet.NodeSet

_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

dict

_get_project_hosts(project)[source]

Return a NodeSet with the list of matching hosts based for the project based on the search parameters.

Parameters

project (str) -- the project name where to get the list of hosts.

Returns

with the FQDNs of the matching hosts.

Return type

ClusterShell.NodeSet.NodeSet

_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.

_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.

execute(query_string)

static 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

grammar = {Group:("*") | {Group:(Combine:({{W:(abcd...) ":"} {quotedString using single or double quotes | W:(0123...)}}))}...}

load the grammar parser only once in a singleton-like way.

Type

pyparsing.ParserElement

cumin.backends.openstack._get_keystone_session(config, project=None)[source]

Return a new keystone session based on configuration.

Parameters
  • config (dict) -- a dictionary with the session configuration keys: auth_url, username, password.

  • project (str, optional) -- a project to scope the session to.

Returns

the Keystone session scoped for the project if specified.

Return type

keystoneauth1.session.Session

cumin.backends.openstack._get_nova_client(config, project)[source]

Return a new nova client tailored to the given project.

Parameters
  • config (dict) -- a dictionary with the session configuration keys: auth_url, username, password, nova_api_version, timeout.

  • project (str) -- the project to scope the novaclient session to.

Returns

the novaclient Client instance, already authenticated.

Return type

novaclient.client.Client

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

pyparsing.ParserElement

cumin.backends.openstack.query_class

Required by the backend auto-loader in cumin.grammar.get_registered_backends().

alias of cumin.backends.openstack.OpenStackQuery