Пример #1
0
def get_port(bridge):
    #check if bridge exists on pc
    if len(str(sub_P01T2OpenvSwitch.bridge_pc(bridge))) == 0:
        abort(404)

    return jsonify(
        {'Port': sub_P01T2OpenvSwitch.get_ports(bridge).splitlines()})
Пример #2
0
def del_netflow(bridge):
    #check if bridge exists on pc
    if len(str(sub_P01T2OpenvSwitch.bridge_pc(bridge))) == 0:
        abort(404)

    sub_P01T2OpenvSwitch.del_netflow(bridge)

    return jsonify({'Result': True})
Пример #3
0
def get_netflow(bridge):
    #check if bridge exists on pc
    if len(str(sub_P01T2OpenvSwitch.bridge_pc(bridge))) == 0:
        abort(404)

    return jsonify({
        'Bridge':
        bridge,
        'Netflow':
        sub_P01T2OpenvSwitch.get_netflow(bridge).splitlines()
    })
Пример #4
0
def update_netflow(bridge):
    #check if bridge exists on pc
    if len(str(sub_P01T2OpenvSwitch.bridge_pc(bridge))) == 0:
        abort(404)

    if not request.json or not 'options' in request.json:
        abort(400)

    options = request.json['options']

    sub_P01T2OpenvSwitch.update_netflow(bridge, options)

    return jsonify({'Bridge': bridge, 'Options': options})
Пример #5
0
def add_netflow(bridge):
    #check if bridge exists on pc
    if len(str(sub_P01T2OpenvSwitch.bridge_pc(bridge))) == 0:
        abort(404)

    if not request.json or not 'target' in request.json:
        abort(400)
    if not request.json or not 'timeout' in request.json:
        abort(400)

    target = request.json['target']
    timeout = request.json['timeout']

    sub_P01T2OpenvSwitch.add_netflow(bridge, target, timeout)

    return jsonify({'Bridge': bridge, 'Target': target, 'Timeout': timeout})
Пример #6
0
def update_port(bridge, port):

    #check if bridge exist
    if len(str(sub_P01T2OpenvSwitch.bridge_pc(bridge))) == 0:
        abort(404)

    #check if port exist on bridge
    if len(str(sub_P01T2OpenvSwitch.port_bridge(bridge, port))) == 0:
        abort(404)

    if not request.json or not 'action' in request.json:
        abort(400)

    action = request.json['action']
    sub_P01T2OpenvSwitch.update_ports(bridge, port, action)
    return jsonify({'Bridge': bridge, 'Port': port, 'Action': action})
Пример #7
0
def del_mirror(bridge, mirror):

    #check if bridge exists
    if len(str(sub_P01T2OpenvSwitch.bridge_pc(bridge))) == 0:
        abort(404)

    #check if mirror exists
    if len(str(sub_P01T2OpenvSwitch.check_mirror(mirror))) == 0:
        abort(404)

    sub_P01T2OpenvSwitch.del_mirror(bridge, mirror)

    #check if mirror gets deleted successfully
    if len(str(sub_P01T2OpenvSwitch.check_mirror(mirror))) != 0:
        abort(400)

    return jsonify({'Result': True})
Пример #8
0
def add_port(bridge):

    #check if bridge already exists
    if len(str(sub_P01T2OpenvSwitch.bridge_pc(bridge))) == 0:
        abort(404)

    if not request.json:
        abort(400)

    if not 'port' in request.json or type(request.json['port']) != unicode:
        abort(400)

    port = request.json['port']

    #check if interface already exists on pc
    if len(str(sub_P01T2OpenvSwitch.int_pc(port))) == 0:
        abort(404)

    sub_P01T2OpenvSwitch.add_ports(bridge, port)
    return jsonify({'Bridge': bridge, 'Port': port}), 201
Пример #9
0
def del_port(bridge):

    #check if bridge exists
    if len(str(sub_P01T2OpenvSwitch.bridge_pc(bridge))) == 0:
        abort(404)

    if not request.json or not 'port' in request.json:
        abort(400)

    port = request.json['port']

    #check if port exists on bridge
    if len(str(sub_P01T2OpenvSwitch.port_bridge(bridge, port))) == 0:
        abort(404)

    sub_P01T2OpenvSwitch.del_ports(bridge, port)

    #check if delete was successful
    if len(str(sub_P01T2OpenvSwitch.port_bridge(bridge, port))) != 0:
        abort(404)

    return jsonify({'Result': True})
Пример #10
0
def update_mirror(bridge):

    #check if bridge already exists
    if len(str(sub_P01T2OpenvSwitch.bridge_pc(bridge))) == 0:
        abort(404)

    if not request.json or not 'port1' in request.json:
        abort(400)

    if not request.json or not 'port2' in request.json:
        abort(400)

    if not request.json or not 'port3' in request.json:
        abort(400)

    if not request.json or not 'port4' in request.json:
        abort(400)

    if not request.json or not 'name' in request.json:
        abort(400)

    if not request.json or not 'dest' in request.json:
        abort(400)

    if not request.json or not 'source' in request.json:
        abort(400)

    if not request.json or not 'output' in request.json:
        abort(400)

    port1 = request.json['port1']
    port2 = request.json['port2']
    port3 = request.json['port3']
    port4 = request.json['port4']
    name = request.json['name']
    dest = request.json['dest']
    source = request.json['source']
    output = request.json['output']

    #check if port already exists
    if len(str(sub_P01T2OpenvSwitch.int_pc(port2))) == 0:
        abort(404)

    if len(str(sub_P01T2OpenvSwitch.int_pc(port4))) == 0:
        abort(404)

    #check if port exist on bridge
    if len(str(sub_P01T2OpenvSwitch.port_bridge(bridge, port2))) == 0:
        abort(404)

    if len(str(sub_P01T2OpenvSwitch.port_bridge(bridge, port4))) == 0:
        abort(404)

    if port2 == port4:
        abort(400)

    sub_P01T2OpenvSwitch.add_mirror(bridge, port1, port2, port3, port4, name,
                                    dest, source, output)

    return jsonify({
        'Bridge': bridge,
        'Name': name,
        'Destination': dest,
        'Source': source,
        'Output': output
    })