From e00c817737b086b92c7ffb193e6bb328aea064fc Mon Sep 17 00:00:00 2001 From: Alex Kavanagh Date: Thu, 23 Jun 2016 13:40:04 +0000 Subject: [PATCH] Initial interface files This is a basic, 'just about works' commit of the HSM plugin interface to provide a base to work from in getting the HSM <-> barbican charm to work. --- copyright | 21 +++++++++++++++++++++ interface.yaml | 4 ++++ provides.py | 28 ++++++++++++++++++++++++++++ requires.py | 31 +++++++++++++++++++++++++++++++ test-requirements.txt | 3 +++ tox.ini | 30 ++++++++++++++++++++++++++++++ 6 files changed, 117 insertions(+) create mode 100644 copyright create mode 100644 interface.yaml create mode 100644 provides.py create mode 100644 requires.py create mode 100644 test-requirements.txt create mode 100644 tox.ini 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..61e3155 --- /dev/null +++ b/interface.yaml @@ -0,0 +1,4 @@ +name: barbican-hsm-plugin +summary: Interface for a plugin to the Barbican charm. +maintainer: OpenStack Charmers +repo: https://github.com/openstack-charmers/charm-interface-barbican-plugin diff --git a/provides.py b/provides.py new file mode 100644 index 0000000..ba53d73 --- /dev/null +++ b/provides.py @@ -0,0 +1,28 @@ +import charms.reactive as reactive +import charmhelpers.core.hookenv as hookenv + + +class BarbicanProvides(reactive.RelationBase): + scope = reactive.scopes.GLOBAL + + # These remote data fields will be automatically mapped to accessors + # with a basic documentation string provided. + auto_accessors = ['test'] + + @reactive.hook('{provides:barbican-hsm-plugin}-relation-joined') + def joined(self): + self.set_state('{relation_name}.connected') + hookenv.log("BarbicanProvides.joined() ran") + + @reactive.hook('{provides:barbican-hsm-plugin}-relation-changed') + def changed(self): + hookenv.log("BarbicanProvides.changed() ran") + + @reactive.hook('{provides:barbican-hsm-plugin}-relation-{broken,departed}') + def departed(self): + hookenv.log("BarbicanProvides.departed() ran") + self.remove_state('{relation_name}.connected') + self.remove_state('{relation_name}.available') + + def set_name(self, name): + self.set_remote(name=name) diff --git a/requires.py b/requires.py new file mode 100644 index 0000000..ed853b9 --- /dev/null +++ b/requires.py @@ -0,0 +1,31 @@ +import charms.reactive as reactive +import charmhelpers.core.hookenv as hookenv + + +class BarbicanRequires(reactive.RelationBase): + scope = reactive.scopes.GLOBAL + + # These remote data fields will be automatically mapped to accessors + # with a basic documentation string provided. + auto_accessors = ['name'] + + @reactive.hook('{requires:barbican-hsm-plugin}-relation-joined') + def joined(self): + self.set_state('{relation_name}.connected') + hookenv.log("BarbicanRequires.joined() ran") + self.update_status() + + @reactive.hook('{requires:barbican-hsm-plugin}-relation-changed') + def changed(self): + hookenv.log("BarbicanRequires.changed() ran") + self.update_status() + + @reactive.hook('{requires:barbican-hsm-plugin}-relation-{broken,departed}') + def departed(self): + hookenv.log("BarbicanRequires.departed() ran") + self.remove_state('{relation_name}.connected') + self.remove_state('{relation_name}.available') + + def update_status(self): + if self.name is not None: + self.set_state('{relation_name}.available') 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..42026e1 --- /dev/null +++ b/tox.ini @@ -0,0 +1,30 @@ +[tox] +envlist = lint,py34,py35 +skipsdist = True +skip_missing_interpreters = True + +[testenv] +setenv = VIRTUAL_ENV={envdir} + PYTHONHASHSEED=0 +install_command = + pip install --allow-unverified python-apt {opts} {packages} +commands = ostestr {posargs} + +[testenv:py34] +basepython = python3.4 +deps = -r{toxinidir}/test-requirements.txt + +[testenv:py35] +basepython = python3.5 +deps = -r{toxinidir}/test-requirements.txt + +[testenv:pep8] +basepython = python2.7 +deps = -r{toxinidir}/test-requirements.txt +commands = flake8 {posargs} + +[testenv:venv] +commands = {posargs} + +[flake8] +ignore = E402,E226