mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-22 21:00:22 -07:00
make connection types pluggable
This commit is contained in:
parent
9aa41f075d
commit
7fd4051857
6 changed files with 34 additions and 17 deletions
|
@ -18,9 +18,16 @@
|
|||
|
||||
################################################
|
||||
|
||||
import local
|
||||
import paramiko_ssh
|
||||
import ssh
|
||||
from ansible import utils
|
||||
from ansible.errors import AnsibleError
|
||||
|
||||
import os.path
|
||||
dirname = os.path.dirname(__file__)
|
||||
modules = utils.import_plugins(os.path.join(dirname, 'connections'))
|
||||
|
||||
# rename this module
|
||||
modules['paramiko'] = modules['paramiko_ssh']
|
||||
del modules['paramiko_ssh']
|
||||
|
||||
class Connection(object):
|
||||
''' Handles abstract connections to remote hosts '''
|
||||
|
@ -31,13 +38,9 @@ class Connection(object):
|
|||
def connect(self, host, port=None):
|
||||
conn = None
|
||||
transport = self.runner.transport
|
||||
if transport == 'local':
|
||||
conn = local.LocalConnection(self.runner, host)
|
||||
elif transport == 'paramiko':
|
||||
conn = paramiko_ssh.ParamikoConnection(self.runner, host, port)
|
||||
elif transport == 'ssh':
|
||||
conn = ssh.SSHConnection(self.runner, host, port)
|
||||
if conn is None:
|
||||
raise Exception("unsupported connection type")
|
||||
module = modules.get(transport, None)
|
||||
if module is None:
|
||||
raise AnsibleError("unsupported connection type: %s" % transport)
|
||||
conn = module.Connection(self.runner, host, port)
|
||||
return conn.connect()
|
||||
|
|
@ -22,12 +22,14 @@ import subprocess
|
|||
from ansible import errors
|
||||
from ansible.callbacks import vvv
|
||||
|
||||
class LocalConnection(object):
|
||||
class Connection(object):
|
||||
''' Local based connections '''
|
||||
|
||||
def __init__(self, runner, host):
|
||||
def __init__(self, runner, host, port):
|
||||
self.runner = runner
|
||||
self.host = host
|
||||
# port is unused, since this is local
|
||||
self.port = port
|
||||
|
||||
def connect(self, port=None):
|
||||
''' connect to the local host; nothing to do here '''
|
|
@ -33,10 +33,11 @@ with warnings.catch_warnings():
|
|||
except ImportError:
|
||||
pass
|
||||
|
||||
class ParamikoConnection(object):
|
||||
class Connection(object):
|
||||
''' SSH based connections with Paramiko '''
|
||||
|
||||
def __init__(self, runner, host, port=None):
|
||||
|
||||
self.ssh = None
|
||||
self.runner = runner
|
||||
self.host = host
|
|
@ -27,7 +27,7 @@ import ansible.constants as C
|
|||
from ansible.callbacks import vvv
|
||||
from ansible import errors
|
||||
|
||||
class SSHConnection(object):
|
||||
class Connection(object):
|
||||
''' ssh based connections '''
|
||||
|
||||
def __init__(self, runner, host, port):
|
Loading…
Add table
Add a link
Reference in a new issue