Loading src/service/service/service_handlers/l2nm_gnmi_openconfig/ConfigRuleComposer.py +22 −11 Original line number Diff line number Diff line Loading @@ -60,7 +60,6 @@ class EndpointComposer: def __init__(self, endpoint_uuid : str) -> None: self.uuid = endpoint_uuid self.objekt : Optional[EndPoint] = None self.sub_interface_index = 0 self.vlan_id = None def configure(self, endpoint_obj : Optional[EndPoint], settings : Optional[TreeNode]) -> None: Loading @@ -71,35 +70,42 @@ class EndpointComposer: if 'vlan_id' in json_settings: self.vlan_id = json_settings['vlan_id'] self.sub_interface_index = json_settings.get('index', 0) elif 'vlan-id' in json_settings: self.vlan_id = json_settings['vlan-id'] else: MSG = 'VLAN ID not found. Tried: vlan_id and vlan-id. endpoint_obj={:s} settings={:s}' LOGGER.warning(MSG.format(grpc_message_to_json_string(endpoint_obj), str(settings))) def get_config_rules(self, network_instance_name : str, delete : bool = False) -> List[Dict]: config_rules : List[Dict] = list() if self.vlan_id is None: MSG = 'VLAN ID not defined for endpoint_obj={:s}' LOGGER.warning(MSG.format(grpc_message_to_json_string(self.objekt))) return config_rules json_config_rule = json_config_rule_delete if delete else json_config_rule_set config_rules : List[Dict] = list() if network_instance_name != DEFAULT_NETWORK_INSTANCE: config_rules.append(json_config_rule(*_network_instance_interface( network_instance_name, self.objekt.name, self.sub_interface_index network_instance_name, self.objekt.name, self.vlan_id ))) if delete: config_rules.extend([ json_config_rule(*_interface( self.objekt.name, index=self.sub_interface_index, vlan_id=self.vlan_id, enabled=False self.objekt.name, index=self.vlan_id, vlan_id=self.vlan_id, enabled=False )), ]) else: config_rules.extend([ json_config_rule(*_interface( self.objekt.name, index=self.sub_interface_index, vlan_id=self.vlan_id, enabled=True self.objekt.name, index=self.vlan_id, vlan_id=self.vlan_id, enabled=True )), ]) return config_rules def dump(self) -> Dict: return { 'index' : self.sub_interface_index, 'vlan_id' : self.vlan_id, } Loading Loading @@ -154,7 +160,7 @@ class DeviceComposer: match = RE_SUBIF.match(config_rule_custom.resource_key) if match is not None: if_name, subif_index = match.groups() if_name, _ = match.groups() if if_name in mgmt_ifaces: continue resource_value = json.loads(config_rule_custom.resource_value) if 'vlan_id' not in resource_value: continue Loading @@ -162,7 +168,6 @@ class DeviceComposer: self.vlan_ids.add(vlan_id) endpoint = self.get_endpoint(if_name) endpoint.vlan_id = vlan_id endpoint.sub_interface_index = int(subif_index) def get_config_rules(self, network_instance_name : str, delete : bool = False) -> List[Dict]: SELECTED_DEVICES = { Loading Loading @@ -191,7 +196,8 @@ class DeviceComposer: 'endpoints' : { endpoint_uuid : endpoint.dump() for endpoint_uuid, endpoint in self.endpoints.items() } }, 'vlan_ids' : list(self.vlan_ids) } def __str__(self): Loading Loading @@ -232,6 +238,11 @@ class ConfigRuleComposer: def get_config_rules( self, network_instance_name : str = NETWORK_INSTANCE, delete : bool = False ) -> Dict[str, List[Dict]]: if self.vlan_id is None: MSG = 'VLAN ID not defined for service_obj={:s}' LOGGER.warning(MSG.format(grpc_message_to_json_string(self.objekt))) return dict() return { device_uuid : device.get_config_rules(network_instance_name, delete=delete) for device_uuid, device in self.devices.items() Loading src/service/service/service_handlers/l2nm_gnmi_openconfig/VlanIdPropagator.py +8 −2 Original line number Diff line number Diff line Loading @@ -64,27 +64,33 @@ class VlanIdPropagator: device_endpoint_a, device_endpoint_b = link_endpoints device_uuid_a, endpoint_uuid_a = device_endpoint_a[0:2] endpoint_a = self._config_rule_composer.get_device(device_uuid_a).get_endpoint(endpoint_uuid_a) device_a = self._config_rule_composer.get_device(device_uuid_a) endpoint_a = device_a.get_endpoint(endpoint_uuid_a) device_uuid_b, endpoint_uuid_b = device_endpoint_b[0:2] endpoint_b = self._config_rule_composer.get_device(device_uuid_b).get_endpoint(endpoint_uuid_b) device_b = self._config_rule_composer.get_device(device_uuid_b) endpoint_b = device_b.get_endpoint(endpoint_uuid_b) svc_vlan_id = self._config_rule_composer.vlan_id ep_a_vlan_id = endpoint_a.vlan_id ep_b_vlan_id = endpoint_b.vlan_id if ep_a_vlan_id is None and ep_b_vlan_id is None: device_a.vlan_ids.add(svc_vlan_id) endpoint_a.vlan_id = svc_vlan_id device_b.vlan_ids.add(svc_vlan_id) endpoint_b.vlan_id = svc_vlan_id elif ep_a_vlan_id is not None and ep_b_vlan_id is None: if ep_a_vlan_id != svc_vlan_id: MSG = 'Incompatible VLAN-IDs: endpoint_a({:s}), service({:s})' raise Exception(MSG.format(str(endpoint_a), str(svc_vlan_id))) device_b.vlan_ids.add(svc_vlan_id) endpoint_b.vlan_id = svc_vlan_id elif ep_a_vlan_id is None and ep_b_vlan_id is not None: if ep_b_vlan_id != svc_vlan_id: MSG = 'Incompatible VLAN-IDs: endpoint_b({:s}), service({:s})' raise Exception(MSG.format(str(endpoint_b), str(svc_vlan_id))) device_a.vlan_ids.add(svc_vlan_id) endpoint_a.vlan_id = svc_vlan_id elif ep_a_vlan_id is not None and ep_b_vlan_id is not None: if ep_a_vlan_id != svc_vlan_id or ep_b_vlan_id != svc_vlan_id: Loading Loading
src/service/service/service_handlers/l2nm_gnmi_openconfig/ConfigRuleComposer.py +22 −11 Original line number Diff line number Diff line Loading @@ -60,7 +60,6 @@ class EndpointComposer: def __init__(self, endpoint_uuid : str) -> None: self.uuid = endpoint_uuid self.objekt : Optional[EndPoint] = None self.sub_interface_index = 0 self.vlan_id = None def configure(self, endpoint_obj : Optional[EndPoint], settings : Optional[TreeNode]) -> None: Loading @@ -71,35 +70,42 @@ class EndpointComposer: if 'vlan_id' in json_settings: self.vlan_id = json_settings['vlan_id'] self.sub_interface_index = json_settings.get('index', 0) elif 'vlan-id' in json_settings: self.vlan_id = json_settings['vlan-id'] else: MSG = 'VLAN ID not found. Tried: vlan_id and vlan-id. endpoint_obj={:s} settings={:s}' LOGGER.warning(MSG.format(grpc_message_to_json_string(endpoint_obj), str(settings))) def get_config_rules(self, network_instance_name : str, delete : bool = False) -> List[Dict]: config_rules : List[Dict] = list() if self.vlan_id is None: MSG = 'VLAN ID not defined for endpoint_obj={:s}' LOGGER.warning(MSG.format(grpc_message_to_json_string(self.objekt))) return config_rules json_config_rule = json_config_rule_delete if delete else json_config_rule_set config_rules : List[Dict] = list() if network_instance_name != DEFAULT_NETWORK_INSTANCE: config_rules.append(json_config_rule(*_network_instance_interface( network_instance_name, self.objekt.name, self.sub_interface_index network_instance_name, self.objekt.name, self.vlan_id ))) if delete: config_rules.extend([ json_config_rule(*_interface( self.objekt.name, index=self.sub_interface_index, vlan_id=self.vlan_id, enabled=False self.objekt.name, index=self.vlan_id, vlan_id=self.vlan_id, enabled=False )), ]) else: config_rules.extend([ json_config_rule(*_interface( self.objekt.name, index=self.sub_interface_index, vlan_id=self.vlan_id, enabled=True self.objekt.name, index=self.vlan_id, vlan_id=self.vlan_id, enabled=True )), ]) return config_rules def dump(self) -> Dict: return { 'index' : self.sub_interface_index, 'vlan_id' : self.vlan_id, } Loading Loading @@ -154,7 +160,7 @@ class DeviceComposer: match = RE_SUBIF.match(config_rule_custom.resource_key) if match is not None: if_name, subif_index = match.groups() if_name, _ = match.groups() if if_name in mgmt_ifaces: continue resource_value = json.loads(config_rule_custom.resource_value) if 'vlan_id' not in resource_value: continue Loading @@ -162,7 +168,6 @@ class DeviceComposer: self.vlan_ids.add(vlan_id) endpoint = self.get_endpoint(if_name) endpoint.vlan_id = vlan_id endpoint.sub_interface_index = int(subif_index) def get_config_rules(self, network_instance_name : str, delete : bool = False) -> List[Dict]: SELECTED_DEVICES = { Loading Loading @@ -191,7 +196,8 @@ class DeviceComposer: 'endpoints' : { endpoint_uuid : endpoint.dump() for endpoint_uuid, endpoint in self.endpoints.items() } }, 'vlan_ids' : list(self.vlan_ids) } def __str__(self): Loading Loading @@ -232,6 +238,11 @@ class ConfigRuleComposer: def get_config_rules( self, network_instance_name : str = NETWORK_INSTANCE, delete : bool = False ) -> Dict[str, List[Dict]]: if self.vlan_id is None: MSG = 'VLAN ID not defined for service_obj={:s}' LOGGER.warning(MSG.format(grpc_message_to_json_string(self.objekt))) return dict() return { device_uuid : device.get_config_rules(network_instance_name, delete=delete) for device_uuid, device in self.devices.items() Loading
src/service/service/service_handlers/l2nm_gnmi_openconfig/VlanIdPropagator.py +8 −2 Original line number Diff line number Diff line Loading @@ -64,27 +64,33 @@ class VlanIdPropagator: device_endpoint_a, device_endpoint_b = link_endpoints device_uuid_a, endpoint_uuid_a = device_endpoint_a[0:2] endpoint_a = self._config_rule_composer.get_device(device_uuid_a).get_endpoint(endpoint_uuid_a) device_a = self._config_rule_composer.get_device(device_uuid_a) endpoint_a = device_a.get_endpoint(endpoint_uuid_a) device_uuid_b, endpoint_uuid_b = device_endpoint_b[0:2] endpoint_b = self._config_rule_composer.get_device(device_uuid_b).get_endpoint(endpoint_uuid_b) device_b = self._config_rule_composer.get_device(device_uuid_b) endpoint_b = device_b.get_endpoint(endpoint_uuid_b) svc_vlan_id = self._config_rule_composer.vlan_id ep_a_vlan_id = endpoint_a.vlan_id ep_b_vlan_id = endpoint_b.vlan_id if ep_a_vlan_id is None and ep_b_vlan_id is None: device_a.vlan_ids.add(svc_vlan_id) endpoint_a.vlan_id = svc_vlan_id device_b.vlan_ids.add(svc_vlan_id) endpoint_b.vlan_id = svc_vlan_id elif ep_a_vlan_id is not None and ep_b_vlan_id is None: if ep_a_vlan_id != svc_vlan_id: MSG = 'Incompatible VLAN-IDs: endpoint_a({:s}), service({:s})' raise Exception(MSG.format(str(endpoint_a), str(svc_vlan_id))) device_b.vlan_ids.add(svc_vlan_id) endpoint_b.vlan_id = svc_vlan_id elif ep_a_vlan_id is None and ep_b_vlan_id is not None: if ep_b_vlan_id != svc_vlan_id: MSG = 'Incompatible VLAN-IDs: endpoint_b({:s}), service({:s})' raise Exception(MSG.format(str(endpoint_b), str(svc_vlan_id))) device_a.vlan_ids.add(svc_vlan_id) endpoint_a.vlan_id = svc_vlan_id elif ep_a_vlan_id is not None and ep_b_vlan_id is not None: if ep_a_vlan_id != svc_vlan_id or ep_b_vlan_id != svc_vlan_id: Loading