Move files from charm and use new layout for charms

Plus hooks into the charm.openstack module for OpenStackCharm class.
This commit is contained in:
Alex Kavanagh 2016-05-18 15:10:21 +00:00
parent 3e4be98377
commit 80f8be29e1
10 changed files with 245 additions and 0 deletions

35
hooks/install Normal file
View File

@ -0,0 +1,35 @@
#!/bin/bash
# Wrapper to deal with newer Ubuntu versions that don't have py2 installed
# by default.
check_and_install() {
pkg="${1}"
if ! dpkg -s ${pkg} 2>&1 > /dev/null; then
apt-get -y install ${pkg}
fi
}
if [[ $(lsb_release -sc) -eq "trusty" ]]; then
juju-log "Enabling cloud archive to work around old trusty tools"
# Add a random cloud archive for the Openstack python3 clients
add-apt-repository --yes ppa:ubuntu-cloud-archive/mitaka-staging
apt-get update
check_and_install 'python3-pip'
# The trusty version of tox is too low (tox version is 1.6, required is at least 2.3.1)
# pip install tox to get around this and die a little inside
pip3 install tox
else
juju-log "Installing tox"
check_and_install 'tox'
fi
declare -a DEPS=('libssl-dev' 'libffi-dev' 'apt' 'python3-netaddr' 'python3-netifaces' 'python3-pip' 'python3-yaml' 'python-cinderclient' 'python-glanceclient' 'python-heatclient' 'python-keystoneclient' 'python-neutronclient' 'python-novaclient' 'python-swiftclient' 'python-ceilometerclient' 'openvswitch-test' 'python3-cinderclient' 'python3-glanceclient' 'python3-heatclient' 'python3-keystoneclient' 'python3-neutronclient' 'python3-novaclient' 'python3-swiftclient' 'python3-ceilometerclient')
PYTHON="python"
for dep in ${DEPS[@]}; do
check_and_install ${dep}
done
exec ./hooks/install.real

20
hooks/install.real Normal file
View File

@ -0,0 +1,20 @@
#!/usr/bin/env python3
# Load modules from $CHARM_DIR/lib
import sys
sys.path.append('lib')
from charms.layer import basic
basic.bootstrap_charm_deps()
basic.init_config_states()
# This will load and run the appropriate @hook and other decorated
# handlers from $CHARM_DIR/reactive, $CHARM_DIR/hooks/reactive,
# and $CHARM_DIR/hooks/relations.
#
# See https://jujucharms.com/docs/stable/authors-charm-building
# for more information on this pattern.
from charms.reactive import main
main()

View File

@ -0,0 +1,154 @@
# The barbican handlers class
# bare functions are provided to the reactive handlers to perform the functions
# needed on the class.
from __future__ import absolute_import
import charm.openstack.charm
import charm.openstack.adapters
import charmhelpers.fetch
PACKAGES = ['barbican-common', 'barbican-api', 'barbican-worker',
'python-mysqldb']
BARBICAN_DIR = '/etc/barbican'
BARBICAN_ADMIN_PASTE_CONF = "barbican-admin-paste.ini"
BARBICAN_API_CONF = "barbican-api.conf"
BARBICAN_API_PASTE_CONF = "barbican-api-paste.ini"
###
# Handler functions for events that are interesting to the Barbican charms
def install():
"""Use the singleton from the BarbicanCharm to install the packages on the
unit
"""
BarbicanCharm.singleton.install()
def setup_amqp_req(amqp):
"""Use the amqp interface to request access to the amqp broker using our
local configuration.
"""
amqp.request_access(username=config('rabbit-user'),
vhost=config('rabbit-vhost'))
def setup_database(database):
"""On receiving database credentials, configure the database on the
interface.
"""
database.configure(config('database'), config('database-user'),
unit_private_ip())
def setup_endpoint(keystone):
"""When the keystone interface connects, register this unit in the keystone
catalogue.
"""
charm = BarbicanCharm.singleton
keystone.register_endpoints(charm.service_type,
charm.region,
charm.public_url,
charm.internal_url,
charm.admin_url)
def render_configs(interfaces_list):
"""Using a list of interfaces, render the configs and, if they have
changes, restart the services on the unit.
"""
BarbicanCharm.singleton.render_interfaces(interfaces_list)
###
# Implementation of the Barbican Charm classes
class BarbicanConfigurationAdapater(
charm.openstack.adapters.ConfigurationAdapter):
def __init__(self):
super(BarbicanConfigurationAdapater, self).__init__()
if self.keystone_api_version not in ['2', '3', 'none']:
raise ValueError(
"Unsupported keystone-api-version ({}). It should be 2 or 3"
.format(self.keystone_api_version))
@property
def barbican_api_keystone_pipeline(self):
if self.keystone_api_version == "2":
return 'keystone_authtoken context apiapp'
else:
return 'keystone_v3_authtoken context apiapp'
@property
def barbican_api_pipeline(self):
return {
"2": "keystone_authtoken context apiapp",
"3": "keystone_v3_authtoken context apiapp",
"none": "unauthenticated-context apiapp"
}[self.keystone_api_version]
class BarbicanAdapters(charm.openstack.adapters.OpenStackRelationAdapters):
"""
Adapters class for the Barbican charm.
This plumbs in the BarbicanConfigurationAdapter as the ConfigurationAdapter
to provide additional properties.
"""
def __init__(self, relations):
super(BarbicanAdapters, self).__init__(
relations, options=BarbicanConfigurationAdapter)
class BarbicanCharm(charm.openstack.charm.OpenStackCharm):
"""BarbicanCharm provides the specialisation of the OpenStackCharm
functionality to manage a barbican unit.
"""
releases = {
'liberty': BarbicanCharm
}
first_release = 'liberty'
name = 'barbican'
packages = PACKAGES
api_ports = {
'barbican-api': {
PUBLIC: 9311,
ADMIN: 9312,
INTERNAL: 9313,
}
}
service_type = 'secretstore'
default_service = 'barbican-api'
services = ['barbican-api', 'barbican-worker']
restart_map = {
"{}/{}".format(BARBICAN_DIR, BARBICAN_API_CONF): services,
"{}/{}".format(BARBICAN_DIR, BARBICAN_ADMIN_PASTE_CONF): services,
"{}/{}".format(BARBICAN_DIR, BARBICAN_API_PASTE_CONF): services,
}
adapters_class = BarbicanAdapters
def __init__(self, release=None, *kwargs):
"""Custom initialiser for class
If no release is passed, then the charm determines the release from the
os_release() function.
"""
if release is None:
#release = os_release('barbican-common')
release = os_release('python-keystonemiddleware')
super(BarbicanCharm, self).__init__(release=release, **kwargs)
def install(self):
"""Customise the installation, configure the source and then call the
parent install() method to install the packages
"""
charmhelpers.fetch.add_source("ppa:gnuoy/barbican-alt")
self.configure_source()
# and do the actual install
super(BarbicanCharm, self).install()

View File

@ -0,0 +1,36 @@
# this is just for the reactive handlers and calls into the charm.
from __future__ import absolute_import
import charms.reactive as reactive
# This charm's library contains all of the handler code
import charm.openstack.barbican as barbican
# use a synthetic state to ensure that it get it to be installed independent of
# the install hook.
@reactive.when_not('charm.installed')
def install_packages():
barbican.install()
reactive.set_state('charm.installed')
@reactive.when('amqp.connected')
def setup_amqp_req(amqp):
barbican.setup_amqp_req(amqp)
@reactive.when('shared-db.connected')
def setup_database(database):
barbican.setup_database(database)
@reactive.when('identity-service.connected')
def setup_endpoint(keystone):
barbican.setup_endpoint(keystone)
@reactive.when('shared-db.available')
@reactive.when('identity-service.available')
@reactive.when('amqp.available')
def render_stuff(*args):
barbican.render_configs(args)