Decorate the ConnectionBase methods, switch to calling super from individual connection classes

This commit is contained in:
Matt Martz 2015-06-04 13:27:18 -05:00
parent 9754c67138
commit bce281014c
5 changed files with 32 additions and 12 deletions

View file

@ -34,7 +34,7 @@ from hashlib import sha1
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
class Connection(ConnectionBase):
@ -270,10 +270,11 @@ class Connection(ConnectionBase):
self._display.vvv("EXEC previous known host file not found for {0}".format(host))
return True
@ensure_connect
def exec_command(self, cmd, tmp_path, executable='/bin/sh', in_data=None):
''' run a command on the remote host '''
super(Connection, self).exec_command(cmd, tmp_path, executable=executable, in_data=in_data)
ssh_cmd = self._password_cmd()
ssh_cmd += ("ssh", "-C")
if not in_data:
@ -392,9 +393,11 @@ class Connection(ConnectionBase):
return (p.returncode, '', no_prompt_out + stdout, no_prompt_err + stderr)
@ensure_connect
def put_file(self, in_path, out_path):
''' transfer a file from local to remote '''
super(Connection, self).put_file(in_path, out_path)
self._display.vvv("PUT {0} TO {1}".format(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: {0}".format(in_path))
@ -428,9 +431,11 @@ class Connection(ConnectionBase):
if returncode != 0:
raise AnsibleError("failed to transfer file to {0}:\n{1}\n{2}".format(out_path, stdout, stderr))
@ensure_connect
def fetch_file(self, in_path, out_path):
''' fetch a file from remote to local '''
super(Connection, self).fetch_file(in_path, out_path)
self._display.vvv("FETCH {0} TO {1}".format(in_path, out_path), host=self._connection_info.remote_addr)
cmd = self._password_cmd()