mirror of https://github.com/m-labs/artiq.git
artiq_flash, artiq_devtool: add support for ssh -J option.
This commit is contained in:
parent
9704fb837f
commit
a148729bf8
|
@ -46,6 +46,9 @@ def get_argparser():
|
||||||
parser.add_argument("-H", "--host",
|
parser.add_argument("-H", "--host",
|
||||||
type=str, default="lab.m-labs.hk",
|
type=str, default="lab.m-labs.hk",
|
||||||
help="SSH host where the development board is located")
|
help="SSH host where the development board is located")
|
||||||
|
parser.add_argument("-J", "--jump",
|
||||||
|
type=str, default=None,
|
||||||
|
help="SSH host to jump through")
|
||||||
parser.add_argument("-b", "--board",
|
parser.add_argument("-b", "--board",
|
||||||
type=str, default="{board_type}-1",
|
type=str, default="{board_type}-1",
|
||||||
help="board to connect to on the development SSH host")
|
help="board to connect to on the development SSH host")
|
||||||
|
@ -57,7 +60,7 @@ def get_argparser():
|
||||||
type=str, default="/dev/ttyUSB_{board}",
|
type=str, default="/dev/ttyUSB_{board}",
|
||||||
help="TTY device corresponding to the development board")
|
help="TTY device corresponding to the development board")
|
||||||
parser.add_argument("-d", "--device",
|
parser.add_argument("-d", "--device",
|
||||||
type=str, default="{board}.{host}",
|
type=str, default="{board}",
|
||||||
help="address or domain corresponding to the development board")
|
help="address or domain corresponding to the development board")
|
||||||
parser.add_argument("-w", "--wait", action="store_true",
|
parser.add_argument("-w", "--wait", action="store_true",
|
||||||
help="wait for the board to unlock instead of aborting the actions")
|
help="wait for the board to unlock instead of aborting the actions")
|
||||||
|
@ -96,7 +99,7 @@ def main():
|
||||||
device = args.device.format(board=board, host=args.host)
|
device = args.device.format(board=board, host=args.host)
|
||||||
serial = args.serial.format(board=board)
|
serial = args.serial.format(board=board)
|
||||||
|
|
||||||
client = SSHClient(args.host)
|
client = SSHClient(args.host, args.jump)
|
||||||
|
|
||||||
flock_acquired = False
|
flock_acquired = False
|
||||||
flock_file = None # GC root
|
flock_file = None # GC root
|
||||||
|
@ -158,6 +161,8 @@ def main():
|
||||||
for _ in range(args.verbose):
|
for _ in range(args.verbose):
|
||||||
flash_args.append("-v")
|
flash_args.append("-v")
|
||||||
flash_args += ["-H", args.host]
|
flash_args += ["-H", args.host]
|
||||||
|
if args.jump:
|
||||||
|
flash_args += ["-J", args.jump]
|
||||||
flash_args += ["-t", board_type]
|
flash_args += ["-t", board_type]
|
||||||
flash_args += ["-V", variant]
|
flash_args += ["-V", variant]
|
||||||
flash_args += ["-I", "source {}".format(board_file)]
|
flash_args += ["-I", "source {}".format(board_file)]
|
||||||
|
|
|
@ -48,6 +48,9 @@ Prerequisites:
|
||||||
parser.add_argument("-H", "--host", metavar="HOSTNAME",
|
parser.add_argument("-H", "--host", metavar="HOSTNAME",
|
||||||
type=str, default=None,
|
type=str, default=None,
|
||||||
help="SSH host where the development board is located")
|
help="SSH host where the development board is located")
|
||||||
|
parser.add_argument("-J", "--jump",
|
||||||
|
type=str, default=None,
|
||||||
|
help="SSH host to jump through")
|
||||||
parser.add_argument("-t", "--target", default="kc705",
|
parser.add_argument("-t", "--target", default="kc705",
|
||||||
help="target board, default: %(default)s, one of: "
|
help="target board, default: %(default)s, one of: "
|
||||||
"kc705 kasli sayma")
|
"kc705 kasli sayma")
|
||||||
|
@ -299,7 +302,7 @@ def main():
|
||||||
if args.host is None:
|
if args.host is None:
|
||||||
client = LocalClient()
|
client = LocalClient()
|
||||||
else:
|
else:
|
||||||
client = SSHClient(args.host)
|
client = SSHClient(args.host, args.jump)
|
||||||
|
|
||||||
programmer = config["programmer"](client, preinit_script=args.preinit_command)
|
programmer = config["programmer"](client, preinit_script=args.preinit_command)
|
||||||
|
|
||||||
|
|
|
@ -57,8 +57,9 @@ class LocalClient(Client):
|
||||||
|
|
||||||
|
|
||||||
class SSHClient(Client):
|
class SSHClient(Client):
|
||||||
def __init__(self, host):
|
def __init__(self, host, jump_host=None):
|
||||||
self.host = host
|
self.host = host
|
||||||
|
self.jump_host = jump_host
|
||||||
self.ssh = None
|
self.ssh = None
|
||||||
self.sftp = None
|
self.sftp = None
|
||||||
self._tmpr = "/tmp/artiq"
|
self._tmpr = "/tmp/artiq"
|
||||||
|
@ -70,10 +71,19 @@ class SSHClient(Client):
|
||||||
if self.ssh is None:
|
if self.ssh is None:
|
||||||
import paramiko
|
import paramiko
|
||||||
logging.getLogger("paramiko").setLevel(logging.WARNING)
|
logging.getLogger("paramiko").setLevel(logging.WARNING)
|
||||||
|
|
||||||
|
if self.jump_host:
|
||||||
|
proxy_cmd = "ssh -W {}:22 {}".format(self.host, self.jump_host)
|
||||||
|
logger.debug("Using proxy command '{}'".format(proxy_cmd))
|
||||||
|
proxy = paramiko.proxy.ProxyCommand(proxy_cmd)
|
||||||
|
else:
|
||||||
|
proxy = None
|
||||||
|
|
||||||
self.ssh = paramiko.SSHClient()
|
self.ssh = paramiko.SSHClient()
|
||||||
self.ssh.load_system_host_keys()
|
self.ssh.load_system_host_keys()
|
||||||
self.ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
self.ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||||
self.ssh.connect(self.host)
|
self.ssh.connect(self.host, sock=proxy)
|
||||||
|
|
||||||
logger.debug("Connecting to {}".format(self.host))
|
logger.debug("Connecting to {}".format(self.host))
|
||||||
return self.ssh
|
return self.ssh
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue