web: support sx-blade-2 for VNC applet
[invirt/packages/invirt-web.git] / code / main.py
index 9d39df6..24254c7 100755 (executable)
@@ -11,6 +11,7 @@ import simplejson
 import sys
 import time
 import urllib
+import random
 from StringIO import StringIO
 
 def revertStandardError():
@@ -254,6 +255,10 @@ def vnc(username, state, path, fields):
     token = {'data': pickled_data, 'digest': m.digest()}
     token = cPickle.dumps(token)
     token = base64.urlsafe_b64encode(token)
+    if controls.listHost(machine) == 'sx-blade-2.mit.edu':
+        port = 10004
+    else:
+        port = 10003
 
     status = controls.statusInfo(machine)
     has_vnc = hasVnc(status)
@@ -263,6 +268,7 @@ def vnc(username, state, path, fields):
              has_vnc=has_vnc,
              machine=machine,
              hostname=state.environ.get('SERVER_NAME', 'localhost'),
+             port=port,
              authtoken=token)
     return templates.vnc(searchList=[d])
 
@@ -490,6 +496,7 @@ def infoDict(username, state, machine):
         cputime = None
     else:
         main_status = dict(status[1:])
+        main_status['host'] = controls.listHost(machine)
         start_time = float(main_status.get('start_time', 0))
         uptime = datetime.timedelta(seconds=int(time.time()-start_time))
         cpu_time_float = float(main_status.get('cpu_time', 0))
@@ -506,6 +513,7 @@ def infoDict(username, state, machine):
                       'NIC_INFO',
                       ('uptime', 'uptime'),
                       ('cputime', 'CPU usage'),
+                      ('host', 'Hosted on'),
                       ('memory', 'RAM'),
                       'DISK_INFO',
                       ('state', 'state (xen format)'),
@@ -663,6 +671,8 @@ class App:
         self.state = State(self.username)
         self.state.environ = environ
 
+        random.seed() #sigh
+
     def __iter__(self):
         start_time = time.time()
         sipb_xen_database.clear_cache()