pldm_visualise_pdrs.py: add jump host support
A jump host allows tunneling an ssh connection through an intermediate
server. Enabling this means using any ProxyCommand host directives from
an ssh config if one exists, and feeding that to paramiko.
Change-Id: Ic4aa6c765a6fe9a0bcb790d1bce23fa9c49de419
Signed-off-by: Brad Bishop <bradleyb@fuzziesquirrel.com>
diff --git a/tools/visualize-pdr/pldm_visualise_pdrs.py b/tools/visualize-pdr/pldm_visualise_pdrs.py
index d337ef0..1e05ff0 100755
--- a/tools/visualize-pdr/pldm_visualise_pdrs.py
+++ b/tools/visualize-pdr/pldm_visualise_pdrs.py
@@ -13,7 +13,7 @@
import os
-def connect_to_bmc(hostname, uname, passwd, port):
+def connect_to_bmc(hostname, uname, passwd, port, **kw):
""" This function is responsible to connect to the BMC via
ssh and returns a client object.
@@ -28,7 +28,7 @@
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
- client.connect(hostname, username=uname, password=passwd, port=port)
+ client.connect(hostname, username=uname, password=passwd, port=port, **kw)
return client
@@ -330,6 +330,7 @@
default=22)
args = parser.parse_args()
+ extra_cfg = {}
try:
with open(os.path.expanduser("~/.ssh/config")) as f:
ssh_config = paramiko.SSHConfig()
@@ -340,10 +341,14 @@
args.bmc = host_config['hostname']
if 'user' in host_config and args.user is None:
args.user = host_config['user']
+ if 'proxycommand' in host_config:
+ extra_cfg['sock'] = paramiko.ProxyCommand(
+ host_config['proxycommand'])
except FileNotFoundError:
pass
- client = connect_to_bmc(args.bmc, args.user, args.password, args.port)
+ client = connect_to_bmc(
+ args.bmc, args.user, args.password, args.port, **extra_cfg)
association_pdr, state_sensor_pdr, state_effecter_pdr, counter = \
fetch_pdrs_from_bmc(client)
draw_entity_associations(association_pdr, counter)