netutils: Normalize all FQDNs
authorMichael Hanselmann <hansmi@google.com>
Thu, 20 Dec 2012 09:53:36 +0000 (10:53 +0100)
committerMichael Hanselmann <hansmi@google.com>
Thu, 20 Dec 2012 10:37:42 +0000 (11:37 +0100)
Addresses issue 147. Only the hostnames resolved using
“netutils.Hostname($name)” were normalized, but those returned by the
class method “GetSysName” weren't.

Signed-off-by: Michael Hanselmann <hansmi@google.com>
Reviewed-by: Helga Velroyen <helgav@google.com>

lib/netutils.py

index 7ced860..3b76588 100644 (file)
@@ -167,7 +167,7 @@ class Hostname:
     @param name: hostname or None
 
     """
-    self.name = self.GetNormalizedName(self.GetFqdn(name))
+    self.name = self.GetFqdn(name)
     self.ip = self.GetIP(self.name, family=family)
 
   @classmethod
@@ -177,8 +177,8 @@ class Hostname:
     """
     return cls.GetFqdn()
 
-  @staticmethod
-  def GetFqdn(hostname=None):
+  @classmethod
+  def GetFqdn(cls, hostname=None):
     """Return fqdn.
 
     If hostname is None the system's fqdn is returned.
@@ -192,11 +192,13 @@ class Hostname:
     if hostname is None:
       virtfqdn = vcluster.GetVirtualHostname()
       if virtfqdn:
-        return virtfqdn
+        result = virtfqdn
       else:
-        return socket.getfqdn()
+        result = socket.getfqdn()
     else:
-      return socket.getfqdn(hostname)
+      result = socket.getfqdn(hostname)
+
+    return cls.GetNormalizedName(result)
 
   @staticmethod
   def GetIP(hostname, family=None):