Loading src/context/service/database/OpticalConfig.py +2 −1 Changes for src/context/service/database/OpticalConfig.py: 2 added lines, 1 removed line. Original line number Diff line number Diff line Loading @@ -664,7 +664,8 @@ def delete_opticalchannel(db_engine : Engine, messagebroker : MessageBroker, req if 'flow' in config: if config_type == DeviceTypeEnum.OPTICAL_TRANSPONDER._value_: for flow in config['flow']: src,dest = flow # point-to-multipoint flows also carry their slots: (src, dest, slots[, op_mode]) src, dest = flow[0], flow[1] channel_index= src if src is not None and src!='0' else dest channel_name= f"channel-{channel_index}" channels.append({ Loading src/device/service/Tools.py +15 −1 Changes for src/device/service/Tools.py: 15 added lines, 1 removed line. Original line number Diff line number Diff line Loading @@ -756,7 +756,6 @@ def extract_resources(config : dict, device : Device) -> list[list[dict], dict]: resources.append(is_key_existed('Band', keys_dic=new_config)) resources.append(is_key_existed('line-port', keys_dic=new_config)) resources.append({'resource_key': 'admin-state', 'value': 'ENABLED'} if 'status' in new_config and new_config['status'] else is_key_existed('status', keys_dic=new_config, key_name_to_use="admin-state")) resources.append(is_key_existed('status', keys_dic=new_config, key_name_to_use="admin-state")) resources.append(is_key_existed('band_type', keys_dic=new_config, key_name_to_use='name')) resources.append(is_key_existed('ob_id', keys_dic=new_config, key_name_to_use='optical-band-parent')) resources.append(is_key_existed('bidir', keys_dic=new_config)) Loading Loading @@ -1002,6 +1001,21 @@ def extract_resources(config : dict, device : Device) -> list[list[dict], dict]: {'resource_key': 'band', 'value': last_params['bandwidth']} ]) # The ROADM templates (create/disable media channel and optical band) identify the # element by its 'index' (flow_id for media channels, ob_id for optical bands) and # need its frequency range; slot-based (DSCM) flows already provide the range above. if is_opticalband: resources.append(is_key_existed('ob_id', keys_dic=new_config, key_name_to_use='index')) resources.append({'resource_key': 'lower-frequency', 'value': new_config.get('low-freq')}) resources.append({'resource_key': 'upper-frequency', 'value': new_config.get('up-freq')}) elif conditions['edit_type'] == 'media-channel': resources.append(flow_id) has_range = any(r.get('resource_key') == 'lower-frequency' for r in resources) frequency, band = new_config.get('frequency'), new_config.get('band') if not has_range and frequency is not None and band is not None: resources.append({'resource_key': 'lower-frequency', 'value': int(int(frequency) - int(band) / 2 + 1)}) resources.append({'resource_key': 'upper-frequency', 'value': int(int(frequency) + int(band) / 2)}) return resources, conditions Loading src/device/service/driver_api/DriverInstanceCache.py +8 −1 Changes for src/device/service/driver_api/DriverInstanceCache.py: 8 added lines, 1 removed line. Original line number Diff line number Diff line Loading @@ -117,4 +117,11 @@ def get_driver(driver_instance_cache : DriverInstanceCache, device : Device) -> def preload_drivers(driver_instance_cache : DriverInstanceCache) -> None: context_client = ContextClient() devices = context_client.ListDevices(Empty()) for device in devices.devices: get_driver(driver_instance_cache, device) for device in devices.devices: # An unreachable device must not take the whole Device component down at startup; # its driver is instantiated again on the next request that needs it. try: get_driver(driver_instance_cache, device) except: # pylint: disable=bare-except msg = 'Unable to pre-load driver for Device({:s}); skipping it' LOGGER.exception(msg.format(device.device_id.device_uuid.uuid)) src/device/service/drivers/oc_driver/OCDriver.py +7 −0 Changes for src/device/service/drivers/oc_driver/OCDriver.py: 7 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -87,6 +87,13 @@ class NetconfSessionHandler: def connect(self): with self.__lock: # Reconnecting (e.g. from RETRY_DECORATOR after the device dropped the session): # release the previous session first so it does not linger on the device. if self.__manager is not None and self.__manager.connected: try: self.__manager.close_session() except Exception: # pylint: disable=broad-except pass self.__manager = connect_ssh( host=self.__address, port=self.__port, username=self.__username, password=self.__password, device_params=self.__device_params, manager_params=self.__manager_params, nc_params=self.__nc_params, Loading src/device/service/drivers/oc_driver/RetryDecorator.py +7 −2 Changes for src/device/service/drivers/oc_driver/RetryDecorator.py: 7 added lines, 2 removed lines. Original line number Diff line number Diff line Loading @@ -13,6 +13,7 @@ # limitations under the License. import logging, time from ncclient.transport.errors import TransportError from common.tools.client.RetryDecorator import delay_linear LOGGER = logging.getLogger(__name__) Loading @@ -28,8 +29,12 @@ def retry(max_retries=0, delay_function=delay_linear(initial=0, increment=0), while not given_up: try: return func(self, *args, **kwargs) except OSError as e: if str(e) != 'Socket is closed': raise except (OSError, TransportError) as e: # A NETCONF session dropped by the device surfaces as TransportError # ("Not connected to NETCONF server", SessionCloseError, ...): reconnect # and retry like a closed socket. RPCErrors (device rejected the request) # are not TransportErrors and are raised straight away. if isinstance(e, OSError) and str(e) != 'Socket is closed': raise num_try += 1 given_up = num_try > max_retries Loading Loading
src/context/service/database/OpticalConfig.py +2 −1 Changes for src/context/service/database/OpticalConfig.py: 2 added lines, 1 removed line. Original line number Diff line number Diff line Loading @@ -664,7 +664,8 @@ def delete_opticalchannel(db_engine : Engine, messagebroker : MessageBroker, req if 'flow' in config: if config_type == DeviceTypeEnum.OPTICAL_TRANSPONDER._value_: for flow in config['flow']: src,dest = flow # point-to-multipoint flows also carry their slots: (src, dest, slots[, op_mode]) src, dest = flow[0], flow[1] channel_index= src if src is not None and src!='0' else dest channel_name= f"channel-{channel_index}" channels.append({ Loading
src/device/service/Tools.py +15 −1 Changes for src/device/service/Tools.py: 15 added lines, 1 removed line. Original line number Diff line number Diff line Loading @@ -756,7 +756,6 @@ def extract_resources(config : dict, device : Device) -> list[list[dict], dict]: resources.append(is_key_existed('Band', keys_dic=new_config)) resources.append(is_key_existed('line-port', keys_dic=new_config)) resources.append({'resource_key': 'admin-state', 'value': 'ENABLED'} if 'status' in new_config and new_config['status'] else is_key_existed('status', keys_dic=new_config, key_name_to_use="admin-state")) resources.append(is_key_existed('status', keys_dic=new_config, key_name_to_use="admin-state")) resources.append(is_key_existed('band_type', keys_dic=new_config, key_name_to_use='name')) resources.append(is_key_existed('ob_id', keys_dic=new_config, key_name_to_use='optical-band-parent')) resources.append(is_key_existed('bidir', keys_dic=new_config)) Loading Loading @@ -1002,6 +1001,21 @@ def extract_resources(config : dict, device : Device) -> list[list[dict], dict]: {'resource_key': 'band', 'value': last_params['bandwidth']} ]) # The ROADM templates (create/disable media channel and optical band) identify the # element by its 'index' (flow_id for media channels, ob_id for optical bands) and # need its frequency range; slot-based (DSCM) flows already provide the range above. if is_opticalband: resources.append(is_key_existed('ob_id', keys_dic=new_config, key_name_to_use='index')) resources.append({'resource_key': 'lower-frequency', 'value': new_config.get('low-freq')}) resources.append({'resource_key': 'upper-frequency', 'value': new_config.get('up-freq')}) elif conditions['edit_type'] == 'media-channel': resources.append(flow_id) has_range = any(r.get('resource_key') == 'lower-frequency' for r in resources) frequency, band = new_config.get('frequency'), new_config.get('band') if not has_range and frequency is not None and band is not None: resources.append({'resource_key': 'lower-frequency', 'value': int(int(frequency) - int(band) / 2 + 1)}) resources.append({'resource_key': 'upper-frequency', 'value': int(int(frequency) + int(band) / 2)}) return resources, conditions Loading
src/device/service/driver_api/DriverInstanceCache.py +8 −1 Changes for src/device/service/driver_api/DriverInstanceCache.py: 8 added lines, 1 removed line. Original line number Diff line number Diff line Loading @@ -117,4 +117,11 @@ def get_driver(driver_instance_cache : DriverInstanceCache, device : Device) -> def preload_drivers(driver_instance_cache : DriverInstanceCache) -> None: context_client = ContextClient() devices = context_client.ListDevices(Empty()) for device in devices.devices: get_driver(driver_instance_cache, device) for device in devices.devices: # An unreachable device must not take the whole Device component down at startup; # its driver is instantiated again on the next request that needs it. try: get_driver(driver_instance_cache, device) except: # pylint: disable=bare-except msg = 'Unable to pre-load driver for Device({:s}); skipping it' LOGGER.exception(msg.format(device.device_id.device_uuid.uuid))
src/device/service/drivers/oc_driver/OCDriver.py +7 −0 Changes for src/device/service/drivers/oc_driver/OCDriver.py: 7 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -87,6 +87,13 @@ class NetconfSessionHandler: def connect(self): with self.__lock: # Reconnecting (e.g. from RETRY_DECORATOR after the device dropped the session): # release the previous session first so it does not linger on the device. if self.__manager is not None and self.__manager.connected: try: self.__manager.close_session() except Exception: # pylint: disable=broad-except pass self.__manager = connect_ssh( host=self.__address, port=self.__port, username=self.__username, password=self.__password, device_params=self.__device_params, manager_params=self.__manager_params, nc_params=self.__nc_params, Loading
src/device/service/drivers/oc_driver/RetryDecorator.py +7 −2 Changes for src/device/service/drivers/oc_driver/RetryDecorator.py: 7 added lines, 2 removed lines. Original line number Diff line number Diff line Loading @@ -13,6 +13,7 @@ # limitations under the License. import logging, time from ncclient.transport.errors import TransportError from common.tools.client.RetryDecorator import delay_linear LOGGER = logging.getLogger(__name__) Loading @@ -28,8 +29,12 @@ def retry(max_retries=0, delay_function=delay_linear(initial=0, increment=0), while not given_up: try: return func(self, *args, **kwargs) except OSError as e: if str(e) != 'Socket is closed': raise except (OSError, TransportError) as e: # A NETCONF session dropped by the device surfaces as TransportError # ("Not connected to NETCONF server", SessionCloseError, ...): reconnect # and retry like a closed socket. RPCErrors (device rejected the request) # are not TransportErrors and are raised straight away. if isinstance(e, OSError) and str(e) != 'Socket is closed': raise num_try += 1 given_up = num_try > max_retries Loading