mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-07 13:52:54 +00:00
* adds commit replace with config file for iosxr (#35564)
* * adds commit replace with config file for iosxr * fixes dci failure in iosxr_logging * * review comment changes
This commit is contained in:
committed by
John R Barker
parent
2479b6d635
commit
684e953b50
@@ -34,7 +34,6 @@ try:
|
||||
except ImportError:
|
||||
HAS_SCP = False
|
||||
|
||||
|
||||
try:
|
||||
from __main__ import display
|
||||
except ImportError:
|
||||
@@ -135,7 +134,7 @@ class CliconfBase(with_metaclass(ABCMeta, object)):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def edit_config(self, commands):
|
||||
def edit_config(self, commands=None):
|
||||
"""Loads the specified commands into the remote device
|
||||
This method will load the commands into the remote device. This
|
||||
method will make sure the device is in the proper context before
|
||||
@@ -150,7 +149,7 @@ class CliconfBase(with_metaclass(ABCMeta, object)):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get(self, command, prompt=None, answer=None, sendonly=False):
|
||||
def get(self, command=None, prompt=None, answer=None, sendonly=False, newline=True):
|
||||
"""Execute specified command on remote device
|
||||
This method will retrieve the specified data and
|
||||
return it to the caller as a string.
|
||||
@@ -181,18 +180,26 @@ class CliconfBase(with_metaclass(ABCMeta, object)):
|
||||
"Discard changes in candidate datastore"
|
||||
return self._connection.method_not_found("discard_changes is not supported by network_os %s" % self._play_context.network_os)
|
||||
|
||||
def put_file(self, source, destination):
|
||||
"""Copies file over scp to remote device"""
|
||||
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 copy_file(self, source=None, destination=None, proto='scp'):
|
||||
"""Copies file over scp/sftp to remote device"""
|
||||
ssh = self._connection.paramiko_conn._connect_uncached()
|
||||
if proto == 'scp':
|
||||
if not HAS_SCP:
|
||||
self._connection.internal_error("Required library scp is not installed. Please install it using `pip install scp`")
|
||||
with SCPClient(ssh.get_transport()) as scp:
|
||||
scp.put(source, destination)
|
||||
elif proto == 'sftp':
|
||||
with ssh.open_sftp() as sftp:
|
||||
sftp.put(source, destination)
|
||||
|
||||
def fetch_file(self, source, destination):
|
||||
"""Fetch file over scp from remote device"""
|
||||
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)
|
||||
def get_file(self, source=None, destination=None, proto='scp'):
|
||||
"""Fetch file over scp/sftp from remote device"""
|
||||
ssh = self._connection.paramiko_conn._connect_uncached()
|
||||
if proto == 'scp':
|
||||
if not HAS_SCP:
|
||||
self._connection.internal_error("Required library scp is not installed. Please install it using `pip install scp`")
|
||||
with SCPClient(ssh.get_transport()) as scp:
|
||||
scp.get(source, destination)
|
||||
elif proto == 'sftp':
|
||||
with ssh.open_sftp() as sftp:
|
||||
sftp.get(source, destination)
|
||||
|
||||
@@ -67,12 +67,27 @@ class Cliconf(CliconfBase):
|
||||
|
||||
return self.send_command(cmd)
|
||||
|
||||
def edit_config(self, command):
|
||||
for cmd in chain(to_list(command)):
|
||||
self.send_command(cmd)
|
||||
def edit_config(self, commands=None):
|
||||
for cmd in chain(to_list(commands)):
|
||||
try:
|
||||
if isinstance(cmd, str):
|
||||
cmd = json.loads(cmd)
|
||||
command = cmd.get('command', None)
|
||||
prompt = cmd.get('prompt', None)
|
||||
answer = cmd.get('answer', None)
|
||||
sendonly = cmd.get('sendonly', False)
|
||||
newline = cmd.get('newline', True)
|
||||
except:
|
||||
command = cmd
|
||||
prompt = None
|
||||
answer = None
|
||||
sendonly = None
|
||||
newline = None
|
||||
|
||||
def get(self, command, prompt=None, answer=None, sendonly=False):
|
||||
return self.send_command(command, prompt=prompt, answer=answer, sendonly=sendonly)
|
||||
self.send_command(command=command, prompt=prompt, answer=answer, sendonly=sendonly, newline=newline)
|
||||
|
||||
def get(self, command=None, prompt=None, answer=None, sendonly=False, newline=True):
|
||||
return self.send_command(command=command, prompt=prompt, answer=answer, sendonly=sendonly, newline=newline)
|
||||
|
||||
def commit(self, comment=None):
|
||||
if comment:
|
||||
|
||||
@@ -283,10 +283,10 @@ class Connection(ConnectionBase):
|
||||
if self.connected:
|
||||
return
|
||||
|
||||
p = connection_loader.get('paramiko', self._play_context, '/dev/null')
|
||||
p.set_options(direct={'look_for_keys': not bool(self._play_context.password and not self._play_context.private_key_file)})
|
||||
p.force_persistence = self.force_persistence
|
||||
ssh = p._connect()
|
||||
self.paramiko_conn = connection_loader.get('paramiko', self._play_context, '/dev/null')
|
||||
self.paramiko_conn.set_options(direct={'look_for_keys': not bool(self._play_context.password and not self._play_context.private_key_file)})
|
||||
self.paramiko_conn.force_persistence = self.force_persistence
|
||||
ssh = self.paramiko_conn._connect()
|
||||
|
||||
display.vvvv('ssh connection done, setting terminal', host=self._play_context.remote_addr)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user