diff --git a/lib/netutils.py b/lib/netutils.py index 132a7af1fe0bed355dc35d1f0c01170bf56d6bb2..509329eb7a23582e481e01959f951b7e037e9d38 100644 --- a/lib/netutils.py +++ b/lib/netutils.py @@ -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):