Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions lib/jnpr/junos/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -1230,6 +1230,13 @@ def __init__(self, *vargs, **kvargs):
*OPTIONAL* To enable ssh_known hostkey verify
default is ``False``.

:param str proxy_command:
*OPTIONAL* The SSH ProxyCommand string to use when connecting
through a bastion/jump host, e.g.
``"ssh -W %h:%p bastion.example.com"``.
Wraps :class:`paramiko.proxy.ProxyCommand` and is passed as the
``sock`` argument to the underlying ncclient transport.
Cannot be combined with ``sock_fd``.
"""

# ----------------------------------------
Expand All @@ -1251,6 +1258,7 @@ def __init__(self, *vargs, **kvargs):
self._allow_agent = kvargs.get("allow_agent", None)
self._bind_addr = kvargs.get("bind_addr", None)
self._hostkey_verify = kvargs.get("hostkey_verify", False)
self._proxy_command = kvargs.get("proxy_command", None)
if self._fact_style != "new":
warnings.warn(
"fact-style %s will be removed in a future "
Expand All @@ -1275,6 +1283,10 @@ def __init__(self, *vargs, **kvargs):
# --------------------------
if hostname is None and self._sock_fd is None:
raise ValueError("You must provide either 'host' or 'sock_fd' value")
if self._proxy_command is not None and self._sock_fd is not None:
raise ValueError(
"'proxy_command' and 'sock_fd' cannot be used together"
)
self._hostname = hostname
# user will default to $USER
self._auth_user = os.getenv("USER")
Expand Down Expand Up @@ -1397,11 +1409,20 @@ def open(self, *vargs, **kvargs):
else:
hostkey_verify = self._hostkey_verify

# build sock from proxy_command if provided
sock = None
if self._proxy_command is not None:
proxy_cmd = self._proxy_command.replace("%h", self._hostname).replace(
"%p", str(self._port)
)
sock = paramiko.proxy.ProxyCommand(proxy_cmd)

# open connection using ncclient transport
self._conn = netconf_ssh.connect(
host=self._hostname,
port=self._port,
sock_fd=self._sock_fd,
sock=sock, # support for ProxyCommand parameter
username=self._auth_user,
password=self._auth_password,
hostkey_verify=hostkey_verify,
Expand Down
Loading