netutils: Use virtual hostname if set
authorMichael Hanselmann <hansmi@google.com>
Thu, 20 Sep 2012 16:50:56 +0000 (18:50 +0200)
committerMichael Hanselmann <hansmi@google.com>
Fri, 21 Sep 2012 12:44:49 +0000 (14:44 +0200)
This enables the hostname seen by other code through Hostname.GetFqdn to
be changed through the environment variable “GANETI_HOSTNAME”.

Signed-off-by: Michael Hanselmann <hansmi@google.com>
Reviewed-by: René Nussbaumer <rn@google.com>

lib/netutils.py

index 42f8e8b..48d0f98 100644 (file)
@@ -38,6 +38,7 @@ import logging
 from ganeti import constants
 from ganeti import errors
 from ganeti import utils
+from ganeti import vcluster
 
 # Structure definition for getsockopt(SOL_SOCKET, SO_PEERCRED, ...):
 # struct ucred { pid_t pid; uid_t uid; gid_t gid; };
@@ -189,7 +190,11 @@ class Hostname:
 
     """
     if hostname is None:
-      return socket.getfqdn()
+      virtfqdn = vcluster.GetVirtualHostname()
+      if virtfqdn:
+        return virtfqdn
+      else:
+        return socket.getfqdn()
     else:
       return socket.getfqdn(hostname)