Cleanup connections plugins (#2520)

* minor refactors

* minor refactors in plugins/connection/saltstack.py

* minor refactors in plugins/connection/qubes.py

* minor refactor in plugins/connection/lxc.py

* minor refactors in plugins/connection/chroot.py

* minor refactors in plugins/connection/funcd.py

* minor refactors in plugins/connection/iocage.py

* minor refactors in plugins/connection/jail.py

* added changelog fragment
This commit is contained in:
Alexei Znamensky 2021-05-16 23:24:37 +12:00 committed by GitHub
parent a385cbb11d
commit c8f402806f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 79 additions and 80 deletions

View file

@ -44,7 +44,7 @@ display = Display()
class Connection(ConnectionBase):
''' Func-based connections '''
""" Func-based connections """
has_pipelining = False
@ -53,6 +53,7 @@ class Connection(ConnectionBase):
self.host = host
# port is unused, this go on func
self.port = port
self.client = None
def connect(self, port=None):
if not HAVE_FUNC:
@ -62,31 +63,32 @@ class Connection(ConnectionBase):
return self
def exec_command(self, cmd, become_user=None, sudoable=False, executable='/bin/sh', in_data=None):
''' run a command on the remote minion '''
""" run a command on the remote minion """
if in_data:
raise AnsibleError("Internal Error: this module does not support optimized module pipelining")
# totally ignores privlege escalation
display.vvv("EXEC %s" % (cmd), host=self.host)
display.vvv("EXEC %s" % cmd, host=self.host)
p = self.client.command.run(cmd)[self.host]
return (p[0], p[1], p[2])
return p[0], p[1], p[2]
def _normalize_path(self, path, prefix):
@staticmethod
def _normalize_path(path, prefix):
if not path.startswith(os.path.sep):
path = os.path.join(os.path.sep, path)
normpath = os.path.normpath(path)
return os.path.join(prefix, normpath[1:])
def put_file(self, in_path, out_path):
''' transfer a file from local to remote '''
""" transfer a file from local to remote """
out_path = self._normalize_path(out_path, '/')
display.vvv("PUT %s TO %s" % (in_path, out_path), host=self.host)
self.client.local.copyfile.send(in_path, out_path)
def fetch_file(self, in_path, out_path):
''' fetch a file from remote to local '''
""" fetch a file from remote to local """
in_path = self._normalize_path(in_path, '/')
display.vvv("FETCH %s TO %s" % (in_path, out_path), host=self.host)
@ -99,5 +101,5 @@ class Connection(ConnectionBase):
shutil.rmtree(tmpdir)
def close(self):
''' terminate the connection; nothing to do here '''
""" terminate the connection; nothing to do here """
pass