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)
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()
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
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
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."""
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):
#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
(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>
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
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.
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):