1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

adds put_file and fetch_file implementations for cliconf plugin (#26728)

This commit is contained in:
Peter Sprygada 2017-07-12 23:51:02 -04:00 committed by Ganesh Nalawade
parent 0b784c65b1
commit 41c1457823

View file

@ -27,6 +27,13 @@ from functools import wraps
from ansible.errors import AnsibleError, AnsibleConnectionFailure
from ansible.module_utils.six import with_metaclass
try:
from scp import SCPClient
HAS_SCP = True
except ImportError:
HAS_SCP = False
try:
from __main__ import display
except ImportError:
@ -181,8 +188,16 @@ class CliconfBase(with_metaclass(ABCMeta, object)):
def put_file(self, source, destination):
"""Copies file over scp to remote device"""
pass
if not HAS_SCP:
self._connection.internal_error("Required library scp is not installed. Please install it using `pip install scp`")
ssh = self._connection._connect_uncached()
with SCPClient(ssh.get_transport()) as scp:
scp.put(source, destination)
def fetch_file(self, source, destination):
"""Fetch file over scp from remote device"""
pass
if not HAS_SCP:
self._connection.internal_error("Required library scp is not installed. Please install it using `pip install scp`")
ssh = self._connection._connect_uncached()
with SCPClient(ssh.get_transport()) as scp:
scp.get(source, destination)