X-Git-Url: http://xvm.mit.edu/gitweb/invirt/packages/invirt-web.git/blobdiff_plain/4663602deda7a8c90d59c8d3a57cd5a3945d73ca..fe18346ed6628e4e900ef9ab1105cdabbb94abd3:/controls.py diff --git a/controls.py b/controls.py index 3671f21..b6f6dec 100644 --- a/controls.py +++ b/controls.py @@ -74,10 +74,20 @@ def bootMachine(machine, cdtype): id of the CD (e.g. 'gutsy_i386') """ if cdtype is not None: - remctl('control', machine.name, 'create', - cdtype) + out, err = remctl('control', machine.name, 'create', + cdtype, err=True) else: - remctl('control', machine.name, 'create') + out, err = remctl('control', machine.name, 'create', + err=True) + if 'already exists' in out: + raise InvalidInput('action', 'create', + 'VM %s is already on' % machine.name) + elif err: + raise CodeError('"%s" on "control %s create %s' + % (err, machine.name, cdtype)) + else: + raise CodeError('"%s" on "control %s create %s' + % (err, machine.name, cdtype)) def registerMachine(machine): """Register a machine to be controlled by the web interface""" @@ -87,13 +97,13 @@ def unregisterMachine(machine): """Unregister a machine to not be controlled by the web interface""" remctl('web', 'unregister', machine.name) -def createVm(owner, contact, name, memory, disk, is_hvm, cdrom): +def createVm(owner, contact, name, memory, disk_size, is_hvm, cdrom): """Create a VM and put it in the database""" # put stuff in the table transaction = ctx.current.create_transaction() try: validation.validMemory(owner, memory) - validation.validDisk(owner, disk * 1. / 1024) + validation.validDisk(owner, disk_size * 1. / 1024) validation.validAddVm(owner) res = meta.engine.execute('select nextval(' '\'"machines_machine_id_seq"\')') @@ -110,8 +120,8 @@ def createVm(owner, contact, name, memory, disk, is_hvm, cdrom): machine_type = Type.get_by(hvm=is_hvm) machine.type_id = machine_type.type_id ctx.current.save(machine) - disk = Disk(machine.machine_id, - 'hda', disk) + disk = Disk(machine_id=machine.machine_id, + guest_device_name='hda', size=disk_size) open_nics = NIC.select_by(machine_id=None) if not open_nics: #No IPs left! raise CodeError("No IP addresses left! " @@ -201,6 +211,8 @@ def deleteVM(machine): ctx.current.save(nic) for disk in machine.disks: ctx.current.delete(disk) + for access in machine.acl: + ctx.current.delete(access) ctx.current.delete(machine) transaction.commit() except: @@ -212,11 +224,9 @@ def deleteVM(machine): def commandResult(user, fields): start_time = 0 - print >> sys.stderr, time.time()-start_time machine = validation.testMachineId(user, fields.getfirst('machine_id')) action = fields.getfirst('action') cdrom = fields.getfirst('cdrom') - print >> sys.stderr, time.time()-start_time if cdrom is not None and not CDROM.get(cdrom): raise CodeError("Invalid cdrom type '%s'" % cdrom) if action not in ('Reboot', 'Power on', 'Power off', 'Shutdown', @@ -266,7 +276,6 @@ def commandResult(user, fields): raise CodeError('ERROR on remctl') elif action == 'Delete VM': deleteVM(machine) - print >> sys.stderr, time.time()-start_time d = dict(user=user, command=action,