Commit 0b15ad14 authored by Mohamad Rahhal's avatar Mohamad Rahhal
Browse files

QOS CAMARA- NBI:

- Correction After Shayan's Review
parent c6b134a6
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -41,7 +41,7 @@ spec:
            - containerPort: 8762
          env:
            - name: LOG_LEVEL
              value: "DEBUG"
              value: "INFO"
            - name: IETF_NETWORK_RENDERER
              value: "LIBYANG"
            - name: WS_E2E_PORT
+1 −1
Original line number Diff line number Diff line
@@ -38,7 +38,7 @@ spec:
            - containerPort: 9192
          env:
            - name: LOG_LEVEL
              value: "DEBUG"
              value: "INFO"
            - name: CRDB_DATABASE
              value: "tfs_qos_profile"
          envFrom:
+1 −1
Original line number Diff line number Diff line
@@ -134,7 +134,7 @@ export CRDB_PASSWORD="tfs123"
export CRDB_DEPLOY_MODE="single"

# Disable flag for dropping database, if it exists.
export CRDB_DROP_DATABASE_IF_EXISTS="YES"
export CRDB_DROP_DATABASE_IF_EXISTS=""

# Disable flag for re-deploying CockroachDB from scratch.
export CRDB_REDEPLOY=""
+10 −11
Original line number Diff line number Diff line
@@ -54,15 +54,15 @@ class ProfileList(_Resource):
        try:
            qos_profile = create_qos_profile_from_json(request_data)
        except Exception as e:
            LOGGER.info(e) # track if there is an error
            LOGGER.error(e) # track if there is an error 
            raise e  
        # Send to gRPC server using CreateQosProfile done by Shayan
        # Send to gRPC server using CreateQosProfile 
        try:
            qos_profile_created = self.qos_profile_client.CreateQoSProfile(qos_profile) 
        except Exception as e:
            LOGGER.info(e)
            LOGGER.error(e)
            raise e
        #gRPC message back to JSON using the helper function created by shayan 
        #gRPC message back to JSON using the helper function 
        qos_profile_data = grpc_message_to_qos_table_data(qos_profile_created)
        LOGGER.info(f'qos_profile_data{qos_profile_data}')       
        return jsonify(qos_profile_data)
@@ -140,8 +140,7 @@ class ProfileDetail(_Resource):
            return {"error": "Internal Server Error"}, 500
        
###SESSION##########################################################
LOGGER = logging.getLogger(__name__)
class qodinfo(_Resource):
class QodInfo(_Resource):
    def post(self):
        if not request.is_json:
            return (jsonify({'error': 'Unsupported Media Type', 'message': 'JSON payload is required'}), 415)
@@ -163,18 +162,18 @@ class qodinfo(_Resource):
            response = format_grpc_to_json(self.service_client.CreateService(stripped_service))
            response = format_grpc_to_json(self.service_client.UpdateService(service))
        except Exception as e: # pylint: disable=broad-except
            
            return e
        LOGGER.info(f"error related to response: {response}")
            LOGGER.error(f"Unexpected error: {str(e)}", exc_info=True)
            return jsonify({'error': 'Internal Server Error', 'message': 'An unexpected error occurred'}), 500
        LOGGER.error(f"error related to response: {response}")
        return response
    
    def get(self):
        service_list = self.client.ListServices(grpc_context_id(DEFAULT_CONTEXT_NAME)) #return context id as json
        qod_info = [service_2_qod(service) for service in service_list.services] #iterating over service list 
        LOGGER.info(f"error related to qod_info: {qod_info}")
        return qod_info
        return jsonify(qod_info), 200
           
class qodinfoId(_Resource):
class QodInfoID(_Resource):

    def get(self, sessionId: str):
        try:
+6 −22
Original line number Diff line number Diff line
@@ -91,7 +91,7 @@ def ip_withoutsubnet(ip_withsubnet,neededip):
    return IPAddress(neededip) in network


def QOD_2_service(client,qod_info: dict,qos_profile_id,duration) -> Service:
def QOD_2_service(client,qod_info: dict,qos_profile_id: int,duration: int) -> Service:
    qos_profile_client = QoSProfileClient()
    service = Service()
    service_config_rules = service.service_config.config_rules
@@ -110,8 +110,8 @@ def QOD_2_service(client,qod_info: dict,qos_profile_id,duration) -> Service:
        a_ip = qod_info['device'].get('ipv4Address')
        z_ip = qod_info['applicationServer'].get('ipv4Address')

        LOGGER.info('a_ip = {:s}'.format(str(a_ip)))
        LOGGER.info('z_ip = {:s}'.format(str(z_ip)))
        LOGGER.debug('a_ip = {:s}'.format(str(a_ip)))
        LOGGER.debug('z_ip = {:s}'.format(str(z_ip)))

        if a_ip and z_ip:
            devices = client.ListDevices(Empty()).devices
@@ -133,9 +133,9 @@ def QOD_2_service(client,qod_info: dict,qos_profile_id,duration) -> Service:
                    if not match_subif:
                        continue
                    address_ip =json.loads(cr.custom.resource_value).get('address_ip')
                    LOGGER.info('cr..address_ip = {:s}'.format(str(address_ip)))
                    LOGGER.debug('cr..address_ip = {:s}'.format(str(address_ip)))
                    short_port_name = match_subif.groups()[0]
                    LOGGER.info('short_port_name = {:s}'.format(str(short_port_name)))
                    LOGGER.debug('short_port_name = {:s}'.format(str(short_port_name)))

                    ip_interface_name_dict[address_ip] = short_port_name
                    
@@ -145,7 +145,7 @@ def QOD_2_service(client,qod_info: dict,qos_profile_id,duration) -> Service:
                    ep_id.endpoint_uuid.uuid = device_endpoint_uuids.get(short_port_name , '')
                    ep_id.device_id.device_uuid.uuid = device.device_id.device_uuid.uuid
                    service.service_endpoint_ids.append(ep_id)
                    LOGGER.info(f"the ip address{ep_id}")
                    LOGGER.debug(f"the ip address{ep_id}")
    
            #LOGGER.info('ip_interface_name_dict = {:s}'.format(str(ip_interface_name_dict)))
    
@@ -158,17 +158,6 @@ def QOD_2_service(client,qod_info: dict,qos_profile_id,duration) -> Service:
    qod_info["context"]='admin'
    service.service_id.service_uuid.uuid = qod_info['sessionID']
    service.service_id.context_id.context_uuid.uuid = qod_info["context"]

    #try:
    #    id = QoSProfileId(qos_profile_id=Uuid(uuid=qos_profile_id))
    #    id= QoSProfileId()
    #    id.qos_profile_id.uuid="qos_profile_id"
    #    qos_profile = qos_profile_client.GetQoSProfile(id)
    #except grpc._channel._InactiveRpcError as exc:
    #    if exc.code() == grpc.StatusCode.NOT_FOUND:
    #        return {"error": f"QoSProfile {qos_profile_id} not found"}, 404 
    #if qos_profile.qos_profile_id:
    #    qos_profile_id = qod_info.get('qos_profile_id')
    service.name = qod_info.get('qos_profile_id', qos_profile_id)    
    current_time = time.time() 
    duration_days = duration  # days as i saw it in the proto files
@@ -186,11 +175,6 @@ def QOD_2_service(client,qod_info: dict,qos_profile_id,duration) -> Service:
            cs.qos_profile.qos_profile_name.CopyFrom(qos_profile_client.name) #i copied this from the qosprofile
            LOGGER.info(f'the cs : {cs}')
        service.service_constraints.append(cs)
        #qos_profile = QoSProfile()
        #qos_profile.qos_profile_id.qos_profile_id.uuid = qod_info['qosProfile']
    #if 'qosProfile' in qos_profile_list:
    #    qos_profile = QoSProfile()
    #    qos_profile.qos_profile_id.qos_profile_id.uuid = qod_info['qosProfile']

    return service

Loading