Allow fully qualified domains in the NICs table to override the
authorEric Price <ecprice@mit.edu>
Tue, 11 Dec 2007 07:23:21 +0000 (02:23 -0500)
committerEric Price <ecprice@mit.edu>
Tue, 11 Dec 2007 07:23:21 +0000 (02:23 -0500)
name.servers.csail.mit.edu domains.

svn path=/trunk/web/; revision=252

main.py

diff --git a/main.py b/main.py
index ab626e2..e182095 100755 (executable)
--- a/main.py
+++ b/main.py
@@ -274,6 +274,15 @@ def vnc(user, fields):
              authtoken=token)
     return templates.vnc(searchList=[d])
 
+def getHostname(nic):
+    if nic.hostname and '.' in nic.hostname:
+        return nic.hostname
+    elif nic.machine:
+        return nic.machine.name + '.servers.csail.mit.edu'
+    else:
+        return None
+
+
 def getNicInfo(data_dict, machine):
     """Helper function for info, get data on nics for a machine.
 
@@ -289,8 +298,7 @@ def getNicInfo(data_dict, machine):
     for i in range(len(machine.nics)):
         nic_fields.extend([(x % i, y % i) for x, y in nic_fields_template])
         if not i:
-            data_dict['nic%s_hostname' % i] = (machine.name + 
-                                               '.servers.csail.mit.edu')
+            data_dict['nic%s_hostname' % i] = getHostname(machine.nics[i])
         data_dict['nic%s_mac' % i] = machine.nics[i].mac_addr
         data_dict['nic%s_ip' % i] = machine.nics[i].ip
     if len(machine.nics) == 1: