From 3c6f69a7102a09345a51bd0ab0ddb2092ef47e7a Mon Sep 17 00:00:00 2001 From: levisingularity Date: Wed, 27 Nov 2024 12:02:22 -0300 Subject: [PATCH] das-toolbox-139: Singleton remote context manager --- src/commands/config/config_cli.py | 14 +++++--------- src/common/docker/remote_context_manager.py | 6 ++++-- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/commands/config/config_cli.py b/src/commands/config/config_cli.py index cba1bdb..8c8888e 100644 --- a/src/commands/config/config_cli.py +++ b/src/commands/config/config_cli.py @@ -180,10 +180,8 @@ def _build_nodes(self, is_cluster: bool, port: int) -> List[Dict]: nodes = [] - join_current_server = self.prompt( + join_current_server = self.confirm( f"Do you want to join the current server as an actual node on the network?", - hide_input=False, - type=bool, default=True, ) @@ -248,14 +246,12 @@ def _build_cluster( } ) - remote_context_manager = RemoteContextManager(servers) - cluster_contexts = remote_context_manager.create_context() - - return cluster_contexts + self._remote_context_manager.set_servers(servers) + return self._remote_context_manager.create_context() def _destroy_contexts(self, servers: List[Dict]): - remote_context_manager = RemoteContextManager(servers) - remote_context_manager.remove_context() + self._remote_context_manager.set_servers(servers) + self._remote_context_manager.remove_context() def _redis_nodes(self, redis_cluster, redis_port) -> List[Dict]: redis_nodes = self._build_nodes(redis_cluster, redis_port) diff --git a/src/common/docker/remote_context_manager.py b/src/common/docker/remote_context_manager.py index 6073581..0ae1ddc 100644 --- a/src/common/docker/remote_context_manager.py +++ b/src/common/docker/remote_context_manager.py @@ -6,7 +6,7 @@ class RemoteContextManager: def __init__( self, - servers: List[Dict], + servers: List[Dict] = [], ) -> None: self._servers = servers @@ -49,7 +49,9 @@ def create_context(self) -> List[AnyStr]: server_username = server.get("username") context_name = str(uuid4()) - context_description = f"This context connects to {server_ip} and managed by das-cli" + context_description = ( + f"This context connects to {server_ip} and managed by das-cli" + ) context_host = self._get_host(server_username, server_ip) context_docker = self._get_context( host=context_host,