| David Garcia | 82c5ffa | 2020-03-09 08:38:17 +0100 | [diff] [blame] | 1 | #!/usr/bin/python |
| 2 | # Copyright 2020 Canonical Ltd. |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | |
| 16 | from charms.reactive import RelationBase |
| 17 | from charms.reactive import hook |
| 18 | from charms.reactive import scopes |
| 19 | |
| 20 | |
| 21 | class OsmNBIProvides(RelationBase): |
| 22 | scope = scopes.GLOBAL |
| 23 | |
| 24 | @hook("{provides:osm-nbi}-relation-joined") |
| 25 | def joined(self): |
| 26 | self.set_state("{relation_name}.joined") |
| 27 | |
| 28 | @hook("{provides:osm-nbi}-relation-changed") |
| 29 | def changed(self): |
| 30 | self.set_state("{relation_name}.ready") |
| 31 | |
| 32 | @hook("{provides:osm-nbi}-relation-{broken,departed}") |
| 33 | def broken_departed(self): |
| 34 | self.remove_state("{relation_name}.ready") |
| 35 | self.remove_state("{relation_name}.joined") |
| 36 | |
| 37 | @hook("{provides:osm-nbi}-relation-broken") |
| 38 | def broken(self): |
| 39 | self.set_state("{relation_name}.removed") |
| 40 | |
| 41 | def send_connection(self, host, port=9999): |
| 42 | conv = self.conversation() |
| 43 | conv.set_remote("host", host) |
| 44 | conv.set_remote("port", port) |