def doPost(role, command): # execute command if role is None or command is None: abort(404) if request.content_type != JSON_MIME_TYPE: error = json.dumps({'error': 'Invalid Content Type'}) return json_response(error, 400) data = request.json # concurrency:int, timeout:int , role:str, data:{} commandEntity = Command(role, command, data, data.get('concurrency'), data.get('timeout')) switcher = { "run": apiService.run, "pause": apiService.pause, "restart": apiService.restart, "stop": apiService.stop } func = switcher.get(command, lambda: "Invalid command") # Execute the function result = func(commandEntity) # Execute the function content = json.dumps(result, cls=MyEncoder) return content, 200, {'Content-Type': JSON_MIME_TYPE}
def doAll(command): if command is None: abort(404) switcher = { "run": apiService.run, "pause": apiService.pause, "restart": apiService.restart, "stop": apiService.stop } commandEntity = Command("all", command, None, 5, 10) func = switcher.get(command, lambda: "Invalid command") # Execute the function result = func(commandEntity) content = json.dumps(result) return content, 200, {'Content-Type': JSON_MIME_TYPE}
def doGet(role, command): # execute command if role is None or command is None: abort(404) # concurrency:int, timeout:int , role:str, data:{} commandEntity = Command(role, command, None, 5, 10) switcher = { "run": apiService.run, "pause": apiService.pause, "restart": apiService.restart, "stop": apiService.stop } func = switcher.get(command, lambda: "Invalid command") # Execute the function result = func(commandEntity) # Execute the function content = json.dumps(result, cls=MyEncoder) return content, 200, {'Content-Type': JSON_MIME_TYPE}