Skip to content

Commit

Permalink
EOS add force_cfg_session_invalid argument (#1927)
Browse files Browse the repository at this point in the history
Co-authored-by: Kevin Petremann <k.petremann@criteo.com>
  • Loading branch information
ktbyers and kpetremann committed May 19, 2023
1 parent cb4845c commit f1ce50e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
1 change: 1 addition & 0 deletions docs/support/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ ____________________________________
* :code:`eos_fn0039_config` (eos) - Transform old style configuration to the new style, available beginning with EOS release 4.23.0, as per FN 0039. Beware
that enabling this option will change the configuration you're loading through NAPALM. Default: ``False`` (won't change your configuration commands).
.. versionadded:: 3.0.1
* :code:`force_cfg_session_invalid` (eos) - Force the config_session to be cleared in case of issues, like `discard_config` failure. (default: ``False``)

The transport argument
______________________
Expand Down
18 changes: 15 additions & 3 deletions napalm/eos/eos.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ def __init__(self, hostname, username, password, timeout=60, optional_args=None)
Optional args:
* lock_disable (True/False): force configuration lock to be disabled (for external lock
management).
* force_cfg_session_invalid (True/False): force invalidation of the config session
in case of failure.
* enable_password (True/False): Enable password for privilege elevation
* eos_autoComplete (True/False): Allow for shortening of cli commands
* transport (string): transport, eos_transport is a fallback for compatibility.
Expand Down Expand Up @@ -134,6 +136,10 @@ def __init__(self, hostname, username, password, timeout=60, optional_args=None)
# Define locking method
self.lock_disable = self.optional_args.pop("lock_disable", False)

self.force_cfg_session_invalid = self.optional_args.pop(
"force_cfg_session_invalid", False
)

# eos_transport is there for backwards compatibility, transport is the preferred method
transport = self.optional_args.get(
"transport", self.optional_args.get("eos_transport", "https")
Expand All @@ -150,7 +156,6 @@ def _process_optional_args_ssh(self, optional_args):
self.netmiko_optional_args = netmiko_args(optional_args)

def _process_optional_args_eapi(self, optional_args):

# Parse pyeapi transport class
self.transport_class = self._parse_transport(self.transport)

Expand Down Expand Up @@ -543,8 +548,15 @@ def confirm_commit(self):
def discard_config(self):
"""Implementation of NAPALM method discard_config."""
if self.config_session is not None:
commands = [f"configure session {self.config_session} abort"]
self._run_commands(commands, encoding="text")
try:
commands = [f"configure session {self.config_session} abort"]
self._run_commands(commands, encoding="text")
except Exception:
# If discard fails, you might want to invalidate the config_session (esp. Salt)
# The config_session in EOS is used as the config lock.
if self.force_cfg_session_invalid:
self.config_session = None
raise
self.config_session = None

def rollback(self):
Expand Down

0 comments on commit f1ce50e

Please sign in to comment.