commit 496cbe6dba6f18f75da35c1aa061512de89cc440 Author: James Page Date: Thu Mar 10 10:23:06 2016 +0000 Re-initialize repositor diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..172bf57 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.tox diff --git a/copyright b/copyright new file mode 100644 index 0000000..5a49dcb --- /dev/null +++ b/copyright @@ -0,0 +1,21 @@ +Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0 + +Files: * +Copyright: 2015, Canonical Ltd. +License: Apache-2.0 + +License: Apache-2.0 + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + . + http://www.apache.org/licenses/LICENSE-2.0 + . + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + . + On Debian-based systems the full text of the Apache version 2.0 license + can be found in `/usr/share/common-licenses/Apache-2.0'. diff --git a/interface.yaml b/interface.yaml new file mode 100644 index 0000000..cc15048 --- /dev/null +++ b/interface.yaml @@ -0,0 +1,3 @@ +name: rabbitmq +summary: Interface for integrating with RabbitMQ Server +maintainer: OpenStack Charmers diff --git a/requires.py b/requires.py new file mode 100644 index 0000000..7a50d66 --- /dev/null +++ b/requires.py @@ -0,0 +1,117 @@ +#!/usr/bin/python +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from charms.reactive import RelationBase +from charms.reactive import hook +from charms.reactive import scopes +from charmhelpers.core import hookenv + + +class RabbitMQRequires(RelationBase): + scope = scopes.GLOBAL + + # These remote data fields will be automatically mapped to accessors + # with a basic documentation string provided. + auto_accessors = ['password', 'private-address', 'ssl_port', + 'ssl_ca', 'ha_queues', 'ha-vip-only', 'clustered', 'vip'] + + def vhost(self): + return self.get_local('vhost') + + def username(self): + return self.get_local('username') + + @hook('{requires:rabbitmq}-relation-joined') + def joined(self): + self.set_state('{relation_name}.connected') + + def update_state(self): + if self.base_data_complete(): + self.set_state('{relation_name}.available') + if self.ssl_data_complete(): + self.set_state('{relation_name}.available.ssl') + else: + self.remove_state('{relation_name}.available.ssl') + else: + self.remove_state('{relation_name}.available') + self.remove_state('{relation_name}.available.ssl') + if not self.rabbitmq_hosts(): + self.remove_state('{relation_name}.connected') + + @hook('{requires:rabbitmq}-relation-changed') + def changed(self): + self.update_state() + + @hook('{requires:rabbitmq}-relation-{broken,departed}') + def departed(self): + self.update_state() + + def base_data_complete(self): + """ + Get the connection string, if available, or None. + """ + data = { + 'hostname': self.private_address(), + 'vhost': self.vhost(), + 'username': self.username(), + 'password': self.password(), + } + if all(data.values()): + return True + return False + + def ssl_data_complete(self): + """ + Get the connection string, if available, or None. + """ + data = { + 'ssl_port': self.ssl_port(), + 'ssl_ca': self.ssl_ca(), + } + if all(data.values()): + return True + return False + + def request_access(self, username, vhost): + """ + Request access to vhost for the supplied username. + """ + relation_info = { + 'username': username, + 'vhost': vhost, + } + self.set_local(**relation_info) + self.set_remote(**relation_info) + + def configure(self, username, vhost): + """ + DEPRECATED: use request_access instead + Request access to vhost for the supplied username. + """ + self.request_access(username, vhost) + + def get_remote_all(self, key, default=None): + '''Return a list of all values presented by remote units for key''' + values = [] + for conversation in self.conversations(): + for relation_id in conversation.relation_ids: + for unit in hookenv.related_units(relation_id): + value = hookenv.relation_get(key, + unit, + relation_id) or default + if value: + values.append(value) + return list(set(values)) + + def rabbitmq_hosts(self): + return self.get_remote_all('private-address') diff --git a/test-requirements.txt b/test-requirements.txt new file mode 100644 index 0000000..10dbed3 --- /dev/null +++ b/test-requirements.txt @@ -0,0 +1,3 @@ +flake8>=2.2.4,<=2.4.1 +os-testr>=0.4.1 +charm-tools diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..c035f1a --- /dev/null +++ b/tox.ini @@ -0,0 +1,25 @@ +[tox] +envlist = lint,py27 +skipsdist = True + +[testenv] +setenv = VIRTUAL_ENV={envdir} + PYTHONHASHSEED=0 +install_command = + pip install --allow-unverified python-apt {opts} {packages} +commands = ostestr {posargs} + +[testenv:py27] +basepython = python2.7 +deps = -r{toxinidir}/test-requirements.txt + +[testenv:lint] +basepython = python2.7 +deps = -r{toxinidir}/test-requirements.txt +commands = flake8 {posargs} + +[testenv:venv] +commands = {posargs} + +[flake8] +ignore = E402,E226