Skip to content
Snippets Groups Projects
Commit b596c12e authored by PabloArmingolRobles's avatar PabloArmingolRobles
Browse files

Commit per delete rule

parent d36a6c29
No related branches found
No related tags found
2 merge requests!54Release 2.0.0,!4Compute component:
......@@ -67,6 +67,7 @@ class NetconfSessionHandler:
self.__look_for_keys = settings.get('look_for_keys', True)
self.__allow_agent = settings.get('allow_agent', True)
self.__force_running = settings.get('force_running', False)
self.__commit_per_delete = settings.get('delete_rule', False)
self.__device_params = settings.get('device_params', {})
self.__manager_params = settings.get('manager_params', {})
self.__nc_params = settings.get('nc_params', {})
......@@ -91,6 +92,9 @@ class NetconfSessionHandler:
@property
def use_candidate(self): return self.__candidate_supported and not self.__force_running
@property
def commit_per_delete_rule(self): return self.__commit_per_delete
@RETRY_DECORATOR
def get(self, filter=None, with_defaults=None): # pylint: disable=redefined-builtin
with self.__lock:
......@@ -182,8 +186,8 @@ def do_sampling(samples_cache : SamplesCache, resource_key : str, out_samples :
LOGGER.exception('Error retrieving samples')
def edit_config(
netconf_handler : NetconfSessionHandler, resources : List[Tuple[str, Any]], delete=False, target='running',
default_operation='merge', test_option=None, error_option=None, format='xml' # pylint: disable=redefined-builtin
netconf_handler : NetconfSessionHandler, 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.info('[{:s}] resources = {:s}'.format(str_method, str(resources)))
......@@ -203,6 +207,8 @@ def edit_config(
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()
results[i] = True
except Exception as e: # pylint: disable=broad-except
str_operation = 'preparing' if target == 'candidate' else ('deleting' if delete else 'setting')
......@@ -295,12 +301,15 @@ class OpenConfigDriver(_Driver):
with self.__lock:
if self.__netconf_handler.use_candidate:
with self.__netconf_handler.locked(target='candidate'):
results = edit_config(self.__netconf_handler, resources, target='candidate', delete=True)
try:
self.__netconf_handler.commit()
except Exception as e: # pylint: disable=broad-except
LOGGER.exception('[DeleteConfig] Exception commiting resources: {:s}'.format(str(resources)))
results = [e for _ in resources] # if commit fails, set exception in each resource
if self.__netconf_handler.commit_per_delete_rule:
results = edit_config(self.__netconf_handler, resources, target='candidate', delete=True, commit_per_rule= True)
else:
results = edit_config(self.__netconf_handler, resources, target='candidate', delete=True)
try:
self.__netconf_handler.commit()
except Exception as e: # pylint: disable=broad-except
LOGGER.exception('[DeleteConfig] Exception commiting resources: {:s}'.format(str(resources)))
results = [e for _ in resources] # if commit fails, set exception in each resource
else:
results = edit_config(self.__netconf_handler, resources, delete=True)
return results
......
......@@ -32,6 +32,7 @@ DEVICE_OC_CONNECT_RULES = json_device_connect_rules(DEVICE_OC_ADDRESS, DEVICE_OC
'hostkey_verify' : True,
'look_for_keys' : True,
'allow_agent' : True,
'delete_rule' : False,
'device_params' : {'name': 'default'},
'manager_params' : {'timeout' : DEVICE_OC_TIMEOUT},
})
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment