Changeset 2685 for package_branches/invirt-web
- Timestamp:
- Dec 20, 2009, 9:45:18 PM (15 years ago)
- Location:
- package_branches/invirt-web/cherrypy-rebased/code
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
package_branches/invirt-web/cherrypy-rebased/code/main.py
r2684 r2685 147 147 help._cp_config['tools.require_login.on'] = False 148 148 149 def parseCreate(self, fields): 150 kws = dict([(kw, fields.get(kw)) for kw in 'name description owner memory disksize vmtype cdrom autoinstall'.split()]) 151 validate = validation.Validate(cherrypy.request.login, cherrypy.request.state, strict=True, **kws) 152 return dict(contact=cherrypy.request.login, name=validate.name, description=validate.description, memory=validate.memory, 153 disksize=validate.disksize, owner=validate.owner, machine_type=getattr(validate, 'vmtype', Defaults.type), 154 cdrom=getattr(validate, 'cdrom', None), 155 autoinstall=getattr(validate, 'autoinstall', None)) 156 157 @cherrypy.expose 158 @cherrypy.tools.mako(filename="/list.mako") 159 @cherrypy.tools.require_POST() 160 def create(self, **fields): 161 """Handler for create requests.""" 162 try: 163 parsed_fields = self.parseCreate(fields) 164 machine = controls.createVm(cherrypy.request.login, cherrypy.request.state, **parsed_fields) 165 except InvalidInput, err: 166 pass 167 else: 168 err = None 169 cherrypy.request.state.clear() #Changed global state 170 d = getListDict(cherrypy.request.login, cherrypy.request.state) 171 d['err'] = err 172 if err: 173 for field in fields.keys(): 174 setattr(d['defaults'], field, fields.get(field)) 175 else: 176 d['new_machine'] = parsed_fields['name'] 177 return d 178 149 179 @cherrypy.expose 150 180 @cherrypy.tools.mako(filename="/helloworld.mako") … … 219 249 @cherrypy.expose 220 250 @cherrypy.tools.mako(filename="/command.mako") 251 @cherrypy.tools.require_POST() 221 252 def command(self, command_name, machine_id, **kwargs): 222 253 """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 254 back = kwargs.get('back', None) 226 255 try: … … 337 366 return 'location' in d 338 367 return False 339 340 def parseCreate(username, state, fields):341 kws = dict([(kw, fields.getfirst(kw)) for kw in 'name description owner memory disksize vmtype cdrom autoinstall'.split()])342 validate = validation.Validate(username, state, strict=True, **kws)343 return dict(contact=username, name=validate.name, description=validate.description, memory=validate.memory,344 disksize=validate.disksize, owner=validate.owner, machine_type=getattr(validate, 'vmtype', Defaults.type),345 cdrom=getattr(validate, 'cdrom', None),346 autoinstall=getattr(validate, 'autoinstall', None))347 348 def create(username, state, path, fields):349 """Handler for create requests."""350 try:351 parsed_fields = parseCreate(username, state, fields)352 machine = controls.createVm(username, state, **parsed_fields)353 except InvalidInput, err:354 pass355 else:356 err = None357 state.clear() #Changed global state358 d = getListDict(username, state)359 d['err'] = err360 if err:361 for field in fields.keys():362 setattr(d['defaults'], field, fields.getfirst(field))363 else:364 d['new_machine'] = parsed_fields['name']365 return templates.list(searchList=[d])366 368 367 369 … … 653 655 mapping = dict( 654 656 modify=modify, 655 create=create,656 657 unauth=unauthFront, 657 658 admin=admin, -
package_branches/invirt-web/cherrypy-rebased/code/view.py
r2673 r2685 83 83 cherrypy.tools.require_login = cherrypy.Tool('on_start_resource', require_login, priority=150) 84 84 85 def require_POST(): 86 """If the request isn't a POST request, raise 405 Method Not Allowed""" 87 if cherrypy.request.method != "POST": 88 raise cherrypy.HTTPError(405, 89 "You must submit this request with POST") 90 91 cherrypy.tools.require_POST = cherrypy.Tool('on_start_resource', require_POST, priority=150) 92 85 93 def remote_user_login(): 86 94 """Get the current user based on the SSL or GSSAPI environment variables"""
Note: See TracChangeset
for help on using the changeset viewer.