示例#1
0
def delete_partitions(name):
    if not BlockadeManager.blockade_exists(name):
        abort(404)

    b = BlockadeManager.get_blockade(name)
    b.join()
    return '', 204
示例#2
0
def action(name):
    if not request.headers['Content-Type'] == 'application/json':
        abort(415)

    if not BlockadeManager.blockade_exists(name):
        abort(404)

    commands = ['start', 'stop', 'restart', 'kill']
    data = request.get_json()
    command = data.get('command')
    container_names = data.get('container_names')
    if command is None:
        return "'command' not found in body", 400
    if command not in commands:
        error_str = "'%s' is not a valid action" % command
        return error_str, 400
    if container_names is None:
        return "'container_names' not found in body", 400

    b = BlockadeManager.get_blockade(name)
    if 'kill' == command:
        signal = request.args.get('signal', 'SIGKILL')
        getattr(b, command)(container_names, signal=signal)
    else:
        getattr(b, command)(container_names)

    return '', 204
示例#3
0
def status(name):
    if not BlockadeManager.blockade_exists(name):
        abort(404, "The blockade %s does not exist" % name)

    containers = {}
    b = BlockadeManager.get_blockade(name)
    for container in b.status():
        containers[container.name] = container.to_dict()

    return jsonify(containers=containers)
示例#4
0
def destroy(name):
    if not BlockadeManager.blockade_exists(name):
        abort(404)

    b = BlockadeManager.get_blockade(name)
    b.destroy()

    BlockadeManager.delete_config(name)

    return '', 204
示例#5
0
def destroy(name):
    if not BlockadeManager.blockade_exists(name):
        abort(404)

    b = BlockadeManager.get_blockade(name)
    b.destroy()

    BlockadeManager.delete_config(name)

    return '', 204
示例#6
0
def chaos_new(name):
    if not BlockadeManager.blockade_exists(name):
        abort(404, "The blockade %s does not exist" % name)
    if not request.headers['Content-Type'] == 'application/json':
        abort(415, "The body is not in JSON format")
    options = request.get_json()
    _validate_chaos_input(options)
    try:
        _chaos.new_chaos(BlockadeManager.get_blockade(name), name, **options)
        return "Successfully started chaos on %s" % name, 201
    except errors.BlockadeUsageError as bue:
        app.logger.error(str(bue))
        return bue.http_msg, bue.http_code
示例#7
0
def get_events(name):
    if not BlockadeManager.blockade_exists(name):
        abort(404, "The blockade %s does not exist" % name)

    b = BlockadeManager.get_blockade(name)

    def generate():
        yield '{"events": ['
        for a in b.get_audit().read_logs(as_json=False):
            yield a
        yield ']}'

    return Response(generate(), mimetype='application/json')
示例#8
0
def add(name):
    if not request.headers['Content-Type'] == 'application/json':
        abort(415)

    if not BlockadeManager.blockade_exists(name):
        abort(404)

    data = request.get_json()
    containers = data.get('containers')
    b = BlockadeManager.get_blockade(name)
    b.add_container(containers)

    return '', 204
示例#9
0
def create(name):
    if not request.headers['Content-Type'] == 'application/json':
        abort(415)

    if BlockadeManager.blockade_exists(name):
        return 'Blockade name already exists', 400

    # This will abort with a 400 if the JSON is bad
    data = request.get_json()
    config = BlockadeConfig.from_dict(data)
    BlockadeManager.store_config(name, config)

    b = BlockadeManager.get_blockade(name)
    containers = b.create()

    return '', 204
示例#10
0
def destroy(name):
    if not BlockadeManager.blockade_exists(name):
        abort(404)

    if _chaos.exists(name):
        try:
            _chaos.delete(name)
        except errors.BlockadeUsageError as bue:
            app.logger.error(bue)

    b = BlockadeManager.get_blockade(name)
    b.destroy()
    b.get_audit().clean()
    BlockadeManager.delete_config(name)

    return '', 204
示例#11
0
def network_state(name):
    if not request.headers['Content-Type'] == 'application/json':
        abort(415)

    if not BlockadeManager.blockade_exists(name):
        abort(404)

    network_states = ['flaky', 'slow', 'fast', 'duplicate']
    data = request.get_json()
    network_state = data.get('network_state')
    container_names = data.get('container_names')
    if network_state is None:
        return "'network_state' not found in body", 400
    if network_state not in network_states:
        error_str = "'%s' is not a valid network state" % network_state
        return error_str, 400
    if container_names is None:
        return "'container_names' not found in body", 400

    b = BlockadeManager.get_blockade(name)
    getattr(b, network_state)(container_names)

    return '', 204
示例#12
0
def partitions(name):
    if not request.headers['Content-Type'] == 'application/json':
        abort(415)

    if not BlockadeManager.blockade_exists(name):
        abort(404)

    b = BlockadeManager.get_blockade(name)

    if request.args.get('random', False):
        b.random_partition()
        return '', 204

    data = request.get_json()
    partitions = data.get('partitions')
    if partitions is None:
        return "'partitions' not found in body", 400
    for partition in partitions:
        if not isinstance(partition, list):
            return "'partitions' must be a list of lists", 400
    b.partition(partitions)

    return '', 204