Commit f3044516 authored by Manuel Franceschini's avatar Manuel Franceschini

Make Hostname object always intialize its name to fqdn

This patch restores the behaviour of Hostname (previously known as
HostInfo) to always use fqdn. This was broken due to the fact that the
now used getaddrinfo does not return an fqdn in contrast to
gethostbyname_ex().

This patch adds Hostname.GetFqdn() which is always used when
initializing a Hostname object.

A problem this solves is when adding a node and not using its fqdn, node
verify won't complain.
Signed-off-by: default avatarManuel Franceschini <livewire@google.com>
Reviewed-by: default avatarMichael Hanselmann <hansmi@google.com>
parent edcd876b
......@@ -98,20 +98,32 @@ class Hostname:
@param name: hostname or None
"""
if name is None:
name = self.GetSysName()
self.name = self.GetNormalizedName(name)
self.name = self.GetNormalizedName(self.GetFqdn(name))
self.ip = self.GetIP(self.name, family=family)
@classmethod
def GetSysName(cls):
"""Legacy method the get the current system's name.
"""
return cls.GetFqdn()
@staticmethod
def GetSysName():
"""Return the current system's name.
def GetFqdn(hostname=None):
"""Return fqdn.
This is simply a wrapper over C{socket.gethostname()}.
If hostname is None the system's fqdn is returned.
@type hostname: str
@param hostname: name to be fqdn'ed
@rtype: str
@return: fqdn of given name, if it exists, unmodified name otherwise
"""
return socket.gethostname()
if hostname is None:
return socket.getfqdn()
else:
return socket.getfqdn(hostname)
@staticmethod
def GetIP(hostname, family=None):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment