diff --git a/docs/support/index.rst b/docs/support/index.rst index 214c0fd42..d1c1726a7 100644 --- a/docs/support/index.rst +++ b/docs/support/index.rst @@ -133,6 +133,13 @@ ____________________________________ * :code:`transport` (eos, ios, nxos) - Protocol to connect with (see `The transport argument`_ for more information). * :code:`use_keys` (ios, iosxr, nxos_ssh) - Paramiko argument, enable searching for discoverable private key files in ``~/.ssh/`` (default: ``False``). * :code:`eos_autoComplete` (eos) - Allows to set `autoComplete` when running commands. (default: ``None`` equivalent to ``False``) +* :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 The transport argument ______________________ diff --git a/napalm/eos/eos.py b/napalm/eos/eos.py index bc3e3ff1d..93128ca2c 100644 --- a/napalm/eos/eos.py +++ b/napalm/eos/eos.py @@ -129,6 +129,7 @@ def _process_optional_args(self, optional_args): transport = optional_args.get( "transport", optional_args.get("eos_transport", "https") ) + self.fn0039_config = optional_args.pop("eos_fn0039_config", False) try: self.transport_class = pyeapi.client.TRANSPORTS[transport] except KeyError: @@ -285,9 +286,13 @@ def _load_config(self, filename=None, config=None, replace=True): try: if self.eos_autoComplete is not None: - self.device.run_commands(commands, autoComplete=self.eos_autoComplete) + self.device.run_commands( + commands, + autoComplete=self.eos_autoComplete, + fn0039_transform=self.fn0039_config, + ) else: - self.device.run_commands(commands) + self.device.run_commands(commands, fn0039_transform=self.fn0039_config) except pyeapi.eapilib.CommandError as e: self.discard_config() msg = str(e) diff --git a/napalm/eos/pyeapi_syntax_wrapper.py b/napalm/eos/pyeapi_syntax_wrapper.py index 695282860..246b185c9 100644 --- a/napalm/eos/pyeapi_syntax_wrapper.py +++ b/napalm/eos/pyeapi_syntax_wrapper.py @@ -32,9 +32,11 @@ def run_commands(self, commands, **kwargs): :param kwargs: other args :return: list of outputs """ - if isinstance(commands, str): - new_commands = [cli_convert(commands, self.cli_version)] - else: - new_commands = [cli_convert(cmd, self.cli_version) for cmd in commands] + fn0039_transform = kwargs.pop("fn0039_transform", True) + if fn0039_transform: + if isinstance(commands, str): + commands = [cli_convert(commands, self.cli_version)] + else: + commands = [cli_convert(cmd, self.cli_version) for cmd in commands] - return super(Node, self).run_commands(new_commands, **kwargs) + return super(Node, self).run_commands(commands, **kwargs) diff --git a/test/eos/test_heredoc.py b/test/eos/test_heredoc.py index 7ffd1bfb6..df9e48012 100644 --- a/test/eos/test_heredoc.py +++ b/test/eos/test_heredoc.py @@ -57,7 +57,9 @@ def test_heredoc(self): "idle-timeout 15", ] - self.device.device.run_commands.assert_called_with(expected_result) + self.device.device.run_commands.assert_called_with( + expected_result, fn0039_transform=False + ) def test_mode_comment(self): raw_config = dedent( @@ -108,7 +110,9 @@ def test_mode_comment(self): "permit host 192.0.2.3", ] - self.device.device.run_commands.assert_called_with(expected_result) + self.device.device.run_commands.assert_called_with( + expected_result, fn0039_transform=False + ) def test_heredoc_with_bangs(self): @@ -145,4 +149,6 @@ def test_heredoc_with_bangs(self): "idle-timeout 15", ] - self.device.device.run_commands.assert_called_with(expected_result) + self.device.device.run_commands.assert_called_with( + expected_result, fn0039_transform=False + )