Skip to content

Commit

Permalink
Added connect command
Browse files Browse the repository at this point in the history
Signed-off-by: Victor Moene <victor.moene@northern.tech>
Ticket: ENT-5726
  • Loading branch information
victormlg committed Jan 24, 2025
1 parent be6e225 commit c7471cf
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
14 changes: 14 additions & 0 deletions cf_remote/commands.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from datetime import datetime
import os
import subprocess
import sys
import time
from multiprocessing.dummy import Pool
Expand Down Expand Up @@ -931,3 +932,16 @@ def agent(hosts, bootstrap=None):
print(output)

return 0


def connect_cmd(hosts):

assert hosts and len(hosts)

if len(hosts) > 1:
user_error("You can only connect to one host at a time")

print("Opening a SSH command shell...")
subprocess.run(["ssh", hosts[0]])

return 0
7 changes: 7 additions & 0 deletions cf_remote/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

return ap


Expand Down Expand Up @@ -388,6 +393,8 @@ def run_command_with_args(command, args):
return commands.deploy(args.hub, args.masterfiles)
elif command == "agent":
return commands.agent(args.hosts, args.bootstrap)
elif command == "connect":
return commands.connect_cmd(args.hosts)
else:
user_error("Unknown command: '{}'".format(command))

Expand Down

0 comments on commit c7471cf

Please sign in to comment.