pldm_visualise_pdrs.py: add support for ssh_config
Add support for parsing user ssh_configs. For now, this lets users
specify an ssh_config host entry with the --bmc parameter and the script
will pick up the hostname and user directives if they are specified in
the host entry. Like ssh itself, a --user option on the command line
overrides any user specified in the ssh_config host entry.
Change-Id: I4d564677424e984de033a1d15ca6d51342091772
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 95a72aa..d337ef0 100755
--- a/tools/visualize-pdr/pldm_visualise_pdrs.py
+++ b/tools/visualize-pdr/pldm_visualise_pdrs.py
@@ -10,6 +10,7 @@
import paramiko
from graphviz import Digraph
from tabulate import tabulate
+import os
def connect_to_bmc(hostname, uname, passwd, port):
@@ -328,6 +329,20 @@
parser.add_argument('--port', type=int, help="BMC SSH port",
default=22)
args = parser.parse_args()
+
+ try:
+ with open(os.path.expanduser("~/.ssh/config")) as f:
+ ssh_config = paramiko.SSHConfig()
+ ssh_config.parse(f)
+ host_config = ssh_config.lookup(args.bmc)
+ if host_config:
+ if 'hostname' in host_config:
+ args.bmc = host_config['hostname']
+ if 'user' in host_config and args.user is None:
+ args.user = host_config['user']
+ except FileNotFoundError:
+ pass
+
client = connect_to_bmc(args.bmc, args.user, args.password, args.port)
association_pdr, state_sensor_pdr, state_effecter_pdr, counter = \
fetch_pdrs_from_bmc(client)