Loading src/device/service/drivers/openconfig/OpenConfigDriver.py +20 −22 Original line number Diff line number Diff line Loading @@ -55,7 +55,6 @@ RETRY_DECORATOR = retry(max_retries=MAX_RETRIES, delay_function=DELAY_FUNCTION, class NetconfSessionHandler: def __init__(self, address : str, port : int, **settings) -> None: mensaje = f"__init__: address={address}, port={port}, settings={settings}" self.__lock = threading.RLock() self.__connected = threading.Event() self.__address = address Loading Loading @@ -202,13 +201,13 @@ def do_sampling( except: # pylint: disable=bare-except logger.exception('Error retrieving samples') def edit_config( # edit the configuration of openconfig devices def edit_config( netconf_handler : NetconfSessionHandler, logger : logging.Logger, resources : List[Tuple[str, Any]], delete=False, commit_per_rule=False, target='running', default_operation='merge', test_option=None, error_option=None, format='xml' # pylint: disable=redefined-builtin ): str_method = 'DeleteConfig' if delete else 'SetConfig' logger.debug('[{:s}] resources = {:s}'.format(str_method, str(resources))) #logger.debug('[{:s}] resources = {:s}'.format(str_method, str(resources))) results = [None for _ in resources] for i,resource in enumerate(resources): str_resource_name = 'resources[#{:d}]'.format(i) Loading @@ -218,17 +217,17 @@ def edit_config( chk_length(str_resource_name, resource, min_length=2, max_length=2) resource_key,resource_value = resource chk_string(str_resource_name + '.key', resource_key, allow_empty=False) str_config_messages = compose_config( # get template for configuration str_config_messages = compose_config( resource_key, resource_value, delete=delete, vendor=netconf_handler.vendor, message_renderer=netconf_handler.message_renderer) for str_config_message in str_config_messages: # configuration of the received templates for str_config_message in str_config_messages: if str_config_message is None: raise UnsupportedResourceKeyException(resource_key) logger.debug('[{:s}] str_config_message[{:d}] = {:s}'.format( str_method, len(str_config_message), str(str_config_message))) netconf_handler.edit_config( # configure the device netconf_handler.edit_config( config=str_config_message, target=target, default_operation=default_operation, test_option=test_option, error_option=error_option, format=format) if commit_per_rule: netconf_handler.commit() # configuration commit netconf_handler.commit() results[i] = True except Exception as e: # pylint: disable=broad-except str_operation = 'preparing' if target == 'candidate' else ('deleting' if delete else 'setting') Loading Loading @@ -373,7 +372,6 @@ class OpenConfigDriver(_Driver): end_date = start_date + timedelta(seconds=sampling_duration) job_id = 'k={:s}/d={:f}/i={:f}'.format(resource_key, sampling_duration, sampling_interval) job = self.__scheduler.add_job( do_sampling, args=(self.__samples_cache, self.__logger, resource_key, self.__out_samples), kwargs={}, id=job_id, trigger='interval', seconds=sampling_interval, Loading Loading
src/device/service/drivers/openconfig/OpenConfigDriver.py +20 −22 Original line number Diff line number Diff line Loading @@ -55,7 +55,6 @@ RETRY_DECORATOR = retry(max_retries=MAX_RETRIES, delay_function=DELAY_FUNCTION, class NetconfSessionHandler: def __init__(self, address : str, port : int, **settings) -> None: mensaje = f"__init__: address={address}, port={port}, settings={settings}" self.__lock = threading.RLock() self.__connected = threading.Event() self.__address = address Loading Loading @@ -202,13 +201,13 @@ def do_sampling( except: # pylint: disable=bare-except logger.exception('Error retrieving samples') def edit_config( # edit the configuration of openconfig devices def edit_config( netconf_handler : NetconfSessionHandler, logger : logging.Logger, resources : List[Tuple[str, Any]], delete=False, commit_per_rule=False, target='running', default_operation='merge', test_option=None, error_option=None, format='xml' # pylint: disable=redefined-builtin ): str_method = 'DeleteConfig' if delete else 'SetConfig' logger.debug('[{:s}] resources = {:s}'.format(str_method, str(resources))) #logger.debug('[{:s}] resources = {:s}'.format(str_method, str(resources))) results = [None for _ in resources] for i,resource in enumerate(resources): str_resource_name = 'resources[#{:d}]'.format(i) Loading @@ -218,17 +217,17 @@ def edit_config( chk_length(str_resource_name, resource, min_length=2, max_length=2) resource_key,resource_value = resource chk_string(str_resource_name + '.key', resource_key, allow_empty=False) str_config_messages = compose_config( # get template for configuration str_config_messages = compose_config( resource_key, resource_value, delete=delete, vendor=netconf_handler.vendor, message_renderer=netconf_handler.message_renderer) for str_config_message in str_config_messages: # configuration of the received templates for str_config_message in str_config_messages: if str_config_message is None: raise UnsupportedResourceKeyException(resource_key) logger.debug('[{:s}] str_config_message[{:d}] = {:s}'.format( str_method, len(str_config_message), str(str_config_message))) netconf_handler.edit_config( # configure the device netconf_handler.edit_config( config=str_config_message, target=target, default_operation=default_operation, test_option=test_option, error_option=error_option, format=format) if commit_per_rule: netconf_handler.commit() # configuration commit netconf_handler.commit() results[i] = True except Exception as e: # pylint: disable=broad-except str_operation = 'preparing' if target == 'candidate' else ('deleting' if delete else 'setting') Loading Loading @@ -373,7 +372,6 @@ class OpenConfigDriver(_Driver): end_date = start_date + timedelta(seconds=sampling_duration) job_id = 'k={:s}/d={:f}/i={:f}'.format(resource_key, sampling_duration, sampling_interval) job = self.__scheduler.add_job( do_sampling, args=(self.__samples_cache, self.__logger, resource_key, self.__out_samples), kwargs={}, id=job_id, trigger='interval', seconds=sampling_interval, Loading