X-Git-Url: http://xvm.mit.edu/gitweb/invirt/packages/invirt-web.git/blobdiff_plain/2fb52b912876c89ec4f93ab296bf514e966b0ce1..de0b2b5b417d9d70283458dbc5307fd0f4d1e701:/controls.py diff --git a/controls.py b/controls.py index 2e9b541..7134668 100644 --- a/controls.py +++ b/controls.py @@ -10,6 +10,7 @@ import subprocess import sys import time import re +import cache_acls # ... and stolen from xend/uuid.py def randomUUID(): @@ -74,10 +75,17 @@ 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)) def registerMachine(machine): """Register a machine to be controlled by the web interface""" @@ -121,6 +129,7 @@ def createVm(owner, contact, name, memory, disk_size, is_hvm, cdrom): nic.hostname = name ctx.current.save(nic) ctx.current.save(disk) + cache_acls.refreshMachine(machine) transaction.commit() except: transaction.rollback() @@ -214,11 +223,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', @@ -268,7 +275,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,