Skip to content

Commit

Permalink
Compute host's FQDN on demand only
Browse files Browse the repository at this point in the history
  • Loading branch information
parantapa authored and bitprophet committed Feb 28, 2013
1 parent e034a24 commit 2f1daad
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion paramiko/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,18 @@
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):
"""
Expand Down Expand Up @@ -155,7 +167,7 @@ def _expand_variables(self, config, hostname ):
remoteuser = user

host = socket.gethostname().split('.')[0]
fqdn = socket.getfqdn()
fqdn = LazyFqdn()
homedir = os.path.expanduser('~')
replacements = {
'controlpath': [
Expand Down Expand Up @@ -184,5 +196,6 @@ def _expand_variables(self, config, hostname ):
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

0 comments on commit 2f1daad

Please sign in to comment.