mirror of
https://gitlab.com/kupfer/kupferbootstrap.git
synced 2025-02-23 05:35:44 -05:00
ssh: make alloc_tty=True default for run_ssh_command()
This commit is contained in:
parent
0858a64144
commit
1f15d6705c
2 changed files with 7 additions and 5 deletions
|
@ -45,6 +45,6 @@ def cmd_forwarding():
|
|||
click.Abort('Failed set iptables rule')
|
||||
|
||||
logging.info("Setting default route on device via ssh")
|
||||
result = run_ssh_command(cmd=['sudo -S route add default gw 172.16.42.2'])
|
||||
result = run_ssh_command(cmd=['sudo -S route add default gw 172.16.42.2'], alloc_tty=True)
|
||||
if result.returncode != 0:
|
||||
click.Abort('Failed to add gateway over ssh')
|
||||
|
|
10
ssh.py
10
ssh.py
|
@ -16,14 +16,14 @@ from exec.cmd import run_cmd
|
|||
@click.option('--port', '-p', help='the SSH port', type=int, default=SSH_DEFAULT_PORT)
|
||||
def cmd_ssh(cmd: list[str], user: str, host: str, port: int):
|
||||
"""Establish SSH connection to device"""
|
||||
run_ssh_command(list(cmd), user=user, host=host, port=port)
|
||||
run_ssh_command(list(cmd), user=user, host=host, port=port, alloc_tty=True)
|
||||
|
||||
|
||||
def run_ssh_command(cmd: list[str] = [],
|
||||
user: Optional[str] = None,
|
||||
host: str = SSH_DEFAULT_HOST,
|
||||
port: int = SSH_DEFAULT_PORT,
|
||||
alloc_tty: bool = False):
|
||||
alloc_tty: bool = True):
|
||||
if not user:
|
||||
user = config.get_profile()['username']
|
||||
keys = find_ssh_keys()
|
||||
|
@ -34,13 +34,15 @@ def run_ssh_command(cmd: list[str] = [],
|
|||
extra_args += ['-v']
|
||||
if alloc_tty:
|
||||
extra_args += ['-t']
|
||||
logging.info(f'Opening SSH connection to {(user + "@") if user else ""}{host} ({port})')
|
||||
hoststr = f'{(user + "@") if user else ""}{host}'
|
||||
logging.info(f'Opening SSH connection to {hoststr} ({port})')
|
||||
logging.debug(f"ssh: trying to run {cmd} on {hoststr}")
|
||||
full_cmd = [
|
||||
'ssh',
|
||||
] + extra_args + SSH_COMMON_OPTIONS + [
|
||||
'-p',
|
||||
str(port),
|
||||
f'{user}@{host}',
|
||||
hoststr,
|
||||
'--',
|
||||
] + cmd
|
||||
logging.debug(f"running cmd: {full_cmd}")
|
||||
|
|
Loading…
Add table
Reference in a new issue