Loading src/common/tools/rest_conf/client/RestConfClient.py +1 −1 Original line number Diff line number Diff line Loading @@ -26,7 +26,7 @@ class RestConfClient(RestApiClient): username : Optional[str] = None, password : Optional[str] = None, restconf_version : Optional[str] = None, timeout : int = 30, verify_certs : bool = True, allow_redirects : bool = True, logger : Optional[logging.Logger] = None logger : Optional[logging.Logger] = None, **kwargs ) -> None: super().__init__( address, port=port, scheme=scheme, username=username, password=password, Loading src/device/service/DeviceServiceServicerImpl.py +5 −1 Original line number Diff line number Diff line Loading @@ -37,7 +37,7 @@ from .Tools import ( check_connect_rules, check_no_endpoints, compute_rules_to_add_delete, configure_rules, deconfigure_rules, get_device_controller_uuid, populate_config_rules, populate_endpoint_monitoring_resources, populate_endpoints, populate_initial_config_rules, subscribe_kpi, unsubscribe_kpi, update_endpoints subscribe_kpi, unsubscribe_kpi, update_endpoints, update_sap_id, ) LOGGER = logging.getLogger(__name__) Loading @@ -55,6 +55,7 @@ class DeviceServiceServicerImpl(DeviceServiceServicer): self.monitoring_loops = monitoring_loops self.mutex_queues = MutexQueues() LOGGER.debug('Servicer Created') self.sap_id =0 @safe_and_metered_rpc_method(METRICS_POOL, LOGGER) def AddDevice(self, request : Device, context : grpc.ServicerContext) -> DeviceId: Loading Loading @@ -93,6 +94,9 @@ class DeviceServiceServicerImpl(DeviceServiceServicer): device_uuid = device.device_id.device_uuid.uuid device_name = device.name update_sap_id(device, self.sap_id) self.sap_id += 1 t2 = time.time() self.mutex_queues.add_alias(device_uuid, device_name) Loading src/device/service/Tools.py +20 −0 Original line number Diff line number Diff line Loading @@ -719,3 +719,23 @@ def extract_resources(config : dict, device : Device) -> list[list[dict], dict]: resources.append({'resource_key': 'upper-frequency', 'value': upper_frequency}) return [resources, conditions] def update_sap_id(device: Device, sap_id: int) -> None: found = False for config_rule in device.device_config.config_rules: if config_rule.WhichOneof('config_rule') == 'custom' and config_rule.custom.resource_key == '_connect/settings': try: settings = json.loads(config_rule.custom.resource_value) except ValueError: settings = {} settings['sap_id'] = str(sap_id) config_rule.custom.resource_value = json.dumps(settings) found = True break if not found: new_rule = device.device_config.config_rules.add() new_rule.action = ConfigActionEnum.CONFIGACTION_SET new_rule.custom.resource_key = '_connect/settings' settings = {'sap_id': str(sap_id)} new_rule.custom.resource_value = json.dumps(settings) src/device/service/drivers/openconfig/OpenConfigDriver.py +2 −0 Original line number Diff line number Diff line Loading @@ -294,6 +294,7 @@ class OpenConfigDriver(_Driver): self.__out_samples = queue.Queue() self.__netconf_handler = NetconfSessionHandler(self.address, self.port, **(self.settings)) self.__samples_cache = SamplesCache(self.__netconf_handler, self.__logger) self.sap_id = 0 # Initialize sap_id to zero def Connect(self) -> bool: with self.__lock: Loading Loading @@ -340,6 +341,7 @@ class OpenConfigDriver(_Driver): MSG = 'Exception retrieving {:s}: {:s}' self.__logger.exception(MSG.format(str_resource_name, str(resource_key))) results.append((resource_key, e)) # if validation fails, store the exception self.sap_id += 1 return results @metered_subclass_method(METRICS_POOL) Loading src/device/service/drivers/openconfig/templates/Interfaces.py +15 −0 Original line number Diff line number Diff line Loading @@ -26,6 +26,7 @@ XPATH_IPV6ADDRESSES = ".//ociip:ipv6/ociip:addresses/ociip:address" def parse(xml_data : ET.Element) -> List[Tuple[str, Dict[str, Any]]]: response = [] sap_interface_counter = 0 for xml_interface in xml_data.xpath(XPATH_INTERFACES, namespaces=NAMESPACES): #LOGGER.info('xml_interface = {:s}'.format(str(ET.tostring(xml_interface)))) Loading @@ -44,6 +45,12 @@ def parse(xml_data : ET.Element) -> List[Tuple[str, Dict[str, Any]]]: if interface_name is None or interface_name.text is None: continue add_value_from_tag(interface, 'name', interface_name) sap_interface = ET.Element('dummy') sap_interface.text =str(sap_interface_counter) aux =str(sap_interface_counter) add_value_from_tag(interface, 'sap_id', sap_interface) sap_interface_counter += 1 # Get the type of interface according to the vendor's type if 'ianaift:' in interface_type.text: interface_type.text = interface_type.text.replace('ianaift:', '') #ADVA Loading @@ -57,6 +64,8 @@ def parse(xml_data : ET.Element) -> List[Tuple[str, Dict[str, Any]]]: interface_description = xml_interface.find('oci:config/oci:description', namespaces=NAMESPACES) add_value_from_tag(interface, 'description', interface_description) sap_subinterface_counter = 65 for xml_subinterface in xml_interface.xpath(XPATH_SUBINTERFACES, namespaces=NAMESPACES): #LOGGER.info('xml_subinterface = {:s}'.format(str(ET.tostring(xml_subinterface)))) Loading @@ -74,6 +83,12 @@ def parse(xml_data : ET.Element) -> List[Tuple[str, Dict[str, Any]]]: vlan_id = xml_subinterface.find('ocv:vlan/ocv:match/ocv:single-tagged/ocv:config/ocv:vlan-id', namespaces=NAMESPACES) add_value_from_tag(subinterface, 'vlan_id', vlan_id, cast=int) sap_subinterface = ET.Element('dummy') value = (aux + chr(sap_subinterface_counter)) sap_subinterface.text = value add_value_from_tag(subinterface, 'sap_id', sap_subinterface) sap_subinterface_counter += 1 # TODO: implement support for multiple IP addresses per subinterface #ipv4_addresses = [] for xml_ipv4_address in xml_subinterface.xpath(XPATH_IPV4ADDRESSES, namespaces=NAMESPACES): Loading Loading
src/common/tools/rest_conf/client/RestConfClient.py +1 −1 Original line number Diff line number Diff line Loading @@ -26,7 +26,7 @@ class RestConfClient(RestApiClient): username : Optional[str] = None, password : Optional[str] = None, restconf_version : Optional[str] = None, timeout : int = 30, verify_certs : bool = True, allow_redirects : bool = True, logger : Optional[logging.Logger] = None logger : Optional[logging.Logger] = None, **kwargs ) -> None: super().__init__( address, port=port, scheme=scheme, username=username, password=password, Loading
src/device/service/DeviceServiceServicerImpl.py +5 −1 Original line number Diff line number Diff line Loading @@ -37,7 +37,7 @@ from .Tools import ( check_connect_rules, check_no_endpoints, compute_rules_to_add_delete, configure_rules, deconfigure_rules, get_device_controller_uuid, populate_config_rules, populate_endpoint_monitoring_resources, populate_endpoints, populate_initial_config_rules, subscribe_kpi, unsubscribe_kpi, update_endpoints subscribe_kpi, unsubscribe_kpi, update_endpoints, update_sap_id, ) LOGGER = logging.getLogger(__name__) Loading @@ -55,6 +55,7 @@ class DeviceServiceServicerImpl(DeviceServiceServicer): self.monitoring_loops = monitoring_loops self.mutex_queues = MutexQueues() LOGGER.debug('Servicer Created') self.sap_id =0 @safe_and_metered_rpc_method(METRICS_POOL, LOGGER) def AddDevice(self, request : Device, context : grpc.ServicerContext) -> DeviceId: Loading Loading @@ -93,6 +94,9 @@ class DeviceServiceServicerImpl(DeviceServiceServicer): device_uuid = device.device_id.device_uuid.uuid device_name = device.name update_sap_id(device, self.sap_id) self.sap_id += 1 t2 = time.time() self.mutex_queues.add_alias(device_uuid, device_name) Loading
src/device/service/Tools.py +20 −0 Original line number Diff line number Diff line Loading @@ -719,3 +719,23 @@ def extract_resources(config : dict, device : Device) -> list[list[dict], dict]: resources.append({'resource_key': 'upper-frequency', 'value': upper_frequency}) return [resources, conditions] def update_sap_id(device: Device, sap_id: int) -> None: found = False for config_rule in device.device_config.config_rules: if config_rule.WhichOneof('config_rule') == 'custom' and config_rule.custom.resource_key == '_connect/settings': try: settings = json.loads(config_rule.custom.resource_value) except ValueError: settings = {} settings['sap_id'] = str(sap_id) config_rule.custom.resource_value = json.dumps(settings) found = True break if not found: new_rule = device.device_config.config_rules.add() new_rule.action = ConfigActionEnum.CONFIGACTION_SET new_rule.custom.resource_key = '_connect/settings' settings = {'sap_id': str(sap_id)} new_rule.custom.resource_value = json.dumps(settings)
src/device/service/drivers/openconfig/OpenConfigDriver.py +2 −0 Original line number Diff line number Diff line Loading @@ -294,6 +294,7 @@ class OpenConfigDriver(_Driver): self.__out_samples = queue.Queue() self.__netconf_handler = NetconfSessionHandler(self.address, self.port, **(self.settings)) self.__samples_cache = SamplesCache(self.__netconf_handler, self.__logger) self.sap_id = 0 # Initialize sap_id to zero def Connect(self) -> bool: with self.__lock: Loading Loading @@ -340,6 +341,7 @@ class OpenConfigDriver(_Driver): MSG = 'Exception retrieving {:s}: {:s}' self.__logger.exception(MSG.format(str_resource_name, str(resource_key))) results.append((resource_key, e)) # if validation fails, store the exception self.sap_id += 1 return results @metered_subclass_method(METRICS_POOL) Loading
src/device/service/drivers/openconfig/templates/Interfaces.py +15 −0 Original line number Diff line number Diff line Loading @@ -26,6 +26,7 @@ XPATH_IPV6ADDRESSES = ".//ociip:ipv6/ociip:addresses/ociip:address" def parse(xml_data : ET.Element) -> List[Tuple[str, Dict[str, Any]]]: response = [] sap_interface_counter = 0 for xml_interface in xml_data.xpath(XPATH_INTERFACES, namespaces=NAMESPACES): #LOGGER.info('xml_interface = {:s}'.format(str(ET.tostring(xml_interface)))) Loading @@ -44,6 +45,12 @@ def parse(xml_data : ET.Element) -> List[Tuple[str, Dict[str, Any]]]: if interface_name is None or interface_name.text is None: continue add_value_from_tag(interface, 'name', interface_name) sap_interface = ET.Element('dummy') sap_interface.text =str(sap_interface_counter) aux =str(sap_interface_counter) add_value_from_tag(interface, 'sap_id', sap_interface) sap_interface_counter += 1 # Get the type of interface according to the vendor's type if 'ianaift:' in interface_type.text: interface_type.text = interface_type.text.replace('ianaift:', '') #ADVA Loading @@ -57,6 +64,8 @@ def parse(xml_data : ET.Element) -> List[Tuple[str, Dict[str, Any]]]: interface_description = xml_interface.find('oci:config/oci:description', namespaces=NAMESPACES) add_value_from_tag(interface, 'description', interface_description) sap_subinterface_counter = 65 for xml_subinterface in xml_interface.xpath(XPATH_SUBINTERFACES, namespaces=NAMESPACES): #LOGGER.info('xml_subinterface = {:s}'.format(str(ET.tostring(xml_subinterface)))) Loading @@ -74,6 +83,12 @@ def parse(xml_data : ET.Element) -> List[Tuple[str, Dict[str, Any]]]: vlan_id = xml_subinterface.find('ocv:vlan/ocv:match/ocv:single-tagged/ocv:config/ocv:vlan-id', namespaces=NAMESPACES) add_value_from_tag(subinterface, 'vlan_id', vlan_id, cast=int) sap_subinterface = ET.Element('dummy') value = (aux + chr(sap_subinterface_counter)) sap_subinterface.text = value add_value_from_tag(subinterface, 'sap_id', sap_subinterface) sap_subinterface_counter += 1 # TODO: implement support for multiple IP addresses per subinterface #ipv4_addresses = [] for xml_ipv4_address in xml_subinterface.xpath(XPATH_IPV4ADDRESSES, namespaces=NAMESPACES): Loading