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

Device component - IETF L3VPN:

- Properly implemented set/delete
- Code polishing
parent c33f9ae6
Loading
Loading
Loading
Loading
+6 −34
Original line number Diff line number Diff line
@@ -172,41 +172,17 @@ class IetfL3VpnDriver(_Driver):
        results = []
        if len(resources) == 0: return results
        with self.__lock:
            for resource in resources:
                resource_key, resource_value = resource
                if RE_IETF_L3VPN_OPERATION.match(resource_key):
                    operation_type = json.loads(resource_value)['type']
                    results.append((resource_key, True))
                    break
            else:
                raise Exception('operation type not found in resources')

            for i, resource in enumerate(resources):
                str_resource_name = 'resource_key[#{:d}]'.format(i)
                LOGGER.info('resource = {:s}'.format(str(resource)))
                resource_key, resource_value = resource
                if not RE_IETF_L3VPN_DATA.match(resource_key):
                    continue
                if not RE_IETF_L3VPN_DATA.match(resource_key): continue
                try:
                    resource_value = json.loads(resource_value)

                    service_uuid = resource_value['ietf-l3vpn-svc:l3vpn-svc'][
                        'vpn-services'
                    ]['vpn-service'][0]['vpn-id']

                    if operation_type == 'create':
                    self.tac.create_connectivity_service(resource_value)
                    elif operation_type == 'update':
                        self.tac.update_connectivity_service(resource_value)
                    elif operation_type == 'delete':
                        self.tac.delete_connectivity_service(service_uuid)
                    else:
                        MSG = 'OperationType({:s}) not supported'
                        raise Exception(MSG.format(str(operation_type)))

                    results.append((resource_key, True))
                except Exception as e:
                    MSG = 'Unhandled error processing {:s}: resource_key({:s})'
                    MSG = 'Unhandled error processing SET {:s}: resource_key({:s})'
                    LOGGER.exception(MSG.format(str_resource_name, str(resource_key)))
                    results.append((resource_key, e))
        return results
@@ -216,17 +192,13 @@ class IetfL3VpnDriver(_Driver):
        self, resources : List[Tuple[str, Any]]
    ) -> List[Union[bool, Exception]]:
        results = []
        if len(resources) == 0:
            return results
        if len(resources) == 0: return results
        with self.__lock:
            for i, resource in enumerate(resources):
                str_resource_name = 'resource_key[#{:d}]'.format(i)
                LOGGER.info('resource = {:s}'.format(str(resource)))
                resource_key, resource_value = resource

                if not RE_IETF_L3VPN_DATA.match(resource_key):
                    continue

                if not RE_IETF_L3VPN_DATA.match(resource_key): continue
                try:
                    resource_value = json.loads(resource_value)
                    service_uuid = resource_value['ietf-l3vpn-svc:l3vpn-svc'][
@@ -235,7 +207,7 @@ class IetfL3VpnDriver(_Driver):
                    self.tac.delete_connectivity_service(service_uuid)
                    results.append((resource_key, True))
                except Exception as e:
                    MSG = 'Unhandled error processing {:s}: resource_key({:s})'
                    MSG = 'Unhandled error processing DELETE {:s}: resource_key({:s})'
                    LOGGER.exception(MSG.format(str_resource_name, str(resource_key)))
                    results.append((resource_key, e))
        return results