Loading src/pathcomp/frontend/service/algorithms/_Algorithm.py +45 −3 Original line number Diff line number Diff line Loading @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. import json, logging, requests, uuid import json, logging, re, requests, uuid from typing import Dict, List, Optional, Tuple, Union from common.DeviceTypes import DeviceTypeEnum from common.proto.context_pb2 import ( Loading Loading @@ -183,11 +183,9 @@ class _Algorithm: if service_type == ServiceTypeEnum.SERVICETYPE_L2NM and rules_nb == 0: compose_l2nm_config_rules(config_rules, service.service_config.config_rules) self.logger.info("Installing default rules for L2NM service") pass elif service_type == ServiceTypeEnum.SERVICETYPE_L3NM and rules_nb == 0: compose_l3nm_config_rules(config_rules, service.service_config.config_rules) self.logger.info("Installing default rules for L3NM service") pass elif service_type == ServiceTypeEnum.SERVICETYPE_TAPI_CONNECTIVITY_SERVICE and rules_nb == 0: compose_tapi_config_rules(config_rules, service.service_config.config_rules) self.logger.info("Installing default rules for TAPI service") Loading @@ -199,6 +197,50 @@ class _Algorithm: config_rules, service.service_config.config_rules, path_hops, self.device_name_mapping, self.endpoint_name_mapping) for path_hop in path_hops: path_hop_device_id = path_hop['device'] path_hop_ingress_ep_id = path_hop['ingress_ep'] path_hop_egress_ep_id = path_hop['egress_ep'] path_hop_device_uuid = self.device_name_mapping [path_hop_device_id] path_hop_ingress_ep_uuid = self.endpoint_name_mapping[(path_hop_device_id, path_hop_ingress_ep_id)] path_hop_egress_ep_uuid = self.endpoint_name_mapping[(path_hop_device_id, path_hop_egress_ep_id )] target_endpoint_ids = set() target_endpoint_ids.add(path_hop_ingress_ep_uuid) target_endpoint_ids.add(path_hop_egress_ep_uuid) path_hop_device = self.device_dict [path_hop_device_uuid][1] path_hop_ingress_ep = self.endpoint_dict[path_hop_device_uuid][path_hop_ingress_ep_uuid][1] path_hop_egress_ep = self.endpoint_dict[path_hop_device_uuid][path_hop_egress_ep_uuid ][1] path_hop_device_name = path_hop_device.name path_hop_ingress_ep_name = path_hop_ingress_ep.name path_hop_egress_ep_name = path_hop_egress_ep.name target_endpoint_ids.add(path_hop_ingress_ep_name) target_endpoint_ids.add(path_hop_egress_ep_name) RE_ENDPOINT_SETTINGS = re.compile(r'\/endpoints\/endpoint\[([^\]]+)\](\/settings)?') for config_rule in path_hop_device.device_config.config_rules: if config_rule.WhichOneof('config_rule') != 'custom': continue rw_config_rule = ConfigRule() rw_config_rule.CopyFrom(config_rule) resource_key = str(config_rule.custom.resource_key) ep_match = RE_ENDPOINT_SETTINGS.match(resource_key) if ep_match is None: continue endpoint_id = ep_match.group(1) if endpoint_id not in target_endpoint_ids: continue endpoint_uuid = self.endpoint_name_mapping[(path_hop_device_id, endpoint_id)] endpoint = self.endpoint_dict[path_hop_device_uuid][endpoint_uuid][1] endpoint_name = endpoint.name resource_key = '/device[{:s}]/endpoint[{:s}]/settings'.format( path_hop_device_name, endpoint_name ) rw_config_rule.custom.resource_key = resource_key service.service_config.config_rules.append(rw_config_rule) if path_hops is not None and len(path_hops) > 0: ingress_endpoint_id = service.service_endpoint_ids.add() ingress_endpoint_id.device_id.device_uuid.uuid = path_hops[0]['device'] Loading Loading
src/pathcomp/frontend/service/algorithms/_Algorithm.py +45 −3 Original line number Diff line number Diff line Loading @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. import json, logging, requests, uuid import json, logging, re, requests, uuid from typing import Dict, List, Optional, Tuple, Union from common.DeviceTypes import DeviceTypeEnum from common.proto.context_pb2 import ( Loading Loading @@ -183,11 +183,9 @@ class _Algorithm: if service_type == ServiceTypeEnum.SERVICETYPE_L2NM and rules_nb == 0: compose_l2nm_config_rules(config_rules, service.service_config.config_rules) self.logger.info("Installing default rules for L2NM service") pass elif service_type == ServiceTypeEnum.SERVICETYPE_L3NM and rules_nb == 0: compose_l3nm_config_rules(config_rules, service.service_config.config_rules) self.logger.info("Installing default rules for L3NM service") pass elif service_type == ServiceTypeEnum.SERVICETYPE_TAPI_CONNECTIVITY_SERVICE and rules_nb == 0: compose_tapi_config_rules(config_rules, service.service_config.config_rules) self.logger.info("Installing default rules for TAPI service") Loading @@ -199,6 +197,50 @@ class _Algorithm: config_rules, service.service_config.config_rules, path_hops, self.device_name_mapping, self.endpoint_name_mapping) for path_hop in path_hops: path_hop_device_id = path_hop['device'] path_hop_ingress_ep_id = path_hop['ingress_ep'] path_hop_egress_ep_id = path_hop['egress_ep'] path_hop_device_uuid = self.device_name_mapping [path_hop_device_id] path_hop_ingress_ep_uuid = self.endpoint_name_mapping[(path_hop_device_id, path_hop_ingress_ep_id)] path_hop_egress_ep_uuid = self.endpoint_name_mapping[(path_hop_device_id, path_hop_egress_ep_id )] target_endpoint_ids = set() target_endpoint_ids.add(path_hop_ingress_ep_uuid) target_endpoint_ids.add(path_hop_egress_ep_uuid) path_hop_device = self.device_dict [path_hop_device_uuid][1] path_hop_ingress_ep = self.endpoint_dict[path_hop_device_uuid][path_hop_ingress_ep_uuid][1] path_hop_egress_ep = self.endpoint_dict[path_hop_device_uuid][path_hop_egress_ep_uuid ][1] path_hop_device_name = path_hop_device.name path_hop_ingress_ep_name = path_hop_ingress_ep.name path_hop_egress_ep_name = path_hop_egress_ep.name target_endpoint_ids.add(path_hop_ingress_ep_name) target_endpoint_ids.add(path_hop_egress_ep_name) RE_ENDPOINT_SETTINGS = re.compile(r'\/endpoints\/endpoint\[([^\]]+)\](\/settings)?') for config_rule in path_hop_device.device_config.config_rules: if config_rule.WhichOneof('config_rule') != 'custom': continue rw_config_rule = ConfigRule() rw_config_rule.CopyFrom(config_rule) resource_key = str(config_rule.custom.resource_key) ep_match = RE_ENDPOINT_SETTINGS.match(resource_key) if ep_match is None: continue endpoint_id = ep_match.group(1) if endpoint_id not in target_endpoint_ids: continue endpoint_uuid = self.endpoint_name_mapping[(path_hop_device_id, endpoint_id)] endpoint = self.endpoint_dict[path_hop_device_uuid][endpoint_uuid][1] endpoint_name = endpoint.name resource_key = '/device[{:s}]/endpoint[{:s}]/settings'.format( path_hop_device_name, endpoint_name ) rw_config_rule.custom.resource_key = resource_key service.service_config.config_rules.append(rw_config_rule) if path_hops is not None and len(path_hops) > 0: ingress_endpoint_id = service.service_endpoint_ids.add() ingress_endpoint_id.device_id.device_uuid.uuid = path_hops[0]['device'] Loading