summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorOlle Lundberg <geek@nerd.sh>2012-03-30 14:08:14 +0200
committerJeff Forcier <jeff@bitprophet.org>2012-09-23 16:19:29 -0700
commit697524a79f2ca4e09248e455493d1bc684e63c06 (patch)
tree96991df43c02676db3aab49824b0ec50f450a153
parent76e7dc0335b5852b364a549282fbe076ff7042a8 (diff)
Add basic support for parameter substitution in SSHConfig.
(cherry picked from commit fb24d79695f83e14edc0ccd7ed2c0ca30ee8cde8)
-rw-r--r--paramiko/config.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/paramiko/config.py b/paramiko/config.py
index 2a2cbff3..d30080ad 100644
--- a/paramiko/config.py
+++ b/paramiko/config.py
@@ -106,5 +106,27 @@ class SSHConfig (object):
ret = {}
for m in matches:
ret.update(m)
+ ret = self._expand_variables(ret, hostname)
del ret['host']
return ret
+
+ def _expand_variables(self, config, hostname ):
+ """
+ Return a dict of config options with expanded substitutions
+ for a given hostname.
+
+ For the moment only expansion of the %h substitution in the
+ hostname config is supported.
+
+ @param config: the config for the hostname
+ @type hostname: dict
+ @param hostname: the hostname that the config belongs to
+ @type hostname: str
+ """
+ #TODO: Add support for expansion of all substitution parameters
+ #TODO: see man ssh_config(5)
+ if 'hostname' in config:
+ config['hostname'] = config['hostname'].replace('%h',hostname)
+ else:
+ config['hostname'] = hostname
+ return config