upload_parser.add_argument('file',location='files',type='FileStorage',help="Archivo a subir")
upload_parser.add_argument('json_data',location='form',help="Datos JSON en formato string")
# Namespace Controllers
@ixia_ns.route("/slice")
classIxiaSliceList(Resource):
@@ -30,53 +30,50 @@ class IxiaSliceList(Resource):
defget(self):
"""Retrieve all slices"""
controller=NSController(controller_type="IXIA")
returncontroller.get_flows()
data,code=controller.get_flows()
returndata,code
@ixia_ns.doc(summary="Submit a transport network slice request",description="This endpoint allows clients to submit transport network slice requests using a JSON payload.")
json_data=json.load(uploaded_file)# Convert file to JSON
json_data=json.load(uploaded_file)
exceptjson.JSONDecodeError:
return{"error":"JSON file not valid"},400
return{"success":False,"data":None,"error":"JSON file not valid"},400
# If no file was uploaded, try to get the JSON data from the form
ifjson_dataisNone:
raw_json=request.form.get('json_data')
ifraw_json:
try:
json_data=json.loads(raw_json)# Convert string to JSON
json_data=json.loads(raw_json)
exceptjson.JSONDecodeError:
return{"error":"JSON file not valid"},400
return{"success":False,"data":None,"error":"JSON file not valid"},400
# If no JSON data was found, return an error
ifjson_dataisNone:
return{"error":"No data sent"},400
return{"success":False,"data":None,"error":"No data sent"},400
# Process the JSON data with the NSController
controller=NSController(controller_type="IXIA")
returncontroller.add_flow(json_data)
data,code=controller.add_flow(json_data)
returndata,code
@ixia_ns.doc(summary="Delete all transport network slices",description="Deletes all transport network slices from the slice controller.")
@ixia_ns.response(200,"All transport network slices deleted successfully.")
@ixia_ns.response(204,"All transport network slices deleted successfully.")
@ixia_ns.response(500,"Internal server error")
defdelete(self):
"""Delete all slices"""
controller=NSController(controller_type="IXIA")
returncontroller.delete_flows()
data,code=controller.delete_flows()
returndata,code
@ixia_ns.route("/slice/<string:slice_id>")
@@ -89,16 +86,18 @@ class IxiaSlice(Resource):
defget(self,slice_id):
"""Retrieve a specific slice"""
controller=NSController(controller_type="IXIA")
returncontroller.get_flows(slice_id)
data,code=controller.get_flows(slice_id)
returndata,code
@ixia_ns.doc(summary="Delete a specific transport network slice",description="Deletes a specific transport network slice from the slice controller based on the provided `slice_id`.")