Ignore:
Timestamp:
Dec 20, 2009, 9:45:14 PM (14 years ago)
Author:
broder
Message:

Make commands work from list and info pages

File:
1 edited

Legend:

Unmodified
Added
Removed
  • package_branches/invirt-web/cherrypy-rebased/code/controls.py

    r2295 r2684  
    205205        raise
    206206
    207 def commandResult(username, state, fields):
     207def commandResult(username, state, command_name, machine_id, fields):
    208208    start_time = 0
    209     machine = validation.Validate(username, state, machine_id=fields.getfirst('machine_id')).machine
    210     action = fields.getfirst('action')
    211     cdrom = fields.getfirst('cdrom')
     209    machine = validation.Validate(username, state, machine_id=machine_id).machine
     210    action = command_name
     211    cdrom = fields.get('cdrom')
     212    if not cdrom:
     213        cdrom = None
    212214    if cdrom is not None and not CDROM.query().filter_by(cdrom_id=cdrom).one():
    213215        raise CodeError("Invalid cdrom type '%s'" % cdrom)   
    214     if action not in ('Reboot', 'Power on', 'Power off', 'Shutdown',
    215                       'Delete VM'):
     216    if action not in "reboot create destroy shutdown delete".split(" "):
    216217        raise CodeError("Invalid action '%s'" % action)
    217     if action == 'Reboot':
     218    if action == 'reboot':
    218219        if cdrom is not None:
    219220            out, err = remctl('control', machine.name, 'reboot', cdrom,
     
    231232                raise CodeError('ERROR on remctl')
    232233               
    233     elif action == 'Power on':
     234    elif action == 'create':
    234235        if validation.maxMemory(username, state, machine) < machine.memory:
    235236            raise InvalidInput('action', 'Power on',
     
    237238                               "to turn on this machine.")
    238239        bootMachine(machine, cdrom)
    239     elif action == 'Power off':
     240    elif action == 'destroy':
    240241        out, err = remctl('control', machine.name, 'destroy', err=True)
    241242        if err:
     
    247248                print >> sys.stderr, err
    248249                raise CodeError('ERROR on remctl')
    249     elif action == 'Shutdown':
     250    elif action == 'shutdown':
    250251        out, err = remctl('control', machine.name, 'shutdown', err=True)
    251252        if err:
     
    257258                print >> sys.stderr, err
    258259                raise CodeError('ERROR on remctl')
    259     elif action == 'Delete VM':
     260    elif action == 'delete':
    260261        deleteVM(machine)
    261262
Note: See TracChangeset for help on using the changeset viewer.