From 0a163030b72305c514e21940ac8a6aea0e96a3ea Mon Sep 17 00:00:00 2001 From: Alex Kavanagh Date: Tue, 1 Aug 2017 11:54:27 +0100 Subject: [PATCH] Rework the default handlers into layer-openstack-* Due to commit 95493a4 in charms.reactive, the default handlers in charms.openstack broke. This is because charms.reactive no longer will run handlers that are not in the hooks/ or reactive/ directory tree; the default handlers in charms.openstack are in the library code, which is pip installed into the module packages. This patch, and related patches in charms.openstack and layer-openstack enable the default handlers to function again. Note that from a charm author perspective, the API to default handlers is identical. This is merely an implementation change. Change-Id: I38d46eaab3d64dd43166957a4aee01163bc00f5b Partial-Bug: #1707685 --- reactive/layer_openstack_api.py | 64 +++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 reactive/layer_openstack_api.py diff --git a/reactive/layer_openstack_api.py b/reactive/layer_openstack_api.py new file mode 100644 index 0000000..8111bb9 --- /dev/null +++ b/reactive/layer_openstack_api.py @@ -0,0 +1,64 @@ +# attempt to move the default status handler here: +import charmhelpers.core.hookenv as hookenv + +import charms_openstack.charm as charm +import charms.reactive as reactive + + +@reactive.when('amqp.connected', + 'charms.openstack.do-default-amqp.connected') +def default_amqp_connection(amqp): + """Handle the default amqp connection. + + This requires that the charm implements get_amqp_credentials() to + provide a tuple of the (user, vhost) for the amqp server + """ + with charm.provide_charm_instance() as instance: + user, vhost = instance.get_amqp_credentials() + amqp.request_access(username=user, vhost=vhost) + instance.assess_status() + + +@reactive.when('shared-db.connected', + 'charms.openstack.do-default-shared-db.connected') +def default_setup_database(database): + """Handle the default database connection setup + + This requires that the charm implements get_database_setup() to provide + a list of dictionaries; + [{'database': ..., 'username': ..., 'hostname': ..., 'prefix': ...}] + + The prefix can be missing: it defaults to None. + """ + with charm.provide_charm_instance() as instance: + for db in instance.get_database_setup(): + database.configure(**db) + instance.assess_status() + + +@reactive.when('identity-service.connected', + 'charms.openstack.do-default-identity-service.connected') +def default_setup_endpoint_connection(keystone): + """When the keystone interface connects, register this unit into the + catalog. This is the default handler, and calls on the charm class to + provide the endpoint information. If multiple endpoints are needed, + then a custom endpoint handler will be needed. + """ + with charm.provide_charm_instance() as instance: + keystone.register_endpoints(instance.service_type, + instance.region, + instance.public_url, + instance.internal_url, + instance.admin_url) + instance.assess_status() + + +@reactive.when('identity-service.available', + 'charms.openstack.do-default-identity-service.available') +def default_setup_endpoint_available(keystone): + """When the identity-service interface is available, this default + handler switches on the SSL support. + """ + with charm.provide_charm_instance() as instance: + instance.configure_ssl(keystone) + instance.assess_status()