-def commandResult(username, state, fields):
+def commandResult(username, state, command_name, machine_id, fields):
- machine = validation.Validate(username, state, machine_id=fields.getfirst('machine_id')).machine
- action = fields.getfirst('action')
- cdrom = fields.getfirst('cdrom')
+ machine = validation.Validate(username, state, machine_id=machine_id).machine
+ action = command_name
+ cdrom = fields.get('cdrom') or None
if cdrom is not None and not CDROM.query().filter_by(cdrom_id=cdrom).one():
raise CodeError("Invalid cdrom type '%s'" % cdrom)
if cdrom is not None and not CDROM.query().filter_by(cdrom_id=cdrom).one():
raise CodeError("Invalid cdrom type '%s'" % cdrom)
if cdrom is not None:
out, err = remctl('control', machine.name, 'reboot', cdrom,
err=True)
if cdrom is not None:
out, err = remctl('control', machine.name, 'reboot', cdrom,
err=True)
if validation.maxMemory(username, state, machine) < machine.memory:
raise InvalidInput('action', 'Power on',
"You don't have enough free RAM quota "
"to turn on this machine.")
bootMachine(machine, cdrom)
if validation.maxMemory(username, state, machine) < machine.memory:
raise InvalidInput('action', 'Power on',
"You don't have enough free RAM quota "
"to turn on this machine.")
bootMachine(machine, cdrom)
out, err = remctl('control', machine.name, 'destroy', err=True)
if err:
if re.match("machine '.*' is not on", err):
out, err = remctl('control', machine.name, 'destroy', err=True)
if err:
if re.match("machine '.*' is not on", err):
print >> sys.stderr, 'Error on power off:'
print >> sys.stderr, err
raise CodeError('ERROR on remctl')
print >> sys.stderr, 'Error on power off:'
print >> sys.stderr, err
raise CodeError('ERROR on remctl')
out, err = remctl('control', machine.name, 'shutdown', err=True)
if err:
if re.match("machine '.*' is not on", err):
out, err = remctl('control', machine.name, 'shutdown', err=True)
if err:
if re.match("machine '.*' is not on", err):
print >> sys.stderr, 'Error on Shutdown:'
print >> sys.stderr, err
raise CodeError('ERROR on remctl')
print >> sys.stderr, 'Error on Shutdown:'
print >> sys.stderr, err
raise CodeError('ERROR on remctl')