diff --git a/src/nbi/service/rest_server/nbi_plugins/camara_qod/Resources.py b/src/nbi/service/rest_server/nbi_plugins/camara_qod/Resources.py index 398dca9dc5be1923a2f9076f6026bcadabf37937..33b5bc5f65525a56425aab5918ed200d7c0025e4 100644 --- a/src/nbi/service/rest_server/nbi_plugins/camara_qod/Resources.py +++ b/src/nbi/service/rest_server/nbi_plugins/camara_qod/Resources.py @@ -94,6 +94,15 @@ class ProfileDetail(_Resource): except Exception as e: LOGGER.error(f"Error while fetching QoSProfile: {e}") return {"error": "Internal Server Error"}, 500 + + def get(self,QoDConstraintsRequest): + qos_profiles = self.qos_profile_client.GetConstraintListFromQoSProfile(QoDConstraintsRequest) + qos_profile_list = [] #since it iterates over QoSProfile , create a list to store all QOS profiles + for qos_profile in qos_profiles: + qos_profile_data = grpc_message_to_qos_table_data(qos_profile) #transform to json + qos_profile_list.append(qos_profile_data) # append to the list + + return jsonify(qos_profile_list) def put(self, qos_profile_id): try: @@ -155,12 +164,14 @@ class qodinfo(_Resource): def post(self): if not request.is_json: return (jsonify({'error': 'Unsupported Media Type', 'message': 'JSON payload is required'}), 415) - request_data: Dict = request.get_json() qos_profile_id = request_data.get('qos_profile_id') + qos_session_id = request_data.get('qos_session_id') LOGGER.info(f'qos_profile_id:{qos_profile_id}') if not qos_profile_id: return jsonify({'error': 'qos_profile_id is required'}), 400 + if qos_session_id: + return jsonify({'error': 'qos_session_id is not allowed in creation'}), 400 service = QOD_2_service(self.client, request_data,qos_profile_id) stripped_service = copy.deepcopy(service) stripped_service.ClearField('service_endpoint_ids') @@ -180,11 +191,7 @@ class qodinfo(_Resource): qod_info = [service_2_qod(service) for service in service_list.services] LOGGER.info(f"error related to qod_info: {qod_info}") return qod_info - - - - - + class qodinfoId(_Resource): def get(self, sessionId: str): @@ -199,21 +206,21 @@ class qodinfoId(_Resource): def put(self, sessionId: str): try: request_data: Dict = request.get_json() - sessionId= request_data.get('session_id') - if not sessionId: - return jsonify({'error': 'sessionId is required'}), 400 + session_id = request_data.get('session_id') + if not session_id: + return jsonify({'error': 'sessionId is required'}), 400 qos_profile_id = request_data.get('qos_profile_id') if not qos_profile_id: return jsonify({'error': 'qos_profile_id is required'}), 400 - service = QOD_2_service(self.client, request_data, qos_profile_id) + service = self.client.GetService(grpc_service_id(DEFAULT_CONTEXT_NAME, sessionId)) updated_service = self.service_client.UpdateService(service) qod_response = service_2_qod(updated_service) - return qod_response, 200 except KeyError as e: LOGGER.error(f"Missing required key: {e}") return {"error": f"Missing required key: {str(e)}"}, 400 + except grpc._channel._InactiveRpcError as exc: if exc.code() == grpc.StatusCode.NOT_FOUND: LOGGER.warning(f"Qod Session not found: {sessionId}") @@ -223,7 +230,6 @@ class qodinfoId(_Resource): except Exception as e: LOGGER.error(f"Error in PUT /sessions/{sessionId}: {e}") return {"error": "Internal Server Error"}, 500 - def delete(self, sessionId: str): self.service_client.DeleteService(grpc_service_id(DEFAULT_CONTEXT_NAME, sessionId)) diff --git a/src/nbi/service/rest_server/nbi_plugins/camara_qod/Tools.py b/src/nbi/service/rest_server/nbi_plugins/camara_qod/Tools.py index 98a85cc8c424213872136f788302e6533c3fe383..043e5d92adc02bb60d5c50515b55a5b4b6f76576 100644 --- a/src/nbi/service/rest_server/nbi_plugins/camara_qod/Tools.py +++ b/src/nbi/service/rest_server/nbi_plugins/camara_qod/Tools.py @@ -27,8 +27,8 @@ from common.tools.object_factory.Service import json_service_id from uuid import uuid4 from nbi.service.rest_server.nbi_plugins.ietf_network.bindings.networks import network from qos_profile.client.QoSProfileClient import QoSProfileClient -from context.service.database.QoSProfile import grpc_message_to_qos_table_data -from common.proto.context_pb2 import QoSProfile, QoSProfileId, Uuid, QoSProfileValueUnitPair,Empty +#from context.service.database.QoSProfile import grpc_message_to_qos_table_data +from common.proto.context_pb2 import QoSProfile, QoSProfileId, Uuid, QoSProfileValueUnitPair,Empty,ServiceId import logging import grpc from netaddr import IPAddress, IPNetwork