mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-24 11:21:25 -07:00
Decorate the ConnectionBase methods, switch to calling super from individual connection classes
This commit is contained in:
parent
9754c67138
commit
bce281014c
5 changed files with 32 additions and 12 deletions
|
@ -42,7 +42,7 @@ except ImportError:
|
|||
|
||||
from ansible import constants as C
|
||||
from ansible.errors import AnsibleError, AnsibleConnectionFailure, AnsibleFileNotFound
|
||||
from ansible.plugins.connections import ConnectionBase, ensure_connect
|
||||
from ansible.plugins.connections import ConnectionBase
|
||||
from ansible.plugins import shell_loader
|
||||
from ansible.utils.path import makedirs_safe
|
||||
|
||||
|
@ -152,8 +152,8 @@ class Connection(ConnectionBase):
|
|||
self.protocol = self._winrm_connect()
|
||||
return self
|
||||
|
||||
@ensure_connect
|
||||
def exec_command(self, cmd, tmp_path, executable='/bin/sh', in_data=None):
|
||||
super(Connection, self).exec_command(cmd, tmp_path, executable=executable, in_data,in_data)
|
||||
|
||||
cmd = cmd.encode('utf-8')
|
||||
cmd_parts = shlex.split(cmd, posix=False)
|
||||
|
@ -174,8 +174,9 @@ class Connection(ConnectionBase):
|
|||
raise AnsibleError("failed to exec cmd %s" % cmd)
|
||||
return (result.status_code, '', result.std_out.encode('utf-8'), result.std_err.encode('utf-8'))
|
||||
|
||||
@ensure_connect
|
||||
def put_file(self, in_path, out_path):
|
||||
super(Connection, self).put_file(in_path, out_path)
|
||||
|
||||
self._display.vvv("PUT %s TO %s" % (in_path, out_path), host=self._connection_info.remote_addr)
|
||||
if not os.path.exists(in_path):
|
||||
raise AnsibleFileNotFound("file or module does not exist: %s" % in_path)
|
||||
|
@ -213,8 +214,9 @@ class Connection(ConnectionBase):
|
|||
traceback.print_exc()
|
||||
raise AnsibleError("failed to transfer file to %s" % out_path)
|
||||
|
||||
@ensure_connect
|
||||
def fetch_file(self, in_path, out_path):
|
||||
super(Connection, self).fetch_file(in_path, out_path)
|
||||
|
||||
out_path = out_path.replace('\\', '/')
|
||||
self._display.vvv("FETCH %s TO %s" % (in_path, out_path), host=self._connection_info.remote_addr)
|
||||
buffer_size = 2**19 # 0.5MB chunks
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue