From 92f79a63f83d5182b3f1572b5bd5ca15341ed942 Mon Sep 17 00:00:00 2001 From: rohitthakur2590 Date: Fri, 9 May 2025 15:17:39 +0530 Subject: [PATCH 1/3] fixcopytorun Signed-off-by: rohitthakur2590 --- plugins/module_utils/network/netconf/netconf.py | 9 +++++++++ plugins/modules/netconf_config.py | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/plugins/module_utils/network/netconf/netconf.py b/plugins/module_utils/network/netconf/netconf.py index 6e31b5e3e..ac400d2d3 100644 --- a/plugins/module_utils/network/netconf/netconf.py +++ b/plugins/module_utils/network/netconf/netconf.py @@ -132,3 +132,12 @@ def sanitize_xml(data): if key not in IGNORE_XML_ATTRIBUTE: attribute.pop(key) return to_text(tostring(tree), errors="surrogate_then_replace").strip() + +def copy_config(module, source, target): + conn = get_connection(module) + try: + response = conn.copy_config(source=source, target=target) + except ConnectionError as e: + module.fail_json(msg=to_text(e, errors="surrogate_then_replace").strip()) + return response + diff --git a/plugins/modules/netconf_config.py b/plugins/modules/netconf_config.py index 87c1c9c01..66d7baa83 100644 --- a/plugins/modules/netconf_config.py +++ b/plugins/modules/netconf_config.py @@ -598,7 +598,7 @@ def main(): conn.validate(target) if source: if not module.check_mode: - conn.copy(source, target) + conn.copy_config(source, target) result["changed"] = True elif delete: if not module.check_mode: From 7ebbe7c044bb03abc4b9ea003b1bebff61780147 Mon Sep 17 00:00:00 2001 From: rohitthakur2590 Date: Tue, 13 May 2025 10:41:16 +0530 Subject: [PATCH 2/3] fixes for commit in candidate datastore Signed-off-by: rohitthakur2590 --- plugins/module_utils/network/netconf/netconf.py | 9 --------- plugins/modules/netconf_config.py | 15 ++++++++++++++- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/plugins/module_utils/network/netconf/netconf.py b/plugins/module_utils/network/netconf/netconf.py index ac400d2d3..6e31b5e3e 100644 --- a/plugins/module_utils/network/netconf/netconf.py +++ b/plugins/module_utils/network/netconf/netconf.py @@ -132,12 +132,3 @@ def sanitize_xml(data): if key not in IGNORE_XML_ATTRIBUTE: attribute.pop(key) return to_text(tostring(tree), errors="surrogate_then_replace").strip() - -def copy_config(module, source, target): - conn = get_connection(module) - try: - response = conn.copy_config(source=source, target=target) - except ConnectionError as e: - module.fail_json(msg=to_text(e, errors="surrogate_then_replace").strip()) - return response - diff --git a/plugins/modules/netconf_config.py b/plugins/modules/netconf_config.py index 66d7baa83..1361e7a81 100644 --- a/plugins/modules/netconf_config.py +++ b/plugins/modules/netconf_config.py @@ -493,6 +493,7 @@ def main(): save = module.params["save"] filter = module.params["get_filter"] format = module.params["format"] + commit = module.params["commit"] try: filter_data, filter_type = validate_and_normalize_data(filter) @@ -598,7 +599,7 @@ def main(): conn.validate(target) if source: if not module.check_mode: - conn.copy_config(source, target) + conn.copy(source, target) result["changed"] = True elif delete: if not module.check_mode: @@ -689,6 +690,18 @@ def main(): "before": sanitized_before, "after": sanitized_after, } + elif not config and commit: + if not module.check_mode: + confirm_timeout = confirm if confirm > 0 else None + commit_rpc = f""" + + + {confirm_timeout} + + """ + response = conn.dispatch(commit_rpc.strip()) + else: + conn.discard_changes() except ConnectionError as e: module.fail_json(msg=to_text(e, errors="surrogate_then_replace").strip()) From 11904251b57fbfda15804c061c660e062a0e24d2 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 13 May 2025 05:11:51 +0000 Subject: [PATCH 3/3] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- plugins/modules/netconf_config.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/modules/netconf_config.py b/plugins/modules/netconf_config.py index 1361e7a81..48b14b8a8 100644 --- a/plugins/modules/netconf_config.py +++ b/plugins/modules/netconf_config.py @@ -691,7 +691,7 @@ def main(): "after": sanitized_after, } elif not config and commit: - if not module.check_mode: + if not module.check_mode: confirm_timeout = confirm if confirm > 0 else None commit_rpc = f""" @@ -700,8 +700,8 @@ def main(): """ response = conn.dispatch(commit_rpc.strip()) - else: - conn.discard_changes() + else: + conn.discard_changes() except ConnectionError as e: module.fail_json(msg=to_text(e, errors="surrogate_then_replace").strip())