Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added connect command #114

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

victormlg
Copy link
Contributor

@victormlg victormlg commented Jan 13, 2025

It seems like subprocess.Popen doesn't allow changing another process' working directory, so the command "cd" doesn't do anything. I feel like keeping track of the current directory would make the code overly complicated when the user can just use tricks like "cd some/dir && command ..."

Currently, it only allows connecting to a single host

Signed-off-by: Victor Moene <[email protected]>
Ticket: ENT-5726
@victormlg victormlg requested a review from olehermanse January 13, 2025 15:06
@@ -274,6 +274,11 @@ def _get_arg_parser():
)
sp.add_argument("--bootstrap", "-B", help="Which hub to bootstrap to", type=str)

sp = subp.add_parser("connect", help="Opens interactive ssh shell")
sp.add_argument(
"-hosts", "-H", help="Host to open the shell on", type=str, required=True
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"-hosts", "-H", help="Host to open the shell on", type=str, required=True
"--hosts", "-H", help="Host to open the shell on", type=str, required=True

Comment on lines +637 to +660
@auto_connect
def open_shell(host, connection=None):
print("Enter 'exit' to log out\n")

cmd = ""
while cmd != "exit":
try:
cmd = input("\033[92m{}\033[00m :~ $ ".format(host))
result = connection.run(cmd, hide=True)

if cmd == "exit":
pass
elif result.retcode == 0:
print(result.stdout.strip().strip("\n"))
else:
print(result.stderr.strip("\n"))
except KeyboardInterrupt:
print()
continue
except EOFError:
print()
return 0

return 0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you try just launching ssh, instead of "implementing" a new shell like this?

https://stackoverflow.com/questions/3692387/start-interactive-ssh-session-from-python-script

I know it might be a bit tricky to get it to work, but might be worth it if it's not too hard.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants