Initial code drop

This commit is contained in:
James Page 2015-11-04 12:20:42 +00:00
commit 06f492983b
3 changed files with 50 additions and 0 deletions

9
copyright Normal file
View File

@ -0,0 +1,9 @@
Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0
Files: *
Copyright: 2015, Canonical Ltd.
License: GPL-3
License: GPL-3
On Debian GNU/Linux system you can find the complete text of the
GPL-3 license in '/usr/share/common-licenses/GPL-3'

3
interface.yaml Normal file
View File

@ -0,0 +1,3 @@
name: odl-controller-api
summary: Interface for intergrating with an OpenDayLight Controller RESTful API
maintainer: James Page <james.page@ubuntu.com>

38
requires.py Normal file
View File

@ -0,0 +1,38 @@
from charmhelpers.core.reactive import hook
from charmhelpers.core.reactive import RelationBase
from charmhelpers.core.reactive import scopes
class ControllerAPIRequires(RelationBase):
scope = scopes.GLOBAL
auto_accessors = ['private-address', 'host', 'port',
'username', 'password']
@hook('{requires:odl-controller-api}-relation-{joined,changed,departed}')
def changed(self):
self.set_state('{relation_name}.connected')
if self.connection():
self.set_state('{relation_name}.access.available')
else:
self.remove_state('{relation_name}.access.available')
@hook('{requires:odl-controller-api}-relation-broken')
def broken(self):
self.remove_state('{relation_name}.connected')
self.remove_state('{relation_name}.access.available')
def connection(self):
"""OpenDayLight Controller Access Details
Returns a dict of key value pairs for accessing the ODL controller API.
"""
data = {
'host': self.host() or self.private_address(),
'port': self.port() or '8181',
'username': self.username(),
'password': self.password(),
}
if all(data.values()):
return data
else:
return None