Index: package_branches/invirt-web/cherrypy-rebased/code/main.py =================================================================== --- package_branches/invirt-web/cherrypy-rebased/code/main.py (revision 2690) +++ package_branches/invirt-web/cherrypy-rebased/code/main.py (revision 2691) @@ -219,4 +219,26 @@ return d index = info + + @cherrypy.expose + @cherrypy.tools.mako(filename="/info.mako") + @cherrypy.tools.require_POST() + def modify(self, machine_id, **fields): + """Handler for modifying attributes of a machine.""" + try: + modify_dict = modifyDict(cherrypy.request.login, cherrypy.request.state, machine_id, fields) + except InvalidInput, err: + result = None + machine = validation.Validate(cherrypy.request.login, cherrypy.request.state, machine_id=machine_id).machine + else: + machine = modify_dict['machine'] + result = 'Success!' + err = None + info_dict = infoDict(cherrypy.request.login, cherrypy.request.state, machine) + info_dict['err'] = err + if err: + for field in fields.keys(): + setattr(info_dict['defaults'], field, fields.get(field)) + info_dict['result'] = result + return info_dict @cherrypy.expose @@ -350,4 +372,5 @@ name = '' description = '' + administrator = '' type = 'linux-hvm' @@ -481,13 +504,14 @@ return disk_fields -def modifyDict(username, state, fields): +def modifyDict(username, state, machine_id, fields): """Modify a machine as specified by CGI arguments. - Return a list of local variables for modify.tmpl. + Return a dict containing the machine that was modified. """ olddisk = {} session.begin() try: - kws = dict([(kw, fields.getfirst(kw)) for kw in 'machine_id owner admin contact name description memory vmtype disksize'.split()]) + kws = dict([(kw, fields.get(kw)) for kw in 'owner admin contact name description memory vmtype disksize'.split() if fields.get(kw)]) + kws['machine_id'] = machine_id validate = validation.Validate(username, state, **kws) machine = validate.machine @@ -536,26 +560,6 @@ if hasattr(validate, 'name'): controls.renameMachine(machine, oldname, validate.name) - return dict(user=username, - command="modify", - machine=machine) - -def modify(username, state, path, fields): - """Handler for modifying attributes of a machine.""" - try: - modify_dict = modifyDict(username, state, fields) - except InvalidInput, err: - result = None - machine = validation.Validate(username, state, machine_id=fields.getfirst('machine_id')).machine - else: - machine = modify_dict['machine'] - result = 'Success!' - err = None - info_dict = infoDict(username, state, machine) - info_dict['err'] = err - if err: - for field in fields.keys(): - setattr(info_dict['defaults'], field, fields.getfirst(field)) - info_dict['result'] = result - return templates.info(searchList=[info_dict]) + return dict(machine=machine) + def badOperation(u, s, p, e): @@ -634,5 +638,6 @@ defaults = Defaults() for name in 'machine_id name description administrator owner memory contact'.split(): - setattr(defaults, name, getattr(machine, name)) + if getattr(machine, name): + setattr(defaults, name, getattr(machine, name)) defaults.type = machine.type.type_id defaults.disk = "%0.2f" % (machine.disks[0].size/1024.) @@ -656,5 +661,4 @@ mapping = dict( - modify=modify, unauth=unauthFront) Index: package_branches/invirt-web/cherrypy-rebased/code/templates/info.mako =================================================================== --- package_branches/invirt-web/cherrypy-rebased/code/templates/info.mako (revision 2690) +++ package_branches/invirt-web/cherrypy-rebased/code/templates/info.mako (revision 2691) @@ -60,5 +60,5 @@ (To edit ram, disk size, or machine name, turn off the machine first.) % endif -