configurize some web code
authorGreg Price <price@mit.edu>
Tue, 5 Aug 2008 02:16:16 +0000 (22:16 -0400)
committerGreg Price <price@mit.edu>
Tue, 5 Aug 2008 02:16:16 +0000 (22:16 -0400)
svn path=/trunk/packages/sipb-xen-www/; revision=863

code/cache_acls.py
code/controls.py
code/main.py

index 9f8d66a..130f359 100644 (file)
@@ -1,5 +1,5 @@
 #!/usr/bin/python
 #!/usr/bin/python
-from sipb_xen_database import *
+from invirt.database import *
 import sys
 import getafsgroups
 import subprocess
 import sys
 import getafsgroups
 import subprocess
@@ -67,5 +67,5 @@ def refreshCache():
         raise
 
 if __name__ == '__main__':
         raise
 
 if __name__ == '__main__':
-    connect('postgres://sipb-xen@sipb-xen-dev/sipb_xen')
+    connect()
     refreshCache()
     refreshCache()
index b4740d4..d4cc13b 100644 (file)
@@ -2,7 +2,6 @@
 Functions to perform remctls.
 """
 
 Functions to perform remctls.
 """
 
-from sipb_xen_database import Machine, Disk, Type, NIC, CDROM, ctx, meta
 import validation
 from webcommon import CodeError, InvalidInput
 import random
 import validation
 from webcommon import CodeError, InvalidInput
 import random
@@ -13,6 +12,9 @@ import re
 import cache_acls
 import yaml
 
 import cache_acls
 import yaml
 
+from invirt.config import structs as config
+from invirt.database import Machine, Disk, Type, NIC, CDROM, ctx, meta
+
 # ... and stolen from xend/uuid.py
 def randomUUID():
     """Generate a random UUID."""
 # ... and stolen from xend/uuid.py
 def randomUUID():
     """Generate a random UUID."""
@@ -25,10 +27,10 @@ def uuidToString(u):
                      "%02x" * 6]) % tuple(u)
 # end stolen code
 
                      "%02x" * 6]) % tuple(u)
 # end stolen code
 
-def kinit(username = 'daemon/sipb-xen.mit.edu', keytab = '/etc/sipb-xen.keytab'):
+def kinit():
     """Kinit with a given username and keytab"""
     """Kinit with a given username and keytab"""
-
-    p = subprocess.Popen(['kinit', "-k", "-t", keytab, username],
+    p = subprocess.Popen(['kinit', "-k", "-t", '/etc/invirt/keytab',
+                          'daemon/'+config.web.hostname],
                          stderr=subprocess.PIPE)
     e = p.wait()
     if e:
                          stderr=subprocess.PIPE)
     e = p.wait()
     if e:
@@ -46,7 +48,7 @@ def remctl(*args, **kws):
     kinits if necessary, and outputs errors to stderr.
     """
     checkKinit()
     kinits if necessary, and outputs errors to stderr.
     """
     checkKinit()
-    p = subprocess.Popen(['remctl', 'remote.mit.edu']
+    p = subprocess.Popen(['remctl', config.remote.hostname]
                          + list(args),
                          stdout=subprocess.PIPE,
                          stderr=subprocess.PIPE)
                          + list(args),
                          stdout=subprocess.PIPE,
                          stderr=subprocess.PIPE)
index 03d7eb1..a9e54a8 100755 (executable)
@@ -34,15 +34,15 @@ if __name__ == '__main__':
 
 import templates
 from Cheetah.Template import Template
 
 import templates
 from Cheetah.Template import Template
-import sipb_xen_database
-from sipb_xen_database import Machine, CDROM, ctx, connect, MachineAccess, Type, Autoinstall
 import validation
 import cache_acls
 from webcommon import InvalidInput, CodeError, State
 import controls
 from getafsgroups import getAfsGroupMembers
 import validation
 import cache_acls
 from webcommon import InvalidInput, CodeError, State
 import controls
 from getafsgroups import getAfsGroupMembers
-import invirt.config
-invirt_config = invirt.config.load()
+import sipb_xen_database
+from invirt import database
+from sipb_xen_database import Machine, CDROM, ctx, connect, MachineAccess, Type, Autoinstall
+from invirt.config import structs as config
 
 def pathSplit(path):
     if path.startswith('/'):
 
 def pathSplit(path):
     if path.startswith('/'):
@@ -259,8 +259,7 @@ def vnc(username, state, path, fields):
     token = base64.urlsafe_b64encode(token)
     host = controls.listHost(machine)
     if host:
     token = base64.urlsafe_b64encode(token)
     host = controls.listHost(machine)
     if host:
-        port = 10003 + [config_host["hostname"] for config_host in invirt_config["hosts"]
-            ].index(host)
+        port = 10003 + [h.hostname for h in config.hosts].index(host)
     else:
         port = 5900 # dummy
 
     else:
         port = 5900 # dummy
 
@@ -284,7 +283,7 @@ def getHostname(nic):
     if nic.hostname and '.' in nic.hostname:
         return nic.hostname
     elif nic.machine:
     if nic.hostname and '.' in nic.hostname:
         return nic.hostname
     elif nic.machine:
-        return nic.machine.name + '.xvm.mit.edu'
+        return nic.machine.name + '.' + config.dns.domains[0]
     else:
         return None
 
     else:
         return None
 
@@ -441,8 +440,8 @@ def helpHandler(username, state, path, fields):
     help_mapping = {'ParaVM Console': """
 ParaVM machines do not support local console access over VNC.  To
 access the serial console of these machines, you can SSH with Kerberos
     help_mapping = {'ParaVM Console': """
 ParaVM machines do not support local console access over VNC.  To
 access the serial console of these machines, you can SSH with Kerberos
-to console.xvm.mit.edu, using the name of the machine as your
-username.""",
+to console.%s, using the name of the machine as your
+username.""" % config.dns.domains[0],
                     'HVM/ParaVM': """
 HVM machines use the virtualization features of the processor, while
 ParaVM machines use Xen's emulation of virtualization features.  You
                     'HVM/ParaVM': """
 HVM machines use the virtualization features of the processor, while
 ParaVM machines use Xen's emulation of virtualization features.  You
@@ -631,13 +630,13 @@ def printHeaders(headers):
 def send_error_mail(subject, body):
     import subprocess
 
 def send_error_mail(subject, body):
     import subprocess
 
-    to = 'xvm@mit.edu'
+    to = config.web.errormail
     mail = """To: %s
     mail = """To: %s
-From: root@xvm.mit.edu
+From: root@%s
 Subject: %s
 
 %s
 Subject: %s
 
 %s
-""" % (to, subject, body)
+""" % (to, config.web.hostname, subject, body)
     p = subprocess.Popen(['/usr/sbin/sendmail', to], stdin=subprocess.PIPE)
     p.stdin.write(mail)
     p.stdin.close()
     p = subprocess.Popen(['/usr/sbin/sendmail', to], stdin=subprocess.PIPE)
     p.stdin.write(mail)
     p.stdin.close()
@@ -732,7 +731,7 @@ class App:
             yield '<pre>%s</pre>' % cgi.escape(str(checkpoint))
 
 def constructor():
             yield '<pre>%s</pre>' % cgi.escape(str(checkpoint))
 
 def constructor():
-    connect('postgres://sipb-xen@sipb-xen-dev.mit.edu/sipb_xen')
+    connect()
     return App
 
 def main():
     return App
 
 def main():