update to match current error messages
[invirt/packages/invirt-web.git] / code / main.py
index 2740a74..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])
 
@@ -341,7 +347,7 @@ def command(username, state, path, fields):
     elif back == 'info':
         machine = validation.Validate(username, state, machine_id=fields.getfirst('machine_id')).machine
         return ({'Status': '303 See Other',
-                 'Location': '/info?machine_id=%d' % machine.machine_id},
+                 'Location': 'info?machine_id=%d' % machine.machine_id},
                 "You shouldn't see this message.")
     else:
         raise InvalidInput('back', back, 'Not a known back page.')
@@ -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)'),
@@ -585,6 +593,10 @@ def unauthFront(_, _2, _3, fields):
     return templates.unauth(searchList=[{'simple' : True}])
 
 def overlord(username, state, path, fields):
+    if path == '':
+        return ({'Status': '303 See Other',
+                 'Location': 'overlord/'},
+                "You shouldn't see this message.")
     if not username in getAfsGroupMembers('system:xvm', 'athena.mit.edu'):
         raise InvalidInput('username', username, 'Not an overlord.')
     newstate = State(username, overlord=True)
@@ -659,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()
@@ -666,8 +680,7 @@ class App:
         fields = cgi.FieldStorage(fp=self.environ['wsgi.input'], environ=self.environ)
         operation = self.environ.get('PATH_INFO', '')
         if not operation:
-            self.start("301 Moved Permanently", [('Location',
-                                                  self.environ['SCRIPT_NAME']+'/')])
+            self.start("301 Moved Permanently", [('Location', './')])
             return
         if self.username is None:
             operation = 'unauth'