X-Git-Url: https://osm.etsi.org/gitweb/?p=osm%2Fdevops.git;a=blobdiff_plain;f=installers%2Fcharm%2Fosm-nbi%2Fsrc%2Fcharm.py;h=162e2a5aba983bf5cede65940139d30e85e172ad;hp=964050a96ec3b7b88d92621843dfaa8876245788;hb=bb6415948df2dc6a016a2bef4686ebb93c9c68e1;hpb=ff8f33e3d93360bacdd3061ce9cfad6ddb3229a6 diff --git a/installers/charm/osm-nbi/src/charm.py b/installers/charm/osm-nbi/src/charm.py index 964050a9..162e2a5a 100755 --- a/installers/charm/osm-nbi/src/charm.py +++ b/installers/charm/osm-nbi/src/charm.py @@ -40,8 +40,9 @@ from charms.osm_libs.v0.utils import ( check_container_ready, check_service_active, ) +from charms.osm_nbi.v0.nbi import NbiProvides from lightkube.models.core_v1 import ServicePort -from ops.charm import ActionEvent, CharmBase +from ops.charm import ActionEvent, CharmBase, RelationJoinedEvent from ops.framework import StoredState from ops.main import main from ops.model import ActiveStatus, Container @@ -80,6 +81,7 @@ class OsmNbiCharm(CharmBase): }, ) self.kafka = KafkaRequires(self) + self.nbi = NbiProvides(self) self.mongodb_client = MongoClient(self, "mongodb") self.prometheus_client = PrometheusClient(self, "prometheus") self.keystone_client = KeystoneClient(self, "keystone") @@ -113,7 +115,7 @@ class OsmNbiCharm(CharmBase): self._configure_service(self.container) self._update_ingress_config() - + self._update_nbi_relation() # Update charm status self._on_update_status() except CharmError as e: @@ -145,6 +147,11 @@ class OsmNbiCharm(CharmBase): finally: self._on_update_status() + def _update_nbi_relation(self, event: RelationJoinedEvent = None) -> None: + """Handler for the nbi-relation-joined event.""" + if self.unit.is_leader(): + self.nbi.set_host_info(self.app.name, SERVICE_PORT, event.relation if event else None) + def _on_get_debug_mode_information_action(self, event: ActionEvent) -> None: """Handler for the get-debug-mode-information action event.""" if not self.debug_mode.started: @@ -173,6 +180,7 @@ class OsmNbiCharm(CharmBase): self.on["kafka"].relation_broken: self._on_required_relation_broken, # Action events self.on.get_debug_mode_information_action: self._on_get_debug_mode_information_action, + self.on.nbi_relation_joined: self._update_nbi_relation, } for relation in [self.on[rel_name] for rel_name in ["mongodb", "prometheus", "keystone"]]: event_handler_mapping[relation.relation_changed] = self._on_config_changed