Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
ansible
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
ansible
Commits
7fd40518
Commit
7fd40518
authored
Aug 18, 2012
by
Michael DeHaan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
make connection types pluggable
parent
9aa41f07
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
34 additions
and
17 deletions
+34
-17
lib/ansible/constants.py
+0
-1
lib/ansible/runner/connection.py
+14
-11
lib/ansible/runner/connections/local.py
+4
-2
lib/ansible/runner/connections/paramiko_ssh.py
+2
-1
lib/ansible/runner/connections/ssh.py
+1
-1
lib/ansible/utils.py
+13
-1
No files found.
lib/ansible/constants.py
View file @
7fd40518
...
...
@@ -78,7 +78,6 @@ DEFAULT_TRANSPORT = get_config(p, DEFAULTS, 'transport', 'ANSIBLE
# non-configurable things
DEFAULT_REMOTE_PASS
=
None
DEFAULT_TRANSPORT_OPTS
=
[
'local'
,
'paramiko'
,
'ssh'
]
DEFAULT_SUDO_PASS
=
None
DEFAULT_SUBSET
=
None
...
...
lib/ansible/runner/connection
/__init__
.py
→
lib/ansible/runner/connection.py
View file @
7fd40518
...
...
@@ -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
()
lib/ansible/runner/connection/local.py
→
lib/ansible/runner/connection
s
/local.py
View file @
7fd40518
...
...
@@ -22,12 +22,14 @@ import subprocess
from
ansible
import
errors
from
ansible.callbacks
import
vvv
class
Local
Connection
(
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 '''
...
...
lib/ansible/runner/connection/paramiko_ssh.py
→
lib/ansible/runner/connection
s
/paramiko_ssh.py
View file @
7fd40518
...
...
@@ -33,10 +33,11 @@ with warnings.catch_warnings():
except
ImportError
:
pass
class
Paramiko
Connection
(
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
...
...
lib/ansible/runner/connection/ssh.py
→
lib/ansible/runner/connection
s
/ssh.py
View file @
7fd40518
...
...
@@ -27,7 +27,7 @@ import ansible.constants as C
from
ansible.callbacks
import
vvv
from
ansible
import
errors
class
SSH
Connection
(
object
):
class
Connection
(
object
):
''' ssh based connections '''
def
__init__
(
self
,
runner
,
host
,
port
):
...
...
lib/ansible/utils.py
View file @
7fd40518
...
...
@@ -29,6 +29,8 @@ from ansible import __version__
import
ansible.constants
as
C
import
time
import
StringIO
import
imp
import
glob
VERBOSITY
=
0
...
...
@@ -393,7 +395,6 @@ def base_parser(constants=C, usage="", output_opts=False, runas_opts=False,
if
connect_opts
:
parser
.
add_option
(
'-c'
,
'--connection'
,
dest
=
'connection'
,
choices
=
C
.
DEFAULT_TRANSPORT_OPTS
,
default
=
C
.
DEFAULT_TRANSPORT
,
help
=
"connection type to use (default=
%
s)"
%
C
.
DEFAULT_TRANSPORT
)
...
...
@@ -451,3 +452,14 @@ def filter_leading_non_json_lines(buf):
filtered_lines
.
write
(
line
+
'
\n
'
)
return
filtered_lines
.
getvalue
()
import
glob
,
imp
from
os.path
import
join
,
basename
,
splitext
def
import_plugins
(
directory
):
modules
=
{}
for
path
in
glob
.
glob
(
os
.
path
.
join
(
directory
,
'*.py'
)):
name
,
ext
=
os
.
path
.
splitext
(
os
.
path
.
basename
(
path
))
modules
[
name
]
=
imp
.
load_source
(
name
,
path
)
return
modules
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment