summaryrefslogtreecommitdiff
path: root/plugins/module_utils
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/module_utils')
-rw-r--r--plugins/module_utils/network/vyos/vyos.py31
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"))