From 2125e869604558b82c61dfc788400a9a29fcc791 Mon Sep 17 00:00:00 2001 From: Eric Price Date: Sat, 21 Jun 2008 21:23:59 -0400 Subject: [PATCH] Autoinstalls svn path=/trunk/packages/sipb-xen-www/; revision=629 --- code/controls.py | 18 +++++++++++++++--- code/main.py | 13 +++---------- code/templates/list.tmpl | 14 ++------------ code/validation.py | 10 ++++------ 4 files changed, 24 insertions(+), 31 deletions(-) diff --git a/code/controls.py b/code/controls.py index bb6c590..050b365 100644 --- a/code/controls.py +++ b/code/controls.py @@ -69,6 +69,18 @@ def makeDisks(machine): for disk in machine.disks: lvcreate(machine, disk) +def getswap(disksize, memsize): + """Returns the recommended swap partition size.""" + return int(min(disksize / 4, memsize * 1.5)) + +def lvinstall(machine, autoinstall): + disksize = machine.disks[0].size + memsize = machine.memory + imagesize = disksize - getswap(disksize, memsize) + ip = machine.nics[0].ip + remctl('web', 'install', machine.name, autoinstall.distribution, + autoinstall.mirror, str(imagesize), ip) + def lvcopy(machine_orig_name, machine, rootpw): """Copy a golden image onto a machine's disk""" remctl('web', 'lvcopy', machine_orig_name, machine.name, rootpw) @@ -92,7 +104,7 @@ def bootMachine(machine, cdtype): raise CodeError('"%s" on "control %s create %s' % (err, machine.name, cdtype)) -def createVm(username, state, owner, contact, name, description, memory, disksize, machine_type, cdrom, clone_from): +def createVm(username, state, owner, contact, name, description, memory, disksize, machine_type, cdrom, autoinstall): """Create a VM and put it in the database""" # put stuff in the table transaction = ctx.current.create_transaction() @@ -130,8 +142,8 @@ def createVm(username, state, owner, contact, name, description, memory, disksiz transaction.rollback() raise makeDisks(machine) - if clone_from: - lvcopy(clone_from, machine, 'password') + if autoinstall: + lvinstall(machine, autoinstall) # tell it to boot with cdrom bootMachine(machine, cdrom) return machine diff --git a/code/main.py b/code/main.py index 1fbe0d0..91ce41f 100755 --- a/code/main.py +++ b/code/main.py @@ -31,8 +31,6 @@ if __name__ == '__main__': import atexit atexit.register(printError) -sys.path.append('/home/ecprice/.local/lib/python2.5/site-packages') - import templates from Cheetah.Template import Template import sipb_xen_database @@ -136,12 +134,12 @@ def hasVnc(status): return False def parseCreate(username, state, fields): - kws = dict([(kw, fields.getfirst(kw)) for kw in 'name description owner memory disksize vmtype cdrom clone_from'.split()]) + kws = dict([(kw, fields.getfirst(kw)) for kw in 'name description owner memory disksize vmtype cdrom autoinstall'.split()]) validate = validation.Validate(username, state, strict=True, **kws) return dict(contact=username, name=validate.name, description=validate.description, memory=validate.memory, disksize=validate.disksize, owner=validate.owner, machine_type=validate.vmtype, cdrom=getattr(validate, 'cdrom', None), - clone_from=getattr(validate, 'clone_from', None)) + autoinstall=getattr(validate, 'autoinstall', None)) def create(username, state, fields): """Handler for create requests.""" @@ -625,12 +623,7 @@ def show_error(op, username, fields, err, emsg, traceback): def getUser(environ): """Return the current user based on the SSL environment variables""" - email = environ.get('SSL_CLIENT_S_DN_Email', None) - if email is None: - return None - if not email.endswith('@MIT.EDU'): - return None - return email[:-8] + return environ.get('REMOTE_USER', None) class App: def __init__(self, environ, start_response): diff --git a/code/templates/list.tmpl b/code/templates/list.tmpl index 61eafdb..a72c558 100644 --- a/code/templates/list.tmpl +++ b/code/templates/list.tmpl @@ -66,20 +66,10 @@ $vmTypeList($defaults.type) #filter None $errorRow('vmtype', $err) #end filter - - Clone image? -#if $can_clone - - (experimental; 1-2 minutes, and you have an etch machine; root pw is 'password'.) - -#else - Image cloning is currently disabled for maintenance -#end if - #filter None $errorRow('autoinstall', $err) #end filter - + Boot CD diff --git a/code/validation.py b/code/validation.py index dc0fd8c..8f81625 100644 --- a/code/validation.py +++ b/code/validation.py @@ -4,7 +4,7 @@ import cache_acls import getafsgroups import re import string -from sipb_xen_database import Machine, NIC, Type, Disk, CDROM +from sipb_xen_database import Machine, NIC, Type, Disk, CDROM, Autoinstall from webcommon import InvalidInput MAX_MEMORY_TOTAL = 512 @@ -19,7 +19,7 @@ MAX_VMS_ACTIVE = 4 class Validate: def __init__(self, username, state, machine_id=None, name=None, description=None, owner=None, admin=None, contact=None, memory=None, disksize=None, - vmtype=None, cdrom=None, clone_from=None, strict=False): + vmtype=None, cdrom=None, autoinstall=None, strict=False): # XXX Successive quota checks aren't a good idea, since you # can't necessarily change the locker and disk size at the # same time. @@ -65,10 +65,8 @@ class Validate: if not CDROM.get(cdrom): raise CodeError("Invalid cdrom type '%s'" % cdrom) self.cdrom = cdrom - if clone_from is not None: - if clone_from not in ('ice3', ): - raise CodeError("Invalid clone image '%s'" % clone_from) - self.clone_from = clone_from + if autoinstall is not None: + self.autoinstall = Autoinstall.get(autoinstall) def getMachinesByOwner(owner, machine=None): -- 1.7.9.5