Add OSM charms
Change-Id: Iec1c915c77ac24080bfc8813eecc1970ee8c0213
Signed-off-by: David Garcia <david.garcia@canonical.com>
diff --git a/installers/charm/interfaces/osm-nbi/README.md b/installers/charm/interfaces/osm-nbi/README.md
new file mode 100644
index 0000000..8fb9523
--- /dev/null
+++ b/installers/charm/interfaces/osm-nbi/README.md
@@ -0,0 +1,63 @@
+<!--
+Copyright 2020 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. -->
+
+# Overview
+
+This interface layer handles communication between Mongodb and its clients.
+
+## Usage
+
+### Provides
+
+To implement this relation to offer an nbi:
+
+In your charm's metadata.yaml:
+
+```yaml
+provides:
+ nbi:
+ interface: osm-nbi
+```
+
+reactive/mynbi.py:
+
+```python
+@when('nbi.joined')
+def send_config(nbi):
+ nbi.send_connection(
+ unit_get('private-address'),
+ get_nbi_port()
+ )
+```
+
+### Requires
+
+If you would like to use an nbi from your charm:
+
+metadata.yaml:
+
+```yaml
+requires:
+ nbi:
+ interface: osm-nbi
+```
+
+reactive/mycharm.py:
+
+```python
+@when('nbi.ready')
+def nbi_ready():
+ nbi = endpoint_from_flag('nbi.ready')
+ if nbi:
+ for unit in nbi.nbis():
+ add_nbi(unit['host'], unit['port'])
+```
diff --git a/installers/charm/interfaces/osm-nbi/copyright b/installers/charm/interfaces/osm-nbi/copyright
new file mode 100644
index 0000000..dd9405e
--- /dev/null
+++ b/installers/charm/interfaces/osm-nbi/copyright
@@ -0,0 +1,16 @@
+Format: http://dep.debian.net/deps/dep5/
+
+Files: *
+Copyright: Copyright 2020, Canonical Ltd., All Rights Reserved.
+License: Apache License 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.
\ No newline at end of file
diff --git a/installers/charm/interfaces/osm-nbi/interface.yaml b/installers/charm/interfaces/osm-nbi/interface.yaml
new file mode 100644
index 0000000..ec8ee86
--- /dev/null
+++ b/installers/charm/interfaces/osm-nbi/interface.yaml
@@ -0,0 +1,16 @@
+# Copyright 2020 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.
+name: osm-nbi
+summary: Interface for relating to a OSM Northbound Interface
+maintainer: '"Adam Israel" <adam@adamisrael.com>'
diff --git a/installers/charm/interfaces/osm-nbi/provides.py b/installers/charm/interfaces/osm-nbi/provides.py
new file mode 100644
index 0000000..7ff3199
--- /dev/null
+++ b/installers/charm/interfaces/osm-nbi/provides.py
@@ -0,0 +1,44 @@
+#!/usr/bin/python
+# Copyright 2020 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 OsmNBIProvides(RelationBase):
+ scope = scopes.GLOBAL
+
+ @hook("{provides:osm-nbi}-relation-joined")
+ def joined(self):
+ self.set_state("{relation_name}.joined")
+
+ @hook("{provides:osm-nbi}-relation-changed")
+ def changed(self):
+ self.set_state("{relation_name}.ready")
+
+ @hook("{provides:osm-nbi}-relation-{broken,departed}")
+ def broken_departed(self):
+ self.remove_state("{relation_name}.ready")
+ self.remove_state("{relation_name}.joined")
+
+ @hook("{provides:osm-nbi}-relation-broken")
+ def broken(self):
+ self.set_state("{relation_name}.removed")
+
+ def send_connection(self, host, port=9999):
+ conv = self.conversation()
+ conv.set_remote("host", host)
+ conv.set_remote("port", port)
diff --git a/installers/charm/interfaces/osm-nbi/requires.py b/installers/charm/interfaces/osm-nbi/requires.py
new file mode 100644
index 0000000..a5e8e29
--- /dev/null
+++ b/installers/charm/interfaces/osm-nbi/requires.py
@@ -0,0 +1,56 @@
+# Copyright 2020 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 OsmNBIRequires(RelationBase):
+ scope = scopes.GLOBAL
+
+ @hook("{requires:osm-nbi}-relation-joined")
+ def joined(self):
+ conv = self.conversation()
+ conv.set_state("{relation_name}.joined")
+
+ @hook("{requires:osm-nbi}-relation-changed")
+ def changed(self):
+ conv = self.conversation()
+ if self.nbis():
+ conv.set_state("{relation_name}.ready")
+ else:
+ conv.remove_state("{relation_name}.ready")
+
+ @hook("{requires:osm-nbi}-relation-departed")
+ def departed(self):
+ conv = self.conversation()
+ conv.remove_state("{relation_name}.ready")
+ conv.remove_state("{relation_name}.joined")
+
+ def nbis(self):
+ """Return the NBI's host and port.
+
+ [{
+ 'host': <host>,
+ 'port': <port>,
+ }]
+ """
+ nbis = []
+ for conv in self.conversations():
+ port = conv.get_remote("port")
+ host = conv.get_remote("host") or conv.get_remote("private-address")
+ if host and port:
+ nbis.append({"host": host, "port": port})
+ return nbis
diff --git a/installers/charm/interfaces/osm-ro/README.md b/installers/charm/interfaces/osm-ro/README.md
new file mode 100644
index 0000000..eb6413a
--- /dev/null
+++ b/installers/charm/interfaces/osm-ro/README.md
@@ -0,0 +1,63 @@
+<!--
+Copyright 2020 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. -->
+
+# Overview
+
+This interface layer handles communication between OSM's RO and its clients.
+
+## Usage
+
+### Provides
+
+To implement this relation to offer an ro:
+
+In your charm's metadata.yaml:
+
+```yaml
+provides:
+ ro:
+ interface: osm-ro
+```
+
+reactive/myro.py:
+
+```python
+@when('ro.joined')
+def send_config(ro):
+ ro.send_connection(
+ unit_get('private-address'),
+ get_ro_port()
+ )
+```
+
+### Requires
+
+If you would like to use a rodb from your charm:
+
+metadata.yaml:
+
+```yaml
+requires:
+ ro:
+ interface: osm-ro
+```
+
+reactive/mycharm.py:
+
+```python
+@when('ro.ready')
+def ro_ready():
+ ro = endpoint_from_flag('ro.ready')
+ if ro:
+ for unit in ro.ros():
+ add_ro(unit['host'], unit['port'])
+```
diff --git a/installers/charm/interfaces/osm-ro/copyright b/installers/charm/interfaces/osm-ro/copyright
new file mode 100644
index 0000000..9270d6c
--- /dev/null
+++ b/installers/charm/interfaces/osm-ro/copyright
@@ -0,0 +1,16 @@
+Format: http://dep.debian.net/deps/dep5/
+
+Files: *
+Copyright: Copyright 2020, Canonical Ltd., All Rights Reserved.
+License: Apache License 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.
diff --git a/installers/charm/interfaces/osm-ro/interface.yaml b/installers/charm/interfaces/osm-ro/interface.yaml
new file mode 100644
index 0000000..9a12872
--- /dev/null
+++ b/installers/charm/interfaces/osm-ro/interface.yaml
@@ -0,0 +1,16 @@
+# Copyright 2020 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.
+name: osm-ro
+summary: Interface for relating to a OSM Resource Orchestrator
+maintainer: '"Adam Israel" <adam@adamisrael.com>'
diff --git a/installers/charm/interfaces/osm-ro/provides.py b/installers/charm/interfaces/osm-ro/provides.py
new file mode 100644
index 0000000..f577319
--- /dev/null
+++ b/installers/charm/interfaces/osm-ro/provides.py
@@ -0,0 +1,44 @@
+#!/usr/bin/python
+# Copyright 2020 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 OsmROProvides(RelationBase):
+ scope = scopes.GLOBAL
+
+ @hook("{provides:osm-ro}-relation-joined")
+ def joined(self):
+ self.set_state("{relation_name}.joined")
+
+ @hook("{provides:osm-ro}-relation-changed")
+ def changed(self):
+ self.set_state("{relation_name}.ready")
+
+ @hook("{provides:osm-ro}-relation-{broken,departed}")
+ def broken_departed(self):
+ self.remove_state("{relation_name}.ready")
+ self.remove_state("{relation_name}.joined")
+
+ @hook("{provides:osm-ro}-relation-broken")
+ def broken(self):
+ self.set_state("{relation_name}.removed")
+
+ def send_connection(self, host, port=9090):
+ conv = self.conversation()
+ conv.set_remote("host", host)
+ conv.set_remote("port", port)
diff --git a/installers/charm/interfaces/osm-ro/requires.py b/installers/charm/interfaces/osm-ro/requires.py
new file mode 100644
index 0000000..fc8f0f4
--- /dev/null
+++ b/installers/charm/interfaces/osm-ro/requires.py
@@ -0,0 +1,56 @@
+# Copyright 2020 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 OsmRORequires(RelationBase):
+ scope = scopes.GLOBAL
+
+ @hook("{requires:osm-ro}-relation-joined")
+ def joined(self):
+ conv = self.conversation()
+ conv.set_state("{relation_name}.joined")
+
+ @hook("{requires:osm-ro}-relation-changed")
+ def changed(self):
+ conv = self.conversation()
+ if self.ros():
+ conv.set_state("{relation_name}.ready")
+ else:
+ conv.remove_state("{relation_name}.ready")
+
+ @hook("{requires:osm-ro}-relation-departed")
+ def departed(self):
+ conv = self.conversation()
+ conv.remove_state("{relation_name}.ready")
+ conv.remove_state("{relation_name}.joined")
+
+ def ros(self):
+ """Return the NBI's host and port.
+
+ [{
+ 'host': <host>,
+ 'port': <port>,
+ }]
+ """
+ ros = []
+ for conv in self.conversations():
+ port = conv.get_remote("port")
+ host = conv.get_remote("host") or conv.get_remote("private-address")
+ if host and port:
+ ros.append({"host": host, "port": port})
+ return ros