X-Git-Url: http://xvm.mit.edu/gitweb/invirt/packages/invirt-web.git/blobdiff_plain/c8d4c0b540095113a4c605b445536050791ba7c9..d5c709a5a9d53bbff6fae1e3eab6e0a4acf294bf:/code/main.py?ds=inline diff --git a/code/main.py b/code/main.py index 47f9b01..656c209 100755 --- a/code/main.py +++ b/code/main.py @@ -150,6 +150,31 @@ console will suffer artifacts. return {'request': cherrypy.request, 'kwargs': kwargs} helloworld._cp_config['tools.require_login.on'] = False + class MachineView(View): + # This is hairy. Fix when CherryPy 3.2 is out. (rename to + # _cp_dispatch, and parse the argument as a list instead of + # string + + def __getattr__(self, name): + try: + machine_id = int(name) + cherrypy.request.params['machine_id'] = machine_id + return self + except ValueError: + return None + + @cherrypy.expose + @cherrypy.tools.mako(filename="/info.mako") + def info(self, machine_id): + """Handler for info on a single VM.""" + machine = validation.Validate(cherrypy.request.login, cherrypy.request.state, machine_id=machine_id).machine + d = infoDict(cherrypy.request.login, cherrypy.request.state, machine) + checkpoint.checkpoint('Got infodict') + return d + index = info + + machine = MachineView() + def pathSplit(path): if path.startswith('/'): path = path[1:] @@ -605,13 +630,6 @@ def infoDict(username, state, machine): fields = fields) return d -def info(username, state, path, fields): - """Handler for info on a single VM.""" - machine = validation.Validate(username, state, machine_id=fields.getfirst('machine_id')).machine - d = infoDict(username, state, machine) - checkpoint.checkpoint('Got infodict') - return templates.info(searchList=[d]) - def unauthFront(_, _2, _3, fields): """Information for unauth'd users.""" return templates.unauth(searchList=[{'simple' : True, @@ -636,7 +654,6 @@ def throwError(_, __, ___, ____): mapping = dict(vnc=vnc, command=command, modify=modify, - info=info, create=create, unauth=unauthFront, admin=admin,