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

Device component - IETF L3VPN / IETF Slice:

- Added propagation of underly endpoint settings while discovering
parent f096945c
Loading
Loading
Loading
Loading
+10 −1
Original line number Diff line number Diff line
@@ -19,12 +19,13 @@ from common.Constants import DEFAULT_CONTEXT_NAME, DEFAULT_TOPOLOGY_NAME
from common.DeviceTypes import DeviceTypeEnum
from common.method_wrappers.ServiceExceptions import InvalidArgumentException, NotFoundException
from common.proto.context_pb2 import (
    ConfigActionEnum, ConfigRule_ACL, Device, DeviceConfig, EndPoint, Link, Location, OpticalConfig
    ConfigActionEnum, ConfigRule, ConfigRule_ACL, Device, DeviceConfig, EndPoint, Link, Location, OpticalConfig
)
from common.proto.device_pb2 import MonitoringSettings
from common.proto.kpi_sample_types_pb2 import KpiSampleType
from common.tools.grpc.ConfigRules import update_config_rule_custom
from common.tools.grpc.Tools import grpc_message_to_json
from common.tools.object_factory.ConfigRule import json_config_rule_set
from common.type_checkers.Checkers import chk_length, chk_type
from .driver_api._Driver import _Driver, RESOURCE_ENDPOINTS
from .monitoring.MonitoringLoops import MonitoringLoops
@@ -233,10 +234,12 @@ def populate_endpoints(
                # add endpoint to current device
                device_endpoint = device.device_endpoints.add()
                device_endpoint.endpoint_id.device_id.device_uuid.uuid = device_uuid
                device_config_rules = device.device_config.config_rules
            else:
                # add endpoint to specified device
                device_endpoint = new_sub_devices[_device_uuid].device_endpoints.add()
                device_endpoint.endpoint_id.device_id.device_uuid.uuid = _device_uuid
                device_config_rules = new_sub_devices[_device_uuid].device_config.config_rules

            device_endpoint.endpoint_id.endpoint_uuid.uuid = endpoint_uuid

@@ -260,6 +263,12 @@ def populate_endpoints(
            if location is not None:
                device_endpoint.endpoint_location.MergeFrom(Location(**location))

            settings = resource_value.get('settings', None)
            if settings is not None:
                device_config_rules.append(ConfigRule(**json_config_rule_set(
                    '/endpoints/endpoint[{:s}]'.format(str(endpoint_name)), settings
                )))

            if endpoint_uuid == 'mgmt' or endpoint_name == 'mgmt':
                if _device_uuid is None:
                    devices_with_mgmt_endpoints.add(device_uuid)
+21 −2
Original line number Diff line number Diff line
@@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import logging, requests
import json, logging, requests
from typing import Dict, List, Optional
from common.tools.client.RestApiClient import RestApiClient
from device.service.driver_api.ImportTopologyEnum import ImportTopologyEnum
@@ -129,15 +129,34 @@ class TfsApiClient(RestApiClient):
                device_data['ctrl_uuid'] = ctrl_uuid
            result.append((device_url, device_data))

            config_rule_list : List[Dict] = (
                json_device
                .get('device_config', dict())
                .get('config_rules', list())
            )
            config_rule_dict = dict()
            for cr in config_rule_list:
                if cr['action'] != 'CONFIGACTION_SET': continue
                if 'custom' not in cr: continue
                cr_rk : str = cr['custom']['resource_key']
                if not cr_rk.startswith('/endpoints/endpoint['): continue
                settings = json.loads(cr['custom']['resource_value'])
                ep_name = settings['name']
                config_rule_dict[ep_name] = settings

            for json_endpoint in json_device['device_endpoints']:
                endpoint_uuid = json_endpoint['endpoint_id']['endpoint_uuid']['uuid']
                endpoint_name = json_endpoint['name']
                endpoint_url = '/endpoints/endpoint[{:s}]'.format(endpoint_uuid)
                endpoint_data = {
                    'device_uuid': device_uuid,
                    'uuid': endpoint_uuid,
                    'name': json_endpoint['name'],
                    'name': endpoint_name,
                    'type': json_endpoint['endpoint_type'],
                }
                endpoint_settings = config_rule_dict.get(endpoint_name)
                if endpoint_settings is not None:
                    endpoint_data['settings'] = endpoint_settings
                result.append((endpoint_url, endpoint_data))

        if import_topology == ImportTopologyEnum.DEVICES:
+21 −2
Original line number Diff line number Diff line
@@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import logging, requests
import json, logging, requests
from typing import Dict, List, Optional
from common.tools.client.RestApiClient import RestApiClient
from device.service.driver_api.ImportTopologyEnum import ImportTopologyEnum
@@ -130,15 +130,34 @@ class TfsApiClient(RestApiClient):
                device_data['ctrl_uuid'] = ctrl_uuid
            result.append((device_url, device_data))

            config_rule_list : List[Dict] = (
                json_device
                .get('device_config', dict())
                .get('config_rules', list())
            )
            config_rule_dict = dict()
            for cr in config_rule_list:
                if cr['action'] != 'CONFIGACTION_SET': continue
                if 'custom' not in cr: continue
                cr_rk : str = cr['custom']['resource_key']
                if not cr_rk.startswith('/endpoints/endpoint['): continue
                settings = json.loads(cr['custom']['resource_value'])
                ep_name = settings['name']
                config_rule_dict[ep_name] = settings

            for json_endpoint in json_device['device_endpoints']:
                endpoint_uuid = json_endpoint['endpoint_id']['endpoint_uuid']['uuid']
                endpoint_name = json_endpoint['name']
                endpoint_url = '/endpoints/endpoint[{:s}]'.format(endpoint_uuid)
                endpoint_data = {
                    'device_uuid': device_uuid,
                    'uuid': endpoint_uuid,
                    'name': json_endpoint['name'],
                    'name': endpoint_name,
                    'type': json_endpoint['endpoint_type'],
                }
                endpoint_settings = config_rule_dict.get(endpoint_name)
                if endpoint_settings is not None:
                    endpoint_data['settings'] = endpoint_settings
                result.append((endpoint_url, endpoint_data))

        if import_topology == ImportTopologyEnum.DEVICES: