+def command(user, fields):
+ """Handler for running commands like boot and delete on a VM."""
+ js = fields.getfirst('js')
+ try:
+ d = commandResult(user, fields)
+ except InvalidInput, err:
+ if not js:
+ raise
+ result = None
+ else:
+ err = None
+ result = 'Success!'
+ if not js:
+ return Template(file='command.tmpl', searchList=[d])
+ if js == 'list':
+ g.clear() #Changed global state
+ d = getListDict(user)
+ t = Template(file='list.tmpl', searchList=[d])
+ return JsonDict(createtable=t.createTable(),
+ machinelist=t.machineList(d['machines']),
+ result=result,
+ err=err)
+ elif js == 'info':
+ machine = testMachineId(user, fields.getfirst('machine_id'))
+ d = infoDict(user, machine)
+ t = Template(file='info.tmpl', searchList=[d])
+ return JsonDict(info=t.infoTable(),
+ commands=t.commands(),
+ modify=t.modifyForm(),
+ result=result,
+ err=err)
+ else:
+ raise InvalidInput('js', js, 'Not a known js type.')
+
+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
+ 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
+ value = getafsgroups.checkLockerOwner(user.username, owner, verbose=True)
+ if value == True:
+ return owner
+ raise InvalidInput('owner', owner, value)