Initial interface version

This commit is contained in:
James Page 2017-07-06 14:04:23 +01:00
commit 273d2b7919
7 changed files with 139 additions and 0 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
.tox
.project
.pydevproject

21
copyright Normal file
View File

@ -0,0 +1,21 @@
Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0
Files: *
Copyright: 2017, 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: gnocchi
summary: Gnocchi Metrics Service interface
version: 1

32
provides.py Normal file
View File

@ -0,0 +1,32 @@
# Copyright 2017 Canonical Ltd
#
# 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
class GnocchiProvides(RelationBase):
scope = scopes.UNIT
@hook('{provides:gnocchi}-relation-{joined}')
def joined(self):
self.set_state('{relation_name}.connected')
@hook('{provides:gnocchi}-relation-{broken}')
def broken(self):
self.remove_state('{relation_name}.connected')
def set_gnocchi_url(self, url):
self.set_remote(gnocchi_url=url)

35
requires.py Normal file
View File

@ -0,0 +1,35 @@
# Copyright 2017 Canonical Ltd
#
# 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
class GnocchiRequires(RelationBase):
scope = scopes.GLOBAL
auto_accessors = ['gnocchi_url']
@hook('{requires:gnocchi}-relation-{joined,changed,departed}')
def joined(self):
self.set_state('{relation_name}.connected')
if self.gnocchi_url() is not None:
self.set_state('{relation_name}.available')
else:
self.remove_state('{relation_name}.available')
@hook('{requires:gnocchi}-relation-{broken}')
def broken(self):
self.remove_state('{relation_name}.connected')

2
test-requirements.txt Normal file
View File

@ -0,0 +1,2 @@
flake8>=2.2.4,<=2.4.1
os-testr>=0.4.1

43
tox.ini Normal file
View File

@ -0,0 +1,43 @@
[tox]
envlist = pep8,py27,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:py27]
basepython = python2.7
deps = -r{toxinidir}/test-requirements.txt
# TODO: Need to write unit tests then remove the following command.
# https://github.com/juju/charm-tools/issues/249
commands = /bin/true
[testenv:py34]
basepython = python3.4
deps = -r{toxinidir}/test-requirements.txt
# TODO: Need to write unit tests then remove the following command.
# https://github.com/juju/charm-tools/issues/249
commands = /bin/true
[testenv:py35]
basepython = python3.5
deps = -r{toxinidir}/test-requirements.txt
# TODO: Need to write unit tests then remove the following command.
# https://github.com/juju/charm-tools/issues/249
commands = /bin/true
[testenv:pep8]
basepython = python2.7
deps = -r{toxinidir}/test-requirements.txt
commands = flake8 {posargs}
[testenv:venv]
commands = {posargs}
[flake8]
ignore = E402,E226