Changeset 2684 for package_branches/invirt-web/cherrypy-rebased
- Timestamp:
- Dec 20, 2009, 9:45:14 PM (15 years ago)
- Location:
- package_branches/invirt-web/cherrypy-rebased/code
- Files:
-
- 1 added
- 1 deleted
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
package_branches/invirt-web/cherrypy-rebased/code/controls.py
r2295 r2684 205 205 raise 206 206 207 def commandResult(username, state, fields):207 def commandResult(username, state, command_name, machine_id, fields): 208 208 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 212 214 if cdrom is not None and not CDROM.query().filter_by(cdrom_id=cdrom).one(): 213 215 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(" "): 216 217 raise CodeError("Invalid action '%s'" % action) 217 if action == ' Reboot':218 if action == 'reboot': 218 219 if cdrom is not None: 219 220 out, err = remctl('control', machine.name, 'reboot', cdrom, … … 231 232 raise CodeError('ERROR on remctl') 232 233 233 elif action == ' Power on':234 elif action == 'create': 234 235 if validation.maxMemory(username, state, machine) < machine.memory: 235 236 raise InvalidInput('action', 'Power on', … … 237 238 "to turn on this machine.") 238 239 bootMachine(machine, cdrom) 239 elif action == ' Power off':240 elif action == 'destroy': 240 241 out, err = remctl('control', machine.name, 'destroy', err=True) 241 242 if err: … … 247 248 print >> sys.stderr, err 248 249 raise CodeError('ERROR on remctl') 249 elif action == ' Shutdown':250 elif action == 'shutdown': 250 251 out, err = remctl('control', machine.name, 'shutdown', err=True) 251 252 if err: … … 257 258 print >> sys.stderr, err 258 259 raise CodeError('ERROR on remctl') 259 elif action == ' Delete VM':260 elif action == 'delete': 260 261 deleteVM(machine) 261 262 -
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, -
package_branches/invirt-web/cherrypy-rebased/code/templates/info.mako
r2683 r2684 29 29 <%def name="command_button(title, value, cdrom=False, extra='')"> 30 30 <form action="machine/${machine.machine_id}/command/${value}" method="POST"> 31 <input type="hidden" name="back" value=" machine/${machine.machine_id}/info" />31 <input type="hidden" name="back" value="info" /> 32 32 <input type="submit" class="button" name="action" value="${title}" ${extra | n}/> 33 33 % if cdrom: -
package_branches/invirt-web/cherrypy-rebased/code/templates/list.mako
r2682 r2684 85 85 <tr> 86 86 <td rowspan="2"> 87 <form action=" command" method="post">87 <form action="machine/${machine.machine_id}/command/${'shutdown' if machine.uptime else 'create'}" method="post"> 88 88 <input type="hidden" name="back" value="list"/> 89 89 <input type="hidden" name="machine_id" 90 90 value="${machine.machine_id}"/> 91 <input type="submit" class="power ${'on' if machine.uptime else 'off'}" name="action" value="${' Power off' if machine.uptime else 'Power on'}"\91 <input type="submit" class="power ${'on' if machine.uptime else 'off'}" name="action" value="${'Shutdown' if machine.uptime else 'Power on'}"\ 92 92 % if machine.uptime: 93 93 onclick="return confirm('Are you sure you want to power off this VM?');"
Note: See TracChangeset
for help on using the changeset viewer.