From e11cdd5476f7f1a456ece94862c211a1b83b093c Mon Sep 17 00:00:00 2001 From: Greg Price Date: Mon, 4 Aug 2008 22:16:16 -0400 Subject: [PATCH] configurize some web code svn path=/trunk/packages/sipb-xen-www/; revision=863 --- code/cache_acls.py | 4 ++-- code/controls.py | 12 +++++++----- code/main.py | 25 ++++++++++++------------- 3 files changed, 21 insertions(+), 20 deletions(-) diff --git a/code/cache_acls.py b/code/cache_acls.py index 9f8d66a..130f359 100644 --- a/code/cache_acls.py +++ b/code/cache_acls.py @@ -1,5 +1,5 @@ #!/usr/bin/python -from sipb_xen_database import * +from invirt.database import * import sys import getafsgroups import subprocess @@ -67,5 +67,5 @@ def refreshCache(): raise if __name__ == '__main__': - connect('postgres://sipb-xen@sipb-xen-dev/sipb_xen') + connect() refreshCache() diff --git a/code/controls.py b/code/controls.py index b4740d4..d4cc13b 100644 --- a/code/controls.py +++ b/code/controls.py @@ -2,7 +2,6 @@ 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 @@ -13,6 +12,9 @@ import re 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.""" @@ -25,10 +27,10 @@ def uuidToString(u): "%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""" - - 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: @@ -46,7 +48,7 @@ def remctl(*args, **kws): 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) diff --git a/code/main.py b/code/main.py index 03d7eb1..a9e54a8 100755 --- a/code/main.py +++ b/code/main.py @@ -34,15 +34,15 @@ if __name__ == '__main__': 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 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('/'): @@ -259,8 +259,7 @@ def vnc(username, state, path, fields): 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 @@ -284,7 +283,7 @@ def getHostname(nic): 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 @@ -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 -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 @@ -631,13 +630,13 @@ def printHeaders(headers): def send_error_mail(subject, body): import subprocess - to = 'xvm@mit.edu' + to = config.web.errormail mail = """To: %s -From: root@xvm.mit.edu +From: root@%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() @@ -732,7 +731,7 @@ class App: yield '
%s
' % cgi.escape(str(checkpoint)) def constructor(): - connect('postgres://sipb-xen@sipb-xen-dev.mit.edu/sipb_xen') + connect() return App def main(): -- 1.7.9.5