- Timestamp:
- Dec 20, 2009, 9:45:14 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
package_branches/invirt-web/cherrypy-rebased/code/main.py
r2680 r2684 59 59 @cherrypy.expose 60 60 @cherrypy.tools.mako(filename="/list.mako") 61 def list(self ):61 def list(self, result=None): 62 62 """Handler for list requests.""" 63 63 checkpoint.checkpoint('Getting list dict') 64 64 d = getListDict(cherrypy.request.login, cherrypy.request.state) 65 if result is not None: 66 d['result'] = result 65 67 checkpoint.checkpoint('Got list dict') 66 68 return d … … 215 217 authtoken=token) 216 218 return d 219 @cherrypy.expose 220 @cherrypy.tools.mako(filename="/command.mako") 221 def command(self, command_name, machine_id, **kwargs): 222 """Handler for running commands like boot and delete on a VM.""" 223 if cherrypy.request.method != "POST": 224 raise InvalidInput("request.method", command_name, "You must execute commands via POST") 225 back = kwargs.get('back', None) 226 try: 227 d = controls.commandResult(cherrypy.request.login, cherrypy.request.state, command_name, machine_id, kwargs) 228 if d['command'] == 'Delete VM': 229 back = 'list' 230 except InvalidInput, err: 231 if not back: 232 raise 233 print >> sys.stderr, err 234 result = err 235 else: 236 result = 'Success!' 237 if not back: 238 return d 239 if back == 'list': 240 cherrypy.request.state.clear() #Changed global state 241 raise cherrypy.InternalRedirect('/list?result=%s' % urllib.quote(result)) 242 elif back == 'info': 243 raise cherrypy.HTTPRedirect(cherrypy.request.base + '/machine/%d/' % machine_id, status=303) 244 else: 245 raise InvalidInput('back', back, 'Not a known back page.') 217 246 218 247 machine = MachineView() … … 432 461 return disk_fields 433 462 434 def command(username, state, path, fields):435 """Handler for running commands like boot and delete on a VM."""436 back = fields.getfirst('back')437 try:438 d = controls.commandResult(username, state, fields)439 if d['command'] == 'Delete VM':440 back = 'list'441 except InvalidInput, err:442 if not back:443 raise444 print >> sys.stderr, err445 result = err446 else:447 result = 'Success!'448 if not back:449 return templates.command(searchList=[d])450 if back == 'list':451 state.clear() #Changed global state452 d = getListDict(username, state)453 d['result'] = result454 return templates.list(searchList=[d])455 elif back == 'info':456 machine = validation.Validate(username, state, machine_id=fields.getfirst('machine_id')).machine457 return ({'Status': '303 See Other',458 'Location': 'info?machine_id=%d' % machine.machine_id},459 "You shouldn't see this message.")460 else:461 raise InvalidInput('back', back, 'Not a known back page.')462 463 463 def modifyDict(username, state, fields): 464 464 """Modify a machine as specified by CGI arguments. … … 652 652 653 653 mapping = dict( 654 command=command,655 654 modify=modify, 656 655 create=create,
Note: See TracChangeset
for help on using the changeset viewer.