diff options
author | Parantapa Bhattacharya <pb@parantapa.net> | 2013-01-06 23:41:54 +0530 |
---|---|---|
committer | Jeff Forcier <jeff@bitprophet.org> | 2013-02-27 19:03:49 -0800 |
commit | 2f1daad1b9dfb2a8ff38795d5b3a1d95765a0ea4 (patch) | |
tree | c2e3aa9e855286a6b4080c33450242754f1ff9a0 | |
parent | e034a24f87ca24171fceb9f9069149f3fc76d51b (diff) |
Compute host's FQDN on demand only
-rw-r--r-- | paramiko/config.py | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/paramiko/config.py b/paramiko/config.py index d1ce9490..9c15e18f 100644 --- a/paramiko/config.py +++ b/paramiko/config.py @@ -28,6 +28,18 @@ import socket SSH_PORT = 22 proxy_re = re.compile(r"^(proxycommand)\s*=*\s*(.*)", re.I) +class LazyFqdn(object): + """ + Returns the host's fqdn on request as string. + """ + + def __init__(self): + self.fqdn = None + + def __str__(self): + if self.fqdn is None: + self.fqdn = socket.getfqdn() + return self.fqdn class SSHConfig (object): """ @@ -155,7 +167,7 @@ class SSHConfig (object): remoteuser = user host = socket.gethostname().split('.')[0] - fqdn = socket.getfqdn() + fqdn = LazyFqdn() homedir = os.path.expanduser('~') replacements = { 'controlpath': [ @@ -184,5 +196,6 @@ class SSHConfig (object): for k in config: if k in replacements: for find, replace in replacements[k]: + if find in config[k]: config[k] = config[k].replace(find, str(replace)) return config |