- def __init__(self, framework, key):
- super().__init__(framework, key)
- self.state.set_default(spec=None)
-
- # Observe Charm related events
- self.framework.observe(self.on.config_changed, self.on_config_changed)
- self.framework.observe(self.on.start, self.on_start)
- self.framework.observe(self.on.upgrade_charm, self.on_upgrade_charm)
- # self.framework.observe(
- # self.on.nbi_relation_joined, self.on_nbi_relation_joined
- # )
-
- def _apply_spec(self):
- # Only apply the spec if this unit is a leader.
- if not self.framework.model.unit.is_leader():
- return
- new_spec = self.make_pod_spec()
- if new_spec == self.state.spec:
+ def __init__(self, *args) -> NoReturn:
+ """NGUI Charm constructor."""
+ super().__init__(*args)
+
+ # Internal state initialization
+ self.state.set_default(pod_spec=None)
+
+ # North bound interface initialization
+ self.state.set_default(nbi_host=None)
+ self.state.set_default(nbi_port=None)
+
+ self.http_port = NGUI_PORT
+ self.image = OCIImageResource(self, "image")
+
+ # Registering regular events
+ self.framework.observe(self.on.start, self.configure_pod)
+ self.framework.observe(self.on.config_changed, self.configure_pod)
+ # self.framework.observe(self.on.upgrade_charm, self.configure_pod)
+
+ # Registering custom internal events
+ self.framework.observe(self.on.configure_pod, self.configure_pod)
+
+ # Registering required relation changed events
+ self.framework.observe(
+ self.on.nbi_relation_changed, self._on_nbi_relation_changed
+ )
+
+ # Registering required relation departed events
+ self.framework.observe(
+ self.on.nbi_relation_departed, self._on_nbi_relation_departed
+ )
+
+ def _on_nbi_relation_changed(self, event: EventBase) -> NoReturn:
+ """Reads information about the nbi relation.
+
+ Args:
+ event (EventBase): NBI relation event.
+ """
+ if event.unit not in event.relation.data: