Compute host's FQDN on demand only
This commit is contained in:
parent
e034a24f87
commit
2f1daad1b9
|
@ -28,6 +28,18 @@ import socket
|
||||||
SSH_PORT = 22
|
SSH_PORT = 22
|
||||||
proxy_re = re.compile(r"^(proxycommand)\s*=*\s*(.*)", re.I)
|
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):
|
class SSHConfig (object):
|
||||||
"""
|
"""
|
||||||
|
@ -155,7 +167,7 @@ class SSHConfig (object):
|
||||||
remoteuser = user
|
remoteuser = user
|
||||||
|
|
||||||
host = socket.gethostname().split('.')[0]
|
host = socket.gethostname().split('.')[0]
|
||||||
fqdn = socket.getfqdn()
|
fqdn = LazyFqdn()
|
||||||
homedir = os.path.expanduser('~')
|
homedir = os.path.expanduser('~')
|
||||||
replacements = {
|
replacements = {
|
||||||
'controlpath': [
|
'controlpath': [
|
||||||
|
@ -184,5 +196,6 @@ class SSHConfig (object):
|
||||||
for k in config:
|
for k in config:
|
||||||
if k in replacements:
|
if k in replacements:
|
||||||
for find, replace in replacements[k]:
|
for find, replace in replacements[k]:
|
||||||
|
if find in config[k]:
|
||||||
config[k] = config[k].replace(find, str(replace))
|
config[k] = config[k].replace(find, str(replace))
|
||||||
return config
|
return config
|
||||||
|
|
Loading…
Reference in New Issue