diff --git a/src/charm.py b/src/charm.py index de1c5089..4b3aecb3 100755 --- a/src/charm.py +++ b/src/charm.py @@ -97,12 +97,13 @@ def _logrotate(self) -> machine_logrotate.LogRotate: def host_address(self) -> str: """The host address for the machine.""" if ( - self._ha_cluster.relation - and self._ha_cluster.is_clustered() - and self.config.get("vip") + not self.is_externally_accessible(event=None) + or not self.config.get("vip") + or (self._ha_cluster and not self._ha_cluster.is_clustered()) ): - return self.config["vip"] - return str(self.model.get_binding("juju-info").network.bind_address) + return str(self.model.get_binding("juju-info").network.bind_address) + + return self.config["vip"] @property def _read_write_endpoints(self) -> str: diff --git a/src/relations/hacluster.py b/src/relations/hacluster.py index de4ea9d6..cf1f3906 100644 --- a/src/relations/hacluster.py +++ b/src/relations/hacluster.py @@ -10,8 +10,6 @@ import ops -import workload - HACLUSTER_RELATION_NAME = "ha" logger = logging.getLogger(__name__) @@ -36,6 +34,9 @@ def relation(self) -> Optional[ops.Relation]: def is_clustered(self) -> bool: """Check if the related hacluster charm is clustered.""" + if not self.relation: + return False + for key, value in self.relation.data.items(): if ( isinstance(key, ops.Unit) @@ -57,13 +58,6 @@ def get_unit_juju_status(self) -> ops.StatusBase: if vip and not self.charm.is_externally_accessible(event=None): return ops.BlockedStatus("vip configuration without data-integrator") - if ( - isinstance(self.charm.get_workload(event=None), workload.AuthenticatedWorkload) - and self.charm.unit.is_leader() - and vip - ): - return ops.ActiveStatus(f"VIP: {vip}") - def set_vip(self, vip: Optional[str]) -> None: """Adds the requested virtual IP to the integration.""" if not self.relation: