From 5d0edb224094d63feb16991646b87379cac7a04d Mon Sep 17 00:00:00 2001 From: Jiri Otoupal Date: Wed, 25 Oct 2023 10:12:34 +0200 Subject: [PATCH] tries fix --- abst/__version__.py | 2 +- abst/bastion_support/oci_bastion.py | 15 ++++++++------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/abst/__version__.py b/abst/__version__.py index aa478da..9ae019e 100644 --- a/abst/__version__.py +++ b/abst/__version__.py @@ -10,7 +10,7 @@ "CLI Command making OCI Bastion and kubernetes usage simple and fast" ) -__version__ = "2.1.3" +__version__ = "2.1.4" __author__ = "Jiri Otoupal" __author_email__ = "jiri-otoupal@ips-database.eu" __license__ = "MIT" diff --git a/abst/bastion_support/oci_bastion.py b/abst/bastion_support/oci_bastion.py index 070b115..4dd09cf 100644 --- a/abst/bastion_support/oci_bastion.py +++ b/abst/bastion_support/oci_bastion.py @@ -29,6 +29,7 @@ def __init__(self, context_name=None, region=None): self.context_name = context_name self.region = region self.shell: bool = False + self.tries: int = 10 self.connected: bool = False self.active_tunnel: subprocess.Popen = Optional[None] self.response: Optional[dict] = None @@ -535,8 +536,7 @@ def __run_ssh_tunnel(self, ssh_tunnel_arg_str, shell, already_split=False): return True self.active_tunnel = p - tries = 3 - while p.poll() is None and tries >= 0: + while p.poll() is None and self.tries >= 0: line = p.stdout.readline().decode("utf-8").strip() line_err = None @@ -558,7 +558,7 @@ def __run_ssh_tunnel(self, ssh_tunnel_arg_str, shell, already_split=False): f"{datetime.datetime.now()}") self.connected = True self.current_status = "connected" - tries = 3 + self.tries = 10 if not line and not line_err: sleep(0.1) @@ -576,13 +576,14 @@ def __run_ssh_tunnel(self, ssh_tunnel_arg_str, shell, already_split=False): rich.print( f"({self.get_print_name()}) " f"Please check you configuration, for more info use --debug flag") - rich.print("This can also happen when ip changed in .ssh/known_hosts, delete it and try again") - if tries <= 0: + rich.print("[red]This can also happen when ip changed in [yellow]~/.ssh/known_hosts[/yellow], delete it and" + "try again[/red]") + if self.tries <= 0: self.kill() self.current_status = "Failed" exit(255) else: - tries -= 1 - self.current_status = f"failed {tries} left" + self.tries -= 1 + self.current_status = f"failed {self.tries} left" self.connected = False return True