Commit 040072de authored by JorgeEcheva26's avatar JorgeEcheva26
Browse files

App samples

parent bfeb58a2
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -172,3 +172,5 @@ test/logs
.flake8

*.DS_store

netapp-samples/netapp-provider-sample/node_modules
 No newline at end of file
+140 −0
Original line number Diff line number Diff line
from flask import Flask, jsonify, request
from flask_jwt_extended import jwt_required, JWTManager
from werkzeug import serving

app = Flask(__name__)

# JWT Configuration
app.config['JWT_ALGORITHM'] = 'RS256'
app.config['JWT_PUBLIC_KEY'] = "YourPublicKeyHere"
jwt_flask = JWTManager(app)

# Dummy data for QoS, TSN, and Slicing management
qos_profiles = {
    "1": {"profileId": 1, "level": "high"},
    "2": {"profileId": 2, "level": "medium"}
}

tsn_profiles = {
    "profile1": {"name": "profile1", "config": "default"},
    "profile2": {"name": "profile2", "config": "custom"}
}

network_slices = {
    "slice1": {"sliceId": "slice1", "status": "active"},
    "slice2": {"sliceId": "slice2", "status": "inactive"}
}

### QoS Management Endpoints ###


@app.route("/<scsAsId>/qos", methods=["GET", "POST"])
@jwt_required()
def manage_qos(scsAsId):
    """Endpoint to manage QoS levels for network traffic"""
    if request.method == "GET":
        return jsonify({"message": "GET request for QoS management", "scsAsId": scsAsId})

    if request.method == "POST":
        data = request.get_json()
        return jsonify({"message": "POST request to manage QoS", "scsAsId": scsAsId, "data": data})


@app.route("/<scsAsId>/qos/<profileId>", methods=["GET", "PUT", "DELETE"])
@jwt_required()
def manage_single_qos_profile(scsAsId, profileId):
    """Endpoint to manage single QoS profile"""
    if request.method == "GET":
        profile = qos_profiles.get(profileId)
        if profile:
            return jsonify({"profile": profile, "scsAsId": scsAsId})
        return jsonify({"message": f"Profile {profileId} not found"}), 404

    if request.method == "PUT":
        data = request.get_json()
        qos_profiles[profileId] = data
        return jsonify({"message": f"Profile {profileId} updated", "scsAsId": scsAsId, "data": data})

    if request.method == "DELETE":
        if profileId in qos_profiles:
            del qos_profiles[profileId]
            return jsonify({"message": f"Profile {profileId} deleted"})
        return jsonify({"message": f"Profile {profileId} not found"}), 404

### TSN Management Endpoints ###


@app.route("/profile", methods=["GET"])
@jwt_required()
def list_tsn_profiles():
    """Endpoint for retrieving the list of available TSN profiles"""
    return jsonify({"profiles": tsn_profiles})


@app.route("/profile", methods=["GET"])
@jwt_required()
def tsn_profile_by_name():
    """Endpoint for retrieving information about a single TSN profile"""
    profile_name = request.args.get('name')
    profile = tsn_profiles.get(profile_name)
    if profile:
        return jsonify({"profile": profile})
    return jsonify({"message": f"Profile {profile_name} not found"}), 404


@app.route("/apply", methods=["POST"])
@jwt_required()
def apply_tsn_configuration():
    """Endpoint for configuring TSN connection parameters"""
    data = request.get_json()
    return jsonify({"message": "TSN configuration applied", "data": data})


@app.route("/clear", methods=["POST"])
@jwt_required()
def clear_tsn_configuration():
    """Endpoint for removing a previous TSN connection configuration"""
    return jsonify({"message": "TSN configuration cleared"})

### Network Slicing Management Endpoints ###


@app.route("/slice", methods=["GET", "POST"])
@jwt_required()
def manage_slices():
    """Endpoint for managing network slices"""
    if request.method == "GET":
        return jsonify({"slices": network_slices})

    if request.method == "POST":
        data = request.get_json()
        slice_id = f"slice{len(network_slices) + 1}"
        network_slices[slice_id] = data
        return jsonify({"message": "Network slice added", "sliceId": slice_id, "data": data})


@app.route("/slice/<sliceId>", methods=["GET", "PUT", "DELETE"])
@jwt_required()
def manage_single_slice(sliceId):
    """Endpoint for managing a single network slice"""
    if request.method == "GET":
        slice_ = network_slices.get(sliceId)
        if slice_:
            return jsonify({"slice": slice_})
        return jsonify({"message": f"Slice {sliceId} not found"}), 404

    if request.method == "PUT":
        data = request.get_json()
        network_slices[sliceId] = data
        return jsonify({"message": f"Slice {sliceId} updated", "data": data})

    if request.method == "DELETE":
        if sliceId in network_slices:
            del network_slices[sliceId]
            return jsonify({"message": f"Slice {sliceId} deleted"})
        return jsonify({"message": f"Slice {sliceId} not found"}), 404


# Starting the server
if __name__ == '__main__':
    serving.run_simple("0.0.0.0", 8888, app)
+6 −6
Original line number Diff line number Diff line
@@ -2,7 +2,7 @@
    "apiName": "6G-resilience",
    "aefProfiles": [
        {
            "aefId": "AEFc7416f23179329845f26ffdf895627",
            "aefId": "AEF63e3d024de52005e452d03d73f9755",
            "versions": [
                {
                    "apiVersion": "6G_Resilience_v1",
@@ -51,8 +51,8 @@
            ],
            "interfaceDescriptions": [
                {
                    "ipv4Addr": "127.0.0.1",
                    "port": 8899,
                    "ipv4Addr": "localhost",
                    "port": 8088,
                    "securityMethods": [
                        "Oauth"
                    ]
@@ -60,7 +60,7 @@
            ]
        },
        {
            "aefId": "AEFd8fcb1de1f053d282f3107672ac30b",
            "aefId": "AEF3988e5fec8a0bcff1ee4ec64453292",
            "versions": [
                {
                    "apiVersion": "6G_Resilience_v1",
@@ -110,8 +110,8 @@
            ],
            "interfaceDescriptions": [
                {
                    "ipv4Addr": "127.0.0.1",
                    "port": 8877,
                    "ipv4Addr": "localhost",
                    "port": 8088,
                    "securityMethods": [
                        "Oauth"
                    ]
+8 −8
Original line number Diff line number Diff line
@@ -2,7 +2,7 @@
    "apiName": "5G-NetApp-API",
    "aefProfiles": [
        {
            "aefId": "AEFc7416f23179329845f26ffdf895627",
            "aefId": "AEF63e3d024de52005e452d03d73f9755",
            "versions": [
                {
                    "apiVersion": "QoS_v1",
@@ -52,7 +52,7 @@
            ],
            "interfaceDescriptions": [
                {
                    "ipv4Addr": "127.0.0.1",
                    "ipv4Addr": "localhost",
                    "port": 8888,
                    "securityMethods": [
                        "Oauth"
@@ -61,7 +61,7 @@
            ]
        },
        {
            "aefId": "AEFd8fcb1de1f053d282f3107672ac30b",
            "aefId": "AEF3988e5fec8a0bcff1ee4ec64453292",
            "versions": [
                {
                    "apiVersion": "TSN_v1",
@@ -127,8 +127,8 @@
            ],
            "interfaceDescriptions": [
                {
                    "ipv4Addr": "127.0.0.1",
                    "port": 8899,
                    "ipv4Addr": "localhost",
                    "port": 8888,
                    "securityMethods": [
                        "Oauth"
                    ]
@@ -136,7 +136,7 @@
            ]
        },
        {
            "aefId": "AEF862b574b97f78ac88d2dfa00c6dc7b",
            "aefId": "AEFe21f6b078ecc8ba89630ab8f90f656",
            "versions": [
                {
                    "apiVersion": "NetworkSlicing_v1",
@@ -186,8 +186,8 @@
            ],
            "interfaceDescriptions": [
                {
                    "ipv4Addr": "127.0.0.1",
                    "port": 8877,
                    "ipv4Addr": "localhost",
                    "port": 8888,
                    "securityMethods": [
                        "Oauth"
                    ]
+18 −0
Original line number Diff line number Diff line
{
  "name": "netapp-provider-sample",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "dependencies": {
        "flask": "^0.2.10"
      }
    },
    "node_modules/flask": {
      "version": "0.2.10",
      "resolved": "https://registry.npmjs.org/flask/-/flask-0.2.10.tgz",
      "integrity": "sha512-Zy69KIuFsoX0o2W5uDHHk1GHMwRT8QT0AboPQY7b1soCfJ2pfwKxHF2AGVwJmDUjzawgOavoY/UsXnZ7fk3lVQ==",
      "license": "MIT"
    }
  }
}
Loading