示例#1
0
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}
示例#2
0
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}
示例#3
0
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}