def checkFilterParameters(data): """Checks and extracts filter rule parameters from a request body. @return: the checked parameters: (priority, predicates, action). """ if not isinstance(data, dict): raise http.HttpBadRequest("Invalid body contents, not a dictionary") # Forbid unknown parameters allowed_params = set(["priority", "predicates", "action", "reason"]) for param in data: if param not in allowed_params: raise http.HttpBadRequest( "Invalid body parameters: filter rule doesn't" " support the parameter '%s'" % param) priority = baserlib.CheckParameter(data, "priority", exptype=int, default=0) # We leave the deeper check into the predicates list to the server. predicates = baserlib.CheckParameter(data, "predicates", exptype=list, default=[]) # The action can be a string or a list; we leave the check to the server. action = baserlib.CheckParameter(data, "action", default="CONTINUE") reason = baserlib.CheckParameter(data, "reason", exptype=list, default=[]) return (priority, predicates, action, reason)
def _ParseInstanceReinstallRequest(name, data): """Parses a request for reinstalling an instance. """ if not isinstance(data, dict): raise http.HttpBadRequest("Invalid body contents, not a dictionary") ostype = baserlib.CheckParameter(data, "os", default=None) start = baserlib.CheckParameter(data, "start", exptype=bool, default=True) osparams = baserlib.CheckParameter(data, "osparams", default=None) ops = [ opcodes.OpInstanceShutdown(instance_name=name), opcodes.OpInstanceReinstall(instance_name=name, os_type=ostype, osparams=osparams), ] if start: ops.append(opcodes.OpInstanceStartup(instance_name=name, force=False)) return ops