Commit 80133447 authored by Lluis Gifre Renom's avatar Lluis Gifre Renom
Browse files

NBI component - IETF L3 VPN connector:

- Minor code fixes and styling
parent 25cc5c38
Loading
Loading
Loading
Loading
+10 −5
Original line number Diff line number Diff line
@@ -16,7 +16,7 @@ import logging
from flask import request
from flask.json import jsonify
from flask_restful import Resource
from common.proto.context_pb2 import ServiceStatusEnum
from common.proto.context_pb2 import ServiceStatusEnum, ServiceTypeEnum
from common.tools.context_queries.Service import get_service_by_uuid
from context.client.ContextClient import ContextClient
from service.client.ServiceClient import ServiceClient
@@ -24,7 +24,7 @@ from typing import Dict, List
from werkzeug.exceptions import UnsupportedMediaType
from nbi.service._tools.Authentication import HTTP_AUTH
from nbi.service._tools.HttpStatusCodes import (
    HTTP_GATEWAYTIMEOUT, HTTP_NOCONTENT, HTTP_OK, HTTP_SERVERERROR, HTTP_CREATED
    HTTP_GATEWAYTIMEOUT, HTTP_NOCONTENT, HTTP_OK, HTTP_SERVERERROR
)
from .Handlers import  update_vpn
from .YangValidator import YangValidator
@@ -32,7 +32,7 @@ from .YangValidator import YangValidator
LOGGER = logging.getLogger(__name__)

class L3VPN_Service(Resource):
    # @HTTP_AUTH.login_required
    @HTTP_AUTH.login_required
    def get(self, vpn_id : str):
        LOGGER.debug('VPN_Id: {:s}'.format(str(vpn_id)))
        LOGGER.debug('Request: {:s}'.format(str(request)))
@@ -44,6 +44,9 @@ class L3VPN_Service(Resource):
            if target is None:
                raise Exception('VPN({:s}) not found in database'.format(str(vpn_id)))
            
            if target.service_type != ServiceTypeEnum.SERVICETYPE_L3NM:
                raise Exception('VPN({:s}) is not L3VPN'.format(str(vpn_id)))

            service_ids = {target.service_id.service_uuid.uuid, target.name} # pylint: disable=no-member
            if vpn_id not in service_ids:
                raise Exception('Service retrieval failed. Wrong Service Id was returned')
@@ -58,7 +61,7 @@ class L3VPN_Service(Resource):
            response.status_code = HTTP_SERVERERROR
        return response

    # @HTTP_AUTH.login_required
    @HTTP_AUTH.login_required
    def delete(self, vpn_id : str):
        LOGGER.debug('VPN_Id: {:s}'.format(str(vpn_id)))
        LOGGER.debug('Request: {:s}'.format(str(request)))
@@ -69,6 +72,8 @@ class L3VPN_Service(Resource):
            target = get_service_by_uuid(context_client, vpn_id)
            if target is None:
                LOGGER.warning('VPN({:s}) not found in database. Nothing done.'.format(str(vpn_id)))
            elif target.service_type != ServiceTypeEnum.SERVICETYPE_L3NM:
                raise Exception('VPN({:s}) is not L3VPN'.format(str(vpn_id)))
            else:
                service_ids = {target.service_id.service_uuid.uuid, target.name} # pylint: disable=no-member
                if vpn_id not in service_ids:
@@ -102,7 +107,7 @@ class L3VPN_Service(Resource):
            errors.append('Unexpected request format: {:s}'.format(str(request_data)))

        response = jsonify(errors)
        response.status_code = HTTP_CREATED if len(errors) == 0 else HTTP_SERVERERROR
        response.status_code = HTTP_NOCONTENT if len(errors) == 0 else HTTP_SERVERERROR
        return response

    def _update_l3vpn(self, request_data: Dict) -> List[Dict]:
+3 −3
Original line number Diff line number Diff line
@@ -26,11 +26,11 @@ from .YangValidator import YangValidator
LOGGER = logging.getLogger(__name__)

class L3VPN_Services(Resource):
    # @HTTP_AUTH.login_required
    @HTTP_AUTH.login_required
    def get(self):
        return {}

    # @HTTP_AUTH.login_required
    @HTTP_AUTH.login_required
    def post(self):
        if not request.is_json: raise UnsupportedMediaType('JSON payload is required')
        request_data : Dict = request.json
@@ -58,7 +58,7 @@ class L3VPN_Services(Resource):
            #      "vpn-service": [
            errors.extend(self._process_l3vpn(request_data))
        else:
            errors.append('unexpected request: {:s}'.format(str(request_data)))
            errors.append('Unexpected request: {:s}'.format(str(request_data)))

        response = jsonify(errors)
        response.status_code = HTTP_CREATED if len(errors) == 0 else HTTP_SERVERERROR