diff options
| author | omnom62 <75066712+omnom62@users.noreply.github.com> | 2026-09-16 22:32:53 +1000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-09-16 15:32:53 +0300 |
| commit | 762c276f61dd8fb599d9600df93c1a2992a8cf2e (patch) | |
| tree | 1e0d1c381f4dd2ac722661b150d11c0c44221d81 /plugins/module_utils | |
| parent | 25635b0560863eb4a5b34434bb34dfd7c43d77f9 (diff) | |
| download | vyos.vyos-762c276f61dd8fb599d9600df93c1a2992a8cf2e.tar.gz vyos.vyos-762c276f61dd8fb599d9600df93c1a2992a8cf2e.zip | |
T6837: vyos_config replace (#493)
* T6837: vyos_config replace core
Diffstat (limited to 'plugins/module_utils')
| -rw-r--r-- | plugins/module_utils/network/vyos/vyos.py | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/plugins/module_utils/network/vyos/vyos.py b/plugins/module_utils/network/vyos/vyos.py index 92c0f1b8..4983221e 100644 --- a/plugins/module_utils/network/vyos/vyos.py +++ b/plugins/module_utils/network/vyos/vyos.py @@ -27,12 +27,14 @@ # from __future__ import absolute_import, division, print_function + __metaclass__ = type import json from ansible.module_utils._text import to_text from ansible.module_utils.connection import Connection, ConnectionError + _DEVICE_CONFIGS = {} @@ -85,6 +87,30 @@ def get_config(module, flags=None, format=None): return cfg +def copy_file(module, source, destination, proto="scp"): + """Copy a local file to the remote device over the existing network_cli + SSH session, using netcommon's generic connection-level file transfer + RPC (the same mechanism ansible.netcommon.net_put uses). + + Requires the device to have SCP/SFTP reachable over the same SSH + session used for network_cli. Mirrors the calling convention of + cisco.iosxr's module_utils copy_file(module, source, destination, proto), + confirmed against cisco.iosxr's iosxr_config.py call site: + copy_file(module, src, dst, "sftp"). + """ + connection = get_connection(module) + try: + timeout = connection.get_option("persistent_command_timeout") + connection.copy_file( + source=source, + destination=destination, + proto=proto, + timeout=timeout, + ) + except ConnectionError as exc: + module.fail_json(msg=to_text(exc, errors="surrogate_then_replace")) + + def run_commands(module, commands, check_rc=True): connection = get_connection(module) try: @@ -99,7 +125,10 @@ def load_config(module, commands, commit=False, comment=None, confirm=None): try: response = connection.edit_config( - candidate=commands, commit=commit, comment=comment, confirm=confirm + candidate=commands, + commit=commit, + comment=comment, + confirm=confirm, ) except ConnectionError as exc: module.fail_json(msg=to_text(exc, errors="surrogate_then_replace")) |
