From a19d62a64ccf3fc64ec0a4e61b4a3d6ddfd40725 Mon Sep 17 00:00:00 2001 From: KB-perByte Date: Tue, 5 Mar 2024 16:07:56 +0530 Subject: [PATCH 1/5] add restore option --- plugins/cliconf/junos.py | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/plugins/cliconf/junos.py b/plugins/cliconf/junos.py index 75a2e23b..f51aa68f 100644 --- a/plugins/cliconf/junos.py +++ b/plugins/cliconf/junos.py @@ -53,8 +53,12 @@ from ansible.errors import AnsibleConnectionFailure from ansible.module_utils._text import to_text from ansible.module_utils.common._collections_compat import Mapping -from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import to_list -from ansible_collections.ansible.netcommon.plugins.plugin_utils.cliconf_base import CliconfBase +from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import ( + to_list, +) +from ansible_collections.ansible.netcommon.plugins.plugin_utils.cliconf_base import ( + CliconfBase, +) def configure(func): @@ -256,7 +260,12 @@ def compare_configuration(self, rollback_id=None): resp = self.send_command(command) r = resp.splitlines() - if len(r) == 1 and "[edit]" in r[0] or len(r) == 4 and r[1].startswith("- version"): + if ( + len(r) == 1 + and "[edit]" in r[0] + or len(r) == 4 + and r[1].startswith("- version") + ): resp = "" return resp @@ -272,6 +281,15 @@ def rollback(self, rollback_id, commit=True): self.discard_changes() return resp + @configure + def restore(self, filename=None, path=""): + if not filename: + raise ValueError("'file_name' value is required for restore") + cmd = f"load override {path}{filename}" + resp = self.send_command(cmd) + self.commit() + return resp + def get_diff(self, rollback_id=None): diff = {"config_diff": None} response = self.compare_configuration(rollback_id=rollback_id) From e4c7dfe8567d1c8c9040ffd71414b7d93b17fc49 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 5 Mar 2024 10:38:44 +0000 Subject: [PATCH 2/5] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- plugins/cliconf/junos.py | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/plugins/cliconf/junos.py b/plugins/cliconf/junos.py index f51aa68f..4461c9cb 100644 --- a/plugins/cliconf/junos.py +++ b/plugins/cliconf/junos.py @@ -53,12 +53,8 @@ from ansible.errors import AnsibleConnectionFailure from ansible.module_utils._text import to_text from ansible.module_utils.common._collections_compat import Mapping -from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import ( - to_list, -) -from ansible_collections.ansible.netcommon.plugins.plugin_utils.cliconf_base import ( - CliconfBase, -) +from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import to_list +from ansible_collections.ansible.netcommon.plugins.plugin_utils.cliconf_base import CliconfBase def configure(func): @@ -260,12 +256,7 @@ def compare_configuration(self, rollback_id=None): resp = self.send_command(command) r = resp.splitlines() - if ( - len(r) == 1 - and "[edit]" in r[0] - or len(r) == 4 - and r[1].startswith("- version") - ): + if len(r) == 1 and "[edit]" in r[0] or len(r) == 4 and r[1].startswith("- version"): resp = "" return resp From 8712ccc356867c886958d69fd11865122e9f4cd3 Mon Sep 17 00:00:00 2001 From: KB-perByte Date: Tue, 5 Mar 2024 17:46:47 +0530 Subject: [PATCH 3/5] fix api --- plugins/cliconf/junos.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/plugins/cliconf/junos.py b/plugins/cliconf/junos.py index 4461c9cb..bf126291 100644 --- a/plugins/cliconf/junos.py +++ b/plugins/cliconf/junos.py @@ -53,8 +53,12 @@ from ansible.errors import AnsibleConnectionFailure from ansible.module_utils._text import to_text from ansible.module_utils.common._collections_compat import Mapping -from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import to_list -from ansible_collections.ansible.netcommon.plugins.plugin_utils.cliconf_base import CliconfBase +from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import ( + to_list, +) +from ansible_collections.ansible.netcommon.plugins.plugin_utils.cliconf_base import ( + CliconfBase, +) def configure(func): @@ -256,7 +260,12 @@ def compare_configuration(self, rollback_id=None): resp = self.send_command(command) r = resp.splitlines() - if len(r) == 1 and "[edit]" in r[0] or len(r) == 4 and r[1].startswith("- version"): + if ( + len(r) == 1 + and "[edit]" in r[0] + or len(r) == 4 + and r[1].startswith("- version") + ): resp = "" return resp @@ -273,7 +282,7 @@ def rollback(self, rollback_id, commit=True): return resp @configure - def restore(self, filename=None, path=""): + def restore(self, filename=None, path="", force=None): if not filename: raise ValueError("'file_name' value is required for restore") cmd = f"load override {path}{filename}" From 61fb43376faf621bc1dc98c00184b67f5ac8cad4 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 5 Mar 2024 12:17:16 +0000 Subject: [PATCH 4/5] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- plugins/cliconf/junos.py | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/plugins/cliconf/junos.py b/plugins/cliconf/junos.py index bf126291..7e40787c 100644 --- a/plugins/cliconf/junos.py +++ b/plugins/cliconf/junos.py @@ -53,12 +53,8 @@ from ansible.errors import AnsibleConnectionFailure from ansible.module_utils._text import to_text from ansible.module_utils.common._collections_compat import Mapping -from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import ( - to_list, -) -from ansible_collections.ansible.netcommon.plugins.plugin_utils.cliconf_base import ( - CliconfBase, -) +from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import to_list +from ansible_collections.ansible.netcommon.plugins.plugin_utils.cliconf_base import CliconfBase def configure(func): @@ -260,12 +256,7 @@ def compare_configuration(self, rollback_id=None): resp = self.send_command(command) r = resp.splitlines() - if ( - len(r) == 1 - and "[edit]" in r[0] - or len(r) == 4 - and r[1].startswith("- version") - ): + if len(r) == 1 and "[edit]" in r[0] or len(r) == 4 and r[1].startswith("- version"): resp = "" return resp From 59557f7bd33c7906eecd51609d68c52d03de6b6e Mon Sep 17 00:00:00 2001 From: KB-perByte Date: Tue, 5 Mar 2024 17:56:41 +0530 Subject: [PATCH 5/5] fix changes --- plugins/cliconf/junos.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/cliconf/junos.py b/plugins/cliconf/junos.py index 7e40787c..4461c9cb 100644 --- a/plugins/cliconf/junos.py +++ b/plugins/cliconf/junos.py @@ -273,7 +273,7 @@ def rollback(self, rollback_id, commit=True): return resp @configure - def restore(self, filename=None, path="", force=None): + def restore(self, filename=None, path=""): if not filename: raise ValueError("'file_name' value is required for restore") cmd = f"load override {path}{filename}"