From 58cc18fe40526c3b0198a320bdc02fad66c0e88b Mon Sep 17 00:00:00 2001 From: James Page Date: Wed, 15 Jul 2015 12:02:56 +0100 Subject: [PATCH] Initial commit of ovsdb-manager interface --- .gitignore | 2 ++ copyright | 9 +++++++++ interface.yaml | 3 +++ requires.py | 38 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 52 insertions(+) create mode 100644 .gitignore create mode 100644 copyright create mode 100644 interface.yaml create mode 100644 requires.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ddb0a2d --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +bin +.settings diff --git a/copyright b/copyright new file mode 100644 index 0000000..afa853f --- /dev/null +++ b/copyright @@ -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' diff --git a/interface.yaml b/interface.yaml new file mode 100644 index 0000000..13d92f9 --- /dev/null +++ b/interface.yaml @@ -0,0 +1,3 @@ +name: ovsdb-manager +summary: Interface for relating to the OVSDB manager aspect of OpenDayLight SDN +maintainer: James Page diff --git a/requires.py b/requires.py new file mode 100644 index 0000000..95d5bb4 --- /dev/null +++ b/requires.py @@ -0,0 +1,38 @@ +from charmhelpers.core.reactive import hook +from charmhelpers.core.reactive import RelationBase +from charmhelpers.core.reactive import scopes + + +class OVSDBManagerRequires(RelationBase): + scope = scopes.GLOBAL + auto_accessors = ['protocol', 'private-address', 'host', 'port'] + + @hook('{requires:ovsdb-manager}-relation-{joined,changed,departed}') + def changed(self): + self.set_state('{relation_name}.connected') + if self.connection_string(): + self.set_state('{relation_name}.access.available') + else: + self.remove_state('{relation_name}.access.available') + + @hook('{requires:ovsdb-manager}-relation-broken') + def broken(self): + self.remove_state('{relation_name}.connected') + self.remove_state('{relation_name}.access.available') + + def connection_string(self): + """Open vSwitch connection string + + Returns the connection string to use for Open vSwitch or None + if the remote ODL controller has not presented this data + yet. + """ + data = { + 'host': self.host() or self.private_address(), + 'port': self.port() or '6640', + 'protocol': self.protocol(), + } + if all(data.values()): + return "{protocol}:{host}:{port}".format(**data) + else: + return None