First part of confd timer changes
[ganeti-local] / lib / netutils.py
index 48d0f98..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):
@@ -229,7 +231,12 @@ class Hostname:
     try:
       return result[0][4][0]
     except IndexError, err:
-      raise errors.ResolverError("Unknown error in getaddrinfo(): %s" % err)
+      # we don't have here an actual error code, it's just that the
+      # data type returned by getaddrinfo is not what we expected;
+      # let's keep the same format in the exception arguments with a
+      # dummy error code
+      raise errors.ResolverError(hostname, 0,
+                                 "Unknown error in getaddrinfo(): %s" % err)
 
   @classmethod
   def GetNormalizedName(cls, hostname):