Re-initialize repositor

This commit is contained in:
James Page 2016-03-10 10:23:06 +00:00
commit 496cbe6dba
6 changed files with 170 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
.tox

21
copyright Normal file
View File

@ -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'.

3
interface.yaml Normal file
View File

@ -0,0 +1,3 @@
name: rabbitmq
summary: Interface for integrating with RabbitMQ Server
maintainer: OpenStack Charmers <openstack-charmers@lists.ubuntu.com>

117
requires.py Normal file
View File

@ -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')

3
test-requirements.txt Normal file
View File

@ -0,0 +1,3 @@
flake8>=2.2.4,<=2.4.1
os-testr>=0.4.1
charm-tools

25
tox.ini Normal file
View File

@ -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