Autoinstalls
authorEric Price <ecprice@mit.edu>
Sun, 22 Jun 2008 01:23:59 +0000 (21:23 -0400)
committerEric Price <ecprice@mit.edu>
Sun, 22 Jun 2008 01:23:59 +0000 (21:23 -0400)
svn path=/trunk/packages/sipb-xen-www/; revision=629

code/controls.py
code/main.py
code/templates/list.tmpl
code/validation.py

index bb6c590..050b365 100644 (file)
@@ -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
index 1fbe0d0..91ce41f 100755 (executable)
@@ -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):
index 61eafdb..a72c558 100644 (file)
@@ -66,20 +66,10 @@ $vmTypeList($defaults.type)
 #filter None
 $errorRow('vmtype', $err)
 #end filter
-        <tr>
-          <td>Clone image?</td>
-#if $can_clone
-          <td><input type="checkbox" name="clone_from" id="clone_from" value="ice3" onchange="onclone(event)"/>
-              (experimental; 1-2 minutes, and you have an etch machine; root pw is 'password'.)
-              <script type='text/javascript'>function onclone(e){ document.getElementById('cdromlist').value = ''; }</script></td>
-#else
-         <td><input type="checkbox" name="clone_from" id="clone_from" value="ice3" disabled="disabled"/> Image cloning is currently disabled for maintenance</td>
-#end if
-        </tr>
 #filter None
 $errorRow('autoinstall', $err)
 #end filter
-       <!--<tr>
+       <tr>
          <td>Autoinstall#slurp
 #filter None
 $helppopup('Autoinstall')#slurp
@@ -91,7 +81,7 @@ $autoList($defaults.cdrom, "document.getElementById('cd_or_auto_auto').checked =
              (experimental; 1-2 minutes, and you have a machine; root pw is 'password'.)
 #end filter
          </input>
-       </tr>-->
+       </tr>
        <tr>
          <td>Boot CD</td>
          <td><input type="radio" name="cd_or_auto" id="cd_or_auto_cd" checked>
index dc0fd8c..8f81625 100644 (file)
@@ -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):