make connection types pluggable

This commit is contained in:
Michael DeHaan 2012-08-18 10:52:24 -04:00
parent 9aa41f075d
commit 7fd4051857
6 changed files with 34 additions and 17 deletions

View file

@ -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