|
20 | 20 | ) |
21 | 21 | from ops.charm import RelationBrokenEvent, RelationDepartedEvent, RelationJoinedEvent |
22 | 22 | from ops.framework import Object |
23 | | -from ops.model import BlockedStatus, Relation, Unit |
| 23 | +from ops.model import BlockedStatus, Relation |
24 | 24 |
|
25 | 25 | from constants import DB_RELATION_NAME, PASSWORD_LENGTH, PEER |
26 | 26 | from utils import generate_random_password |
@@ -311,45 +311,3 @@ def _on_database_provides_relation_departed(self, event: RelationDepartedEvent) |
311 | 311 | logger.info(f"Removed router from metadata {user.router_id}") |
312 | 312 | except MySQLRemoveRouterFromMetadataError: |
313 | 313 | logger.error(f"Failed to remove router from metadata with ID {user.router_id}") |
314 | | - |
315 | | - def remove_unit_from_endpoints(self, unit: Unit) -> None: |
316 | | - """Remove a unit from the endpoints for related applications. |
317 | | -
|
318 | | - Args: |
319 | | - unit (ops.Unit): The the unit to be removed. |
320 | | - """ |
321 | | - if not self.charm.unit.is_leader(): |
322 | | - return |
323 | | - |
324 | | - if not self.charm.cluster_initialized: |
325 | | - logger.debug("Waiting cluster to be initialized") |
326 | | - return |
327 | | - |
328 | | - unit_address = self.charm.get_unit_ip(unit) |
329 | | - |
330 | | - # filter out the unit address from the (ro)endpoints |
331 | | - for relation in self.active_relations: |
332 | | - # rw endpoints |
333 | | - endpoints = ( |
334 | | - self.database.fetch_my_relation_field(relation.id, "endpoints", DB_RELATION_NAME) |
335 | | - or "" |
336 | | - ) |
337 | | - if unit_address in endpoints: |
338 | | - self.database.set_endpoints( |
339 | | - relation.id, |
340 | | - ",".join([e for e in endpoints.split(",") if unit_address not in e]), |
341 | | - ) |
342 | | - continue |
343 | | - |
344 | | - # ro endpoints |
345 | | - ro_endpoints = ( |
346 | | - self.database.fetch_my_relation_field( |
347 | | - relation.id, "read-only-endpoints", DB_RELATION_NAME |
348 | | - ) |
349 | | - or "" |
350 | | - ) |
351 | | - if unit_address in ro_endpoints: |
352 | | - self.database.set_read_only_endpoints( |
353 | | - relation.id, |
354 | | - ",".join([e for e in ro_endpoints.split(",") if unit_address not in e]), |
355 | | - ) |
0 commit comments