2012-05-31 00:16:31 +00:00
|
|
|
# (c) 2012, Michael DeHaan <michael.dehaan@gmail.com>
|
|
|
|
#
|
|
|
|
# This file is part of Ansible
|
|
|
|
#
|
|
|
|
# Ansible is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# Ansible is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
#
|
|
|
|
|
|
|
|
################################################
|
|
|
|
|
2012-08-18 14:52:24 +00:00
|
|
|
from ansible import utils
|
|
|
|
from ansible.errors import AnsibleError
|
|
|
|
|
|
|
|
import os.path
|
|
|
|
dirname = os.path.dirname(__file__)
|
2012-08-22 00:32:21 +00:00
|
|
|
modules = utils.import_plugins(os.path.join(dirname, 'connection_plugins'))
|
2012-08-18 14:52:24 +00:00
|
|
|
|
|
|
|
# rename this module
|
|
|
|
modules['paramiko'] = modules['paramiko_ssh']
|
|
|
|
del modules['paramiko_ssh']
|
2012-05-31 00:16:31 +00:00
|
|
|
|
|
|
|
class Connection(object):
|
|
|
|
''' Handles abstract connections to remote hosts '''
|
|
|
|
|
2012-07-15 15:54:39 +00:00
|
|
|
def __init__(self, runner):
|
2012-05-31 00:16:31 +00:00
|
|
|
self.runner = runner
|
2012-07-15 13:33:48 +00:00
|
|
|
|
2012-05-31 00:16:31 +00:00
|
|
|
def connect(self, host, port=None):
|
|
|
|
conn = None
|
2012-07-15 15:54:39 +00:00
|
|
|
transport = self.runner.transport
|
2012-08-18 14:52:24 +00:00
|
|
|
module = modules.get(transport, None)
|
|
|
|
if module is None:
|
|
|
|
raise AnsibleError("unsupported connection type: %s" % transport)
|
|
|
|
conn = module.Connection(self.runner, host, port)
|
2012-05-31 00:16:31 +00:00
|
|
|
return conn.connect()
|
|
|
|
|