1 # Copyright 2020 Canonical Ltd.
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
15 from charms
.reactive
import RelationBase
16 from charms
.reactive
import hook
17 from charms
.reactive
import scopes
20 class OsmRORequires(RelationBase
):
23 @hook("{requires:osm-ro}-relation-joined")
25 conv
= self
.conversation()
26 conv
.set_state("{relation_name}.joined")
28 @hook("{requires:osm-ro}-relation-changed")
30 conv
= self
.conversation()
32 conv
.set_state("{relation_name}.ready")
34 conv
.remove_state("{relation_name}.ready")
36 @hook("{requires:osm-ro}-relation-departed")
38 conv
= self
.conversation()
39 conv
.remove_state("{relation_name}.ready")
40 conv
.remove_state("{relation_name}.joined")
43 """Return the NBI's host and port.
51 for conv
in self
.conversations():
52 port
= conv
.get_remote("port")
53 host
= conv
.get_remote("host") or conv
.get_remote("private-address")
55 ros
.append({"host": host
, "port": port
})