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
},
)
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")
self._configure_service(self.container)
self._update_ingress_config()
-
+ self._update_nbi_relation()
# Update charm status
self._on_update_status()
except CharmError as e:
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:
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