+def command(user, fields):
+ """Handler for running commands like boot and delete on a VM."""
+ back = fields.getfirst('back')
+ try:
+ d = commandResult(user, fields)
+ if d['command'] == 'Delete VM':
+ back = 'list'
+ except InvalidInput, err:
+ if not back:
+ raise
+ print >> sys.stderr, err
+ result = None
+ else:
+ result = 'Success!'
+ if not back:
+ return Template(file='command.tmpl', searchList=[d])
+ if back == 'list':
+ g.clear() #Changed global state
+ d = getListDict(user)
+ d['result'] = result
+ return Template(file='list.tmpl', searchList=[d])
+ elif back == 'info':
+ machine = testMachineId(user, fields.getfirst('machine_id'))
+ d = infoDict(user, machine)
+ d['result'] = result
+ return Template(file='info.tmpl', searchList=[d])
+ else:
+ raise InvalidInput('back', back, 'Not a known back page.')
+
+def testAdmin(user, admin, machine):
+ if admin in (None, machine.administrator):
+ return None
+ if admin == user.username:
+ return admin
+ if getafsgroups.checkAfsGroup(user.username, admin, 'athena.mit.edu'):
+ return admin
+ if getafsgroups.checkAfsGroup(user.username, 'system:'+admin,
+ 'athena.mit.edu'):
+ return 'system:'+admin
+ return admin
+ #raise InvalidInput('administrator', admin,
+ # 'You must control the group you move it to.')
+
+def testOwner(user, owner, machine):
+ if owner in (None, machine.owner):
+ return None