Loading src/nbi/service/ietf_l2vpn/L2VPN_Services.py +44 −18 Original line number Diff line number Diff line Loading @@ -18,8 +18,8 @@ from flask import request from flask.json import jsonify from flask_restful import Resource from werkzeug.exceptions import UnsupportedMediaType from nbi.service._tools.HttpStatusCodes import HTTP_CREATED, HTTP_SERVERERROR from nbi.service._tools.Authentication import HTTP_AUTH from nbi.service._tools.HttpStatusCodes import HTTP_CREATED, HTTP_SERVERERROR from .Handlers import process_site, process_vpn_service from .YangValidator import YangValidator Loading @@ -37,29 +37,45 @@ class L2VPN_Services(Resource): LOGGER.debug('Request: {:s}'.format(str(request_data))) errors = list() if 'ietf-l2vpn-svc:l2vpn-services' in request_data: # processing multiple L2VPN service requests formatted as: #{ # "ietf-l2vpn-svc:l2vpn-services": { # "l2vpn-svc": [ # { # "service-id": "vpn1", # "vpn-services": { # "vpn-service": [ for l2vpn_svc in request_data['ietf-l2vpn-svc:l2vpn-services']['l2vpn-svc']: l2vpn_svc.pop('service-id', None) l2vpn_svc_request_data = {'ietf-l2vpn-svc:l2vpn-svc': l2vpn_svc} errors.extend(self._process_l2vpn(l2vpn_svc_request_data)) elif 'ietf-l2vpn-svc:l2vpn-svc' in request_data: # processing single (standard) L2VPN service request formatted as: if 'ietf-l2vpn-svc:l2vpn-svc' in request_data: # processing single (standard) request formatted as: #{ # "ietf-l2vpn-svc:l2vpn-svc": { # "vpn-services": { # "vpn-service": [ errors.extend(self._process_l2vpn(request_data)) elif 'ietf-l2vpn-svc:vpn-service' in request_data: # processing OSM-style payload request formatted as: #{ # "ietf-l2vpn-svc:vpn-service": [ vpn_services = request_data['ietf-l2vpn-svc:vpn-service'] # Add mandatory fields OSM RO driver skips for vpn_service in vpn_services: if 'ce-vlan-preservation' not in vpn_service: vpn_service['ce-vlan-preservation'] = True if 'ce-vlan-cos-preservation' not in vpn_service: vpn_service['ce-vlan-cos-preservation'] = True if 'frame-delivery' not in vpn_service: vpn_service['frame-delivery'] = dict() if 'multicast-gp-port-mapping' not in vpn_service['frame-delivery']: vpn_service['frame-delivery']['multicast-gp-port-mapping'] = \ 'ietf-l2vpn-svc:static-mapping' request_data = { 'ietf-l2vpn-svc:l2vpn-svc': { 'vpn-services': { 'vpn-service': vpn_services } } } errors.extend(self._process_l2vpn(request_data)) else: errors.append('Unexpected request: {:s}'.format(str(request_data))) if len(errors) > 0: LOGGER.error('Errors: {:s}'.format(str(errors))) response = jsonify(errors) response.status_code = HTTP_CREATED if len(errors) == 0 else HTTP_SERVERERROR return response Loading @@ -71,10 +87,20 @@ class L2VPN_Services(Resource): errors = list() for vpn_service in request_data['l2vpn-svc']['vpn-services']['vpn-service']: vpn_services = ( request_data.get('l2vpn-svc', dict()) .get('vpn-services', dict()) .get('vpn-service', list()) ) for vpn_service in vpn_services: process_vpn_service(vpn_service, errors) for site in request_data['l2vpn-svc']['sites']['site']: sites = ( request_data.get('l2vpn-svc', dict()) .get('sites', dict()) .get('site', list()) ) for site in sites: process_site(site, errors) return errors Loading
src/nbi/service/ietf_l2vpn/L2VPN_Services.py +44 −18 Original line number Diff line number Diff line Loading @@ -18,8 +18,8 @@ from flask import request from flask.json import jsonify from flask_restful import Resource from werkzeug.exceptions import UnsupportedMediaType from nbi.service._tools.HttpStatusCodes import HTTP_CREATED, HTTP_SERVERERROR from nbi.service._tools.Authentication import HTTP_AUTH from nbi.service._tools.HttpStatusCodes import HTTP_CREATED, HTTP_SERVERERROR from .Handlers import process_site, process_vpn_service from .YangValidator import YangValidator Loading @@ -37,29 +37,45 @@ class L2VPN_Services(Resource): LOGGER.debug('Request: {:s}'.format(str(request_data))) errors = list() if 'ietf-l2vpn-svc:l2vpn-services' in request_data: # processing multiple L2VPN service requests formatted as: #{ # "ietf-l2vpn-svc:l2vpn-services": { # "l2vpn-svc": [ # { # "service-id": "vpn1", # "vpn-services": { # "vpn-service": [ for l2vpn_svc in request_data['ietf-l2vpn-svc:l2vpn-services']['l2vpn-svc']: l2vpn_svc.pop('service-id', None) l2vpn_svc_request_data = {'ietf-l2vpn-svc:l2vpn-svc': l2vpn_svc} errors.extend(self._process_l2vpn(l2vpn_svc_request_data)) elif 'ietf-l2vpn-svc:l2vpn-svc' in request_data: # processing single (standard) L2VPN service request formatted as: if 'ietf-l2vpn-svc:l2vpn-svc' in request_data: # processing single (standard) request formatted as: #{ # "ietf-l2vpn-svc:l2vpn-svc": { # "vpn-services": { # "vpn-service": [ errors.extend(self._process_l2vpn(request_data)) elif 'ietf-l2vpn-svc:vpn-service' in request_data: # processing OSM-style payload request formatted as: #{ # "ietf-l2vpn-svc:vpn-service": [ vpn_services = request_data['ietf-l2vpn-svc:vpn-service'] # Add mandatory fields OSM RO driver skips for vpn_service in vpn_services: if 'ce-vlan-preservation' not in vpn_service: vpn_service['ce-vlan-preservation'] = True if 'ce-vlan-cos-preservation' not in vpn_service: vpn_service['ce-vlan-cos-preservation'] = True if 'frame-delivery' not in vpn_service: vpn_service['frame-delivery'] = dict() if 'multicast-gp-port-mapping' not in vpn_service['frame-delivery']: vpn_service['frame-delivery']['multicast-gp-port-mapping'] = \ 'ietf-l2vpn-svc:static-mapping' request_data = { 'ietf-l2vpn-svc:l2vpn-svc': { 'vpn-services': { 'vpn-service': vpn_services } } } errors.extend(self._process_l2vpn(request_data)) else: errors.append('Unexpected request: {:s}'.format(str(request_data))) if len(errors) > 0: LOGGER.error('Errors: {:s}'.format(str(errors))) response = jsonify(errors) response.status_code = HTTP_CREATED if len(errors) == 0 else HTTP_SERVERERROR return response Loading @@ -71,10 +87,20 @@ class L2VPN_Services(Resource): errors = list() for vpn_service in request_data['l2vpn-svc']['vpn-services']['vpn-service']: vpn_services = ( request_data.get('l2vpn-svc', dict()) .get('vpn-services', dict()) .get('vpn-service', list()) ) for vpn_service in vpn_services: process_vpn_service(vpn_service, errors) for site in request_data['l2vpn-svc']['sites']['site']: sites = ( request_data.get('l2vpn-svc', dict()) .get('sites', dict()) .get('site', list()) ) for site in sites: process_site(site, errors) return errors