Skip to content

Commit

Permalink
tries fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Jiri Otoupal committed Oct 25, 2023
1 parent 9791100 commit 5d0edb2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion abst/__version__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
15 changes: 8 additions & 7 deletions abst/bastion_support/oci_bastion.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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)
Expand All @@ -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

0 comments on commit 5d0edb2

Please sign in to comment.