X-Git-Url: http://xvm.mit.edu/gitweb/invirt/packages/invirt-web.git/blobdiff_plain/e85742797d25cb0711381d3f2a00e948285e6e71..a6b3091d1a405ce7ece30be84596cd37afce4911:/code/controls.py diff --git a/code/controls.py b/code/controls.py index 4b9c6a4..e32b1c2 100644 --- a/code/controls.py +++ b/code/controls.py @@ -43,8 +43,6 @@ def getswap(disksize, memsize): return int(min(disksize / 4, memsize * 1.5)) def lvinstall(machine, autoinstall): - #raise InvalidInput('autoinstall', 'install', - # "The autoinstaller has been temporarily disabled") disksize = machine.disks[0].size memsize = machine.memory swapsize = getswap(disksize, memsize) @@ -53,6 +51,7 @@ def lvinstall(machine, autoinstall): remctl('control', machine.name, 'install', 'dist=%s' % autoinstall.distribution, 'mirror=%s' % autoinstall.mirror, + 'arch=%s' % autoinstall.arch, 'imagesize=%s' % imagesize) def lvcopy(machine_orig_name, machine, rootpw): @@ -89,7 +88,7 @@ def createVm(username, state, owner, contact, name, description, memory, disksiz machine.description = description machine.memory = memory machine.owner = owner - machine.administrator = owner + machine.administrator = None machine.contact = contact machine.uuid = uuidToString(randomUUID()) machine.boot_off_cd = True @@ -97,7 +96,7 @@ def createVm(username, state, owner, contact, name, description, memory, disksiz session.save_or_update(machine) disk = Disk(machine=machine, guest_device_name='hda', size=disksize) - nic = NIC.query().filter_by(machine_id=None).first() + nic = NIC.query().filter_by(machine_id=None).filter_by(reusable=True).first() if not nic: #No IPs left! raise CodeError("No IP addresses left! " "Contact %s." % config.web.errormail) @@ -106,16 +105,20 @@ def createVm(username, state, owner, contact, name, description, memory, disksiz session.save_or_update(nic) session.save_or_update(disk) cache_acls.refreshMachine(machine) + makeDisks(machine) session.commit() except: session.rollback() raise - makeDisks(machine) - if autoinstall: - lvinstall(machine, autoinstall) - else: - # tell it to boot with cdrom - bootMachine(machine, cdrom) + try: + if autoinstall: + lvinstall(machine, autoinstall) + else: + # tell it to boot with cdrom + bootMachine(machine, cdrom) + except CodeError, e: + deleteVM(machine) + raise return machine def getList():