X-Git-Url: http://xvm.mit.edu/gitweb/invirt/packages/invirt-web.git/blobdiff_plain/4663602deda7a8c90d59c8d3a57cd5a3945d73ca..7077ad5224ba9f02964a1afa0045ef67d2bc956f:/main.py diff --git a/main.py b/main.py index e7412ba..a3c84ee 100755 --- a/main.py +++ b/main.py @@ -13,7 +13,6 @@ import sys import time from StringIO import StringIO - def revertStandardError(): """Move stderr to stdout, and return the contents of the old stderr.""" errio = sys.stderr @@ -37,7 +36,7 @@ sys.path.append('/home/ecprice/.local/lib/python2.5/site-packages') import templates from Cheetah.Template import Template -from sipb_xen_database import Machine, CDROM, ctx, connect +from sipb_xen_database import Machine, CDROM, ctx, connect, MachineAccess import validation from webcommon import InvalidInput, CodeError, g import controls @@ -147,10 +146,10 @@ def parseCreate(user, fields): owner = validation.testOwner(user, fields.getfirst('owner')) memory = fields.getfirst('memory') - memory = validation.validMemory(user, memory, on=True) + memory = validation.validMemory(owner, memory, on=True) - disk = fields.getfirst('disk') - disk = validation.validDisk(user, disk) + disk_size = fields.getfirst('disk') + disk_size = validation.validDisk(owner, disk_size) vm_type = fields.getfirst('vmtype') if vm_type not in ('hvm', 'paravm'): @@ -160,7 +159,7 @@ def parseCreate(user, fields): cdrom = fields.getfirst('cdrom') if cdrom is not None and not CDROM.get(cdrom): raise CodeError("Invalid cdrom type '%s'" % cdrom) - return dict(contact=user, name=name, memory=memory, disk=disk, + return dict(contact=user, name=name, memory=memory, disk_size=disk_size, owner=owner, is_hvm=is_hvm, cdrom=cdrom) def create(user, fields): @@ -184,8 +183,7 @@ def create(user, fields): def getListDict(user): - machines = [m for m in Machine.select() - if validation.haveAccess(user, m)] + machines = g.machines checkpoint.checkpoint('Got my machines') on = {} has_vnc = {} @@ -271,6 +269,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. @@ -286,8 +293,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: @@ -320,8 +326,8 @@ def command(user, fields): except InvalidInput, err: if not back: raise - print >> sys.stderr, err - result = None + #print >> sys.stderr, err + result = err else: result = 'Success!' if not back: @@ -337,8 +343,7 @@ def command(user, fields): d['result'] = result return templates.info(searchList=[d]) else: - raise InvalidInput - ('back', back, 'Not a known back page.') + raise InvalidInput('back', back, 'Not a known back page.') def modifyDict(user, fields): olddisk = {} @@ -572,11 +577,8 @@ def printHeaders(headers): def getUser(): """Return the current user based on the SSL environment variables""" - if 'SSL_CLIENT_S_DN_Email' in os.environ: - username = os.environ['SSL_CLIENT_S_DN_Email'].split("@")[0] - return username - else: - return 'moo' + username = os.environ['SSL_CLIENT_S_DN_Email'].split("@")[0] + return username def main(operation, user, fields): start_time = time.time() @@ -637,7 +639,8 @@ if __name__ == '__main__': if not operation: operation = 'list' - #main(operation, u, fields) - import profile - profile.run('main(operation, u, fields)', 'log-'+operation) - + if os.getenv("SIPB_XEN_PROFILE"): + import profile + profile.run('main(operation, u, fields)', 'log-'+operation) + else: + main(operation, u, fields)