charmhelpers.contrib.openstack package

charmhelpers.contrib.openstack.alternatives module

Helper for managing alternatives for file conflict resolution

charmhelpers.contrib.openstack.alternatives.install_alternative(name, target, source, priority=50)

Install alternative configuration

charmhelpers.contrib.openstack.context module

class charmhelpers.contrib.openstack.context.AMQPContext(ssl_dir=None, rel_name='amqp', relation_prefix=None)

Bases: charmhelpers.contrib.openstack.context.OSContextGenerator

class charmhelpers.contrib.openstack.context.ApacheSSLContext

Bases: charmhelpers.contrib.openstack.context.OSContextGenerator

Generates a context for an apache vhost configuration that configures HTTPS reverse proxying for one or many endpoints. Generated context looks something like:

{
    'namespace': 'cinder',
    'private_address': 'iscsi.mycinderhost.com',
    'endpoints': [(8776, 8766), (8777, 8767)]
}

The endpoints list consists of a tuples mapping external ports to internal ports.

canonical_names()

Figure out which canonical names clients will access this service.

configure_ca()
configure_cert(cn=None)
enable_modules()
external_ports = []
get_network_addresses()
For each network configured, return corresponding address and vip
(if available).

Returns a list of tuples of the form:

[(address_in_net_a, vip_in_net_a),
(address_in_net_b, vip_in_net_b), ...]

or, if no vip(s) available:

[(address_in_net_a, address_in_net_a),
(address_in_net_b, address_in_net_b), ...]
interfaces = ['https']
service_namespace = None
class charmhelpers.contrib.openstack.context.BindHostContext

Bases: charmhelpers.contrib.openstack.context.OSContextGenerator

class charmhelpers.contrib.openstack.context.CephContext

Bases: charmhelpers.contrib.openstack.context.OSContextGenerator

Generates context for /etc/ceph/ceph.conf templates.

interfaces = ['ceph']
class charmhelpers.contrib.openstack.context.DataPortContext

Bases: charmhelpers.contrib.openstack.context.NeutronPortContext

class charmhelpers.contrib.openstack.context.ExternalPortContext

Bases: charmhelpers.contrib.openstack.context.NeutronPortContext

class charmhelpers.contrib.openstack.context.HAProxyContext(singlenode_mode=False)

Bases: charmhelpers.contrib.openstack.context.OSContextGenerator

Provides half a context for the haproxy template, which describes all peers to be included in the cluster. Each charm needs to include its own context generator that describes the port mapping.

interfaces = ['cluster']
class charmhelpers.contrib.openstack.context.IdentityServiceContext(service=None, service_user=None, rel_name='identity-service')

Bases: charmhelpers.contrib.openstack.context.OSContextGenerator

class charmhelpers.contrib.openstack.context.ImageServiceContext

Bases: charmhelpers.contrib.openstack.context.OSContextGenerator

interfaces = ['image-service']
class charmhelpers.contrib.openstack.context.LogLevelContext

Bases: charmhelpers.contrib.openstack.context.OSContextGenerator

class charmhelpers.contrib.openstack.context.NetworkServiceContext(rel_name='quantum-network-service')

Bases: charmhelpers.contrib.openstack.context.OSContextGenerator

class charmhelpers.contrib.openstack.context.NeutronAPIContext

Bases: charmhelpers.contrib.openstack.context.OSContextGenerator

Inspects current neutron-plugin-api relation for neutron settings. Return defaults if it is not present.

get_neutron_options(rdata)
interfaces = ['neutron-plugin-api']
class charmhelpers.contrib.openstack.context.NeutronContext

Bases: charmhelpers.contrib.openstack.context.OSContextGenerator

calico_ctxt()
interfaces = []
n1kv_ctxt()
network_manager
neutron_ctxt()
neutron_security_groups
nuage_ctxt()
nvp_ctxt()
ovs_ctxt()
packages
plugin
class charmhelpers.contrib.openstack.context.NeutronPortContext

Bases: charmhelpers.contrib.openstack.context.OSContextGenerator

NIC_PREFIXES = ['eth', 'bond']
resolve_ports(ports)

Resolve NICs not yet bound to bridge(s)

If hwaddress provided then returns resolved hwaddress otherwise NIC.

class charmhelpers.contrib.openstack.context.NotificationDriverContext(zmq_relation='zeromq-configuration', amqp_relation='amqp')

Bases: charmhelpers.contrib.openstack.context.OSContextGenerator

class charmhelpers.contrib.openstack.context.OSConfigFlagContext(charm_flag='config-flags', template_flag='user_config_flags')

Bases: charmhelpers.contrib.openstack.context.OSContextGenerator

Provides support for user-defined config flags.

Users can define a comma-seperated list of key=value pairs in the charm configuration and apply them at any point in any file by using a template flag.

Sometimes users might want config flags inserted within a specific section so this class allows users to specify the template flag name, allowing for multiple template flags (sections) within the same context.

NOTE: the value of config-flags may be a comma-separated list of
key=value pairs and some Openstack config files support comma-separated lists as values.
exception charmhelpers.contrib.openstack.context.OSContextError

Bases: exceptions.Exception

class charmhelpers.contrib.openstack.context.OSContextGenerator

Bases: object

Base class for all context generators.

interfaces = []
class charmhelpers.contrib.openstack.context.PhyNICMTUContext

Bases: charmhelpers.contrib.openstack.context.DataPortContext

class charmhelpers.contrib.openstack.context.PostgresqlDBContext(database=None)

Bases: charmhelpers.contrib.openstack.context.OSContextGenerator

interfaces = ['pgsql-db']
class charmhelpers.contrib.openstack.context.SharedDBContext(database=None, user=None, relation_prefix=None, ssl_dir=None)

Bases: charmhelpers.contrib.openstack.context.OSContextGenerator

interfaces = ['shared-db']
class charmhelpers.contrib.openstack.context.SubordinateConfigContext(service, config_file, interface)

Bases: charmhelpers.contrib.openstack.context.OSContextGenerator

Responsible for inspecting relations to subordinates that may be exporting required config via a json blob.

The subordinate interface allows subordinates to export their configuration requirements to the principle for multiple config files and multiple serivces. Ie, a subordinate that has interfaces to both glance and nova may export to following yaml blob as json:

glance:
    /etc/glance/glance-api.conf:
        sections:
            DEFAULT:
                - [key1, value1]
    /etc/glance/glance-registry.conf:
            MYSECTION:
                - [key2, value2]
nova:
    /etc/nova/nova.conf:
        sections:
            DEFAULT:
                - [key3, value3]

It is then up to the principle charms to subscribe this context to the service+config file it is interestd in. Configuration data will be available in the template context, in glance’s case, as:

ctxt = {
    ... other context ...
    'subordinate_config': {
        'DEFAULT': {
            'key1': 'value1',
        },
        'MYSECTION': {
            'key2': 'value2',
        },
    }
}
class charmhelpers.contrib.openstack.context.SysctlContext

Bases: charmhelpers.contrib.openstack.context.OSContextGenerator

This context check if the ‘sysctl’ option exists on configuration then creates a file with the loaded contents

class charmhelpers.contrib.openstack.context.SyslogContext

Bases: charmhelpers.contrib.openstack.context.OSContextGenerator

class charmhelpers.contrib.openstack.context.WorkerConfigContext

Bases: charmhelpers.contrib.openstack.context.OSContextGenerator

num_cpus
class charmhelpers.contrib.openstack.context.ZeroMQContext

Bases: charmhelpers.contrib.openstack.context.OSContextGenerator

interfaces = ['zeromq-configuration']
charmhelpers.contrib.openstack.context.config_flags_parser(config_flags)

Parses config flags string into dict.

This parsing method supports a few different formats for the config flag values to be parsed:

  1. A string in the simple format of key=value pairs, with the possibility of specifying multiple key value pairs within the same string. For example, a string in the format of ‘key1=value1, key2=value2’ will return a dict of:

    {‘key1’: ‘value1’,

    ‘key2’: ‘value2’}.

  2. A string in the above format, but supporting a comma-delimited list of values for the same key. For example, a string in the format of ‘key1=value1, key2=value3,value4,value5’ will return a dict of:

    {‘key1’, ‘value1’,

    ‘key2’, ‘value2,value3,value4’}

  3. A string containing a colon character (:) prior to an equal character (=) will be treated as yaml and parsed as such. This can be used to specify more complex key value pairs. For example, a string in the format of ‘key1: subkey1=value1, subkey2=value2’ will return a dict of:

    {‘key1’, ‘subkey1=value1, subkey2=value2’}

The provided config_flags string may be a list of comma-separated values which themselves may be comma-separated list of values.

charmhelpers.contrib.openstack.context.context_complete(ctxt)
charmhelpers.contrib.openstack.context.db_ssl(rdata, ctxt, ssl_dir)
charmhelpers.contrib.openstack.context.ensure_packages(packages)

Install but do not upgrade required plugin packages.

charmhelpers.contrib.openstack.neutron module

charmhelpers.contrib.openstack.neutron.determine_dkms_package()

Determine which DKMS package should be used based on kernel version

charmhelpers.contrib.openstack.neutron.headers_package()

Ensures correct linux-headers for running kernel are installed, for building DKMS package

charmhelpers.contrib.openstack.neutron.kernel_version()

Retrieve the current major kernel version as a tuple e.g. (3, 13)

charmhelpers.contrib.openstack.neutron.network_manager()

Deals with the renaming of Quantum to Neutron in H and any situations that require compatability (eg, deploying H with network-manager=quantum, upgrading from G).

charmhelpers.contrib.openstack.neutron.neutron_plugin_attribute(plugin, attr, net_manager=None)
charmhelpers.contrib.openstack.neutron.neutron_plugins()
charmhelpers.contrib.openstack.neutron.parse_bridge_mappings(mappings)

Parse bridge mappings.

Mappings must be a space-delimited list of provider:bridge mappings.

Returns dict of the form {provider:bridge}.

charmhelpers.contrib.openstack.neutron.parse_data_port_mappings(mappings, default_bridge='br-data')

Parse data port mappings.

Mappings must be a space-delimited list of bridge:port mappings.

Returns dict of the form {bridge:port}.

charmhelpers.contrib.openstack.neutron.parse_mappings(mappings)
charmhelpers.contrib.openstack.neutron.parse_vlan_range_mappings(mappings)

Parse vlan range mappings.

Mappings must be a space-delimited list of provider:start:end mappings.

The start:end range is optional and may be omitted.

Returns dict of the form {provider: (start, end)}.

charmhelpers.contrib.openstack.neutron.quantum_plugins()

charmhelpers.contrib.openstack.templating module

exception charmhelpers.contrib.openstack.templating.OSConfigException

Bases: exceptions.Exception

class charmhelpers.contrib.openstack.templating.OSConfigRenderer(templates_dir, openstack_release)

Bases: object

This class provides a common templating system to be used by OpenStack charms. It is intended to help charms share common code and templates, and ease the burden of managing config templates across multiple OpenStack releases.

Basic usage:

# import some common context generates from charmhelpers
from charmhelpers.contrib.openstack import context

# Create a renderer object for a specific OS release.
configs = OSConfigRenderer(templates_dir='/tmp/templates',
                           openstack_release='folsom')
# register some config files with context generators.
configs.register(config_file='/etc/nova/nova.conf',
                 contexts=[context.SharedDBContext(),
                           context.AMQPContext()])
configs.register(config_file='/etc/nova/api-paste.ini',
                 contexts=[context.IdentityServiceContext()])
configs.register(config_file='/etc/haproxy/haproxy.conf',
                 contexts=[context.HAProxyContext()])
# write out a single config
configs.write('/etc/nova/nova.conf')
# write out all registered configs
configs.write_all()

OpenStack Releases and template loading

When the object is instantiated, it is associated with a specific OS release. This dictates how the template loader will be constructed.

The constructed loader attempts to load the template from several places in the following order: - from the most recent OS release-specific template dir (if one exists) - the base templates_dir - a template directory shipped in the charm with this helper file.

For the example above, ‘/tmp/templates’ contains the following structure:

/tmp/templates/nova.conf
/tmp/templates/api-paste.ini
/tmp/templates/grizzly/api-paste.ini
/tmp/templates/havana/api-paste.ini

Since it was registered with the grizzly release, it first seraches the grizzly directory for nova.conf, then the templates dir.

When writing api-paste.ini, it will find the template in the grizzly directory.

If the object were created with folsom, it would fall back to the base templates dir for its api-paste.ini template.

This system should help manage changes in config files through openstack releases, allowing charms to fall back to the most recently updated config template for a given release

The haproxy.conf, since it is not shipped in the templates dir, will be loaded from the module directory’s template directory, eg $CHARM/hooks/charmhelpers/contrib/openstack/templates. This allows us to ship common templates (haproxy, apache) with the helpers.

Context generators

Context generators are used to generate template contexts during hook execution. Doing so may require inspecting service relations, charm config, etc. When registered, a config file is associated with a list of generators. When a template is rendered and written, all context generates are called in a chain to generate the context dictionary passed to the jinja2 template. See context.py for more info.

complete_contexts()

Returns a list of context interfaces that yield a complete context.

register(config_file, contexts)

Register a config file with a list of context generators to be called during rendering.

render(config_file)
set_release(openstack_release)

Resets the template environment and generates a new template loader based on a the new openstack release.

write(config_file)

Write a single config file, raises if config file is not registered.

write_all()

Write out all registered config files.

class charmhelpers.contrib.openstack.templating.OSConfigTemplate(config_file, contexts)

Bases: object

Associates a config file template with a list of context generators. Responsible for constructing a template context based on those generators.

complete_contexts()

Return a list of interfaces that have atisfied contexts.

context()
charmhelpers.contrib.openstack.templating.get_loader(templates_dir, os_release)

Create a jinja2.ChoiceLoader containing template dirs up to and including os_release. If directory template directory is missing at templates_dir, it will be omitted from the loader. templates_dir is added to the bottom of the search list as a base loading dir.

A charm may also ship a templates dir with this module and it will be appended to the bottom of the search list, eg:

hooks/charmhelpers/contrib/openstack/templates
Parameters:
  • (str) (os_release) – Base template directory containing release sub-directories.
  • (str) – OpenStack release codename to construct template loader.
Returns:

jinja2.ChoiceLoader constructed with a list of jinja2.FilesystemLoaders, ordered in descending order by OpenStack release.

charmhelpers.contrib.openstack.utils module

charmhelpers.contrib.openstack.utils.clean_storage(block_device)
Ensures a block device is clean. That is:
  • unmounted
  • any lvm volume groups are deactivated
  • any lvm physical device signatures removed
  • partition table wiped
Parameters:block_device – str: Full path to block device to clean.
charmhelpers.contrib.openstack.utils.config_value_changed(option)

Determine if config value changed since last call to this function.

charmhelpers.contrib.openstack.utils.configure_installation_source(rel)

Configure apt installation source.

charmhelpers.contrib.openstack.utils.ensure_block_device(block_device)

Confirm block_device, create as loopback if necessary.

Parameters:block_device – str: Full path of block device to ensure.
Returns:str: Full path of ensured block device.
charmhelpers.contrib.openstack.utils.error_out(msg)
charmhelpers.contrib.openstack.utils.get_matchmaker_map(mm_file='/etc/oslo/matchmaker_ring.json')
charmhelpers.contrib.openstack.utils.get_os_codename_install_source(src)

Derive OpenStack release codename from a given installation source.

charmhelpers.contrib.openstack.utils.get_os_codename_package(package, fatal=True)

Derive OpenStack release codename from an installed package.

charmhelpers.contrib.openstack.utils.get_os_codename_version(vers)

Determine OpenStack codename from version number.

charmhelpers.contrib.openstack.utils.get_os_version_codename(codename)

Determine OpenStack version number from codename.

charmhelpers.contrib.openstack.utils.get_os_version_install_source(src)
charmhelpers.contrib.openstack.utils.get_os_version_package(pkg, fatal=True)

Derive OpenStack version number from an installed package.

charmhelpers.contrib.openstack.utils.git_clone_and_install(projects_yaml, core_project, depth=1)

Clone/install all specified OpenStack repositories.

The expected format of projects_yaml is:

repositories:
  • {name: keystone,
    repository: ‘git://git.openstack.org/openstack/keystone.git’, branch: ‘stable/icehouse’}
  • {name: requirements,
    repository: ‘git://git.openstack.org/openstack/requirements.git’, branch: ‘stable/icehouse’}

directory: /mnt/openstack-git http_proxy: squid-proxy-url https_proxy: squid-proxy-url

The directory, http_proxy, and https_proxy keys are optional.

charmhelpers.contrib.openstack.utils.git_install_requested()

Returns true if openstack-origin-git is specified.

charmhelpers.contrib.openstack.utils.git_pip_venv_dir(projects_yaml)

Return the pip virtualenv path.

charmhelpers.contrib.openstack.utils.git_src_dir(projects_yaml, project)

Return the directory where the specified project’s source is located.

charmhelpers.contrib.openstack.utils.git_yaml_value(projects_yaml, key)

Return the value in projects_yaml for the specified key.

charmhelpers.contrib.openstack.utils.import_key(keyid)
charmhelpers.contrib.openstack.utils.openstack_upgrade_available(package)

Determines if an OpenStack upgrade is available from installation source, based on version of installed package.

Parameters:package – str: Name of installed package.
Returns:bool: : Returns True if configured installation source offers a newer version of package.
charmhelpers.contrib.openstack.utils.os_release(package, base='essex')

Returns OpenStack release codename from a cached global. If the codename can not be determined from either an installed package or the installation source, the earliest release supported by the charm should be returned.

charmhelpers.contrib.openstack.utils.os_requires_version(ostack_release, pkg)

Decorator for hook to specify minimum supported release

charmhelpers.contrib.openstack.utils.save_script_rc(script_path='scripts/scriptrc', **env_vars)

Write an rc file in the charm-delivered directory containing exported environment variables provided by env_vars. Any charm scripts run outside the juju hook environment can source this scriptrc to obtain updated config information necessary to perform health checks or service changes.

charmhelpers.contrib.openstack.utils.sync_db_with_multi_ipv6_addresses(database, database_user, relation_prefix=None)