X-Git-Url: http://xvm.mit.edu/gitweb/invirt/packages/invirt-web.git/blobdiff_plain/606c843a867528a38bdc58bcdea8c657be5de5fa..89e13567a64d63163ca622fb8e45be5f3ca6d443:/code/controls.py diff --git a/code/controls.py b/code/controls.py index d152627..911c41a 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) @@ -98,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) @@ -112,11 +110,15 @@ def createVm(username, state, owner, contact, name, description, memory, disksiz 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():