Commit 8574d40b by James Cammarata

Initial work to make paramiko connections work under v2

parent 8c08f1b3
......@@ -44,12 +44,13 @@ class ConnectionInformation:
passwords = {}
# connection
self.connection = None
self.remote_addr = None
self.remote_user = None
self.password = passwords.get('conn_pass','')
self.port = None
self.private_key_file = None
self.connection = None
self.remote_addr = None
self.remote_user = None
self.password = passwords.get('conn_pass','')
self.port = 22
self.private_key_file = C.DEFAULT_PRIVATE_KEY_FILE
self.timeout = C.DEFAULT_TIMEOUT
# privilege escalation
self.become = None
......@@ -119,9 +120,7 @@ class ConnectionInformation:
self.connection = options.connection
self.remote_user = options.remote_user
#if 'port' in options and options.port is not None:
# self.port = options.port
self.private_key_file = None
self.private_key_file = options.private_key_file
# privilege escalation
self.become = options.become
......
......@@ -51,7 +51,7 @@ class WorkerProcess(multiprocessing.Process):
for reading later.
'''
def __init__(self, tqm, main_q, rslt_q, loader, new_stdin):
def __init__(self, tqm, main_q, rslt_q, loader):
# takes a task queue manager as the sole param:
self._main_q = main_q
......@@ -59,23 +59,20 @@ class WorkerProcess(multiprocessing.Process):
self._loader = loader
# dupe stdin, if we have one
self._new_stdin = sys.stdin
try:
fileno = sys.stdin.fileno()
if fileno is not None:
try:
self._new_stdin = os.fdopen(os.dup(fileno))
except OSError, e:
# couldn't dupe stdin, most likely because it's
# not a valid file descriptor, so we just rely on
# using the one that was passed in
pass
except ValueError:
fileno = None
self._new_stdin = new_stdin
if not new_stdin and fileno is not None:
try:
self._new_stdin = os.fdopen(os.dup(fileno))
except OSError, e:
# couldn't dupe stdin, most likely because it's
# not a valid file descriptor, so we just rely on
# using the one that was passed in
pass
if self._new_stdin:
sys.stdin = self._new_stdin
# couldn't get stdin's fileno, so we just carry on
pass
super(WorkerProcess, self).__init__()
......@@ -118,7 +115,7 @@ class WorkerProcess(multiprocessing.Process):
# execute the task and build a TaskResult from the result
debug("running TaskExecutor() for %s/%s" % (host, task))
executor_result = TaskExecutor(host, task, job_vars, new_connection_info, self._loader, module_loader).run()
executor_result = TaskExecutor(host, task, job_vars, new_connection_info, self._new_stdin, self._loader, module_loader).run()
debug("done running TaskExecutor() for %s/%s" % (host, task))
task_result = TaskResult(host, task, executor_result)
......
......@@ -45,11 +45,12 @@ class TaskExecutor:
class.
'''
def __init__(self, host, task, job_vars, connection_info, loader, module_loader):
def __init__(self, host, task, job_vars, connection_info, new_stdin, loader, module_loader):
self._host = host
self._task = task
self._job_vars = job_vars
self._connection_info = connection_info
self._new_stdin = new_stdin
self._loader = loader
self._module_loader = module_loader
......@@ -370,7 +371,7 @@ class TaskExecutor:
if conn_type == 'smart':
conn_type = 'ssh'
connection = connection_loader.get(conn_type, self._connection_info)
connection = connection_loader.get(conn_type, self._connection_info, self._new_stdin)
if not connection:
raise AnsibleError("the connection plugin '%s' was not found" % conn_type)
......
......@@ -87,21 +87,10 @@ class TaskQueueManager:
self._workers = []
for i in range(self._options.forks):
# duplicate stdin, if possible
new_stdin = None
if fileno is not None:
try:
new_stdin = os.fdopen(os.dup(fileno))
except OSError:
# couldn't dupe stdin, most likely because it's
# not a valid file descriptor, so we just rely on
# using the one that was passed in
pass
main_q = multiprocessing.Queue()
rslt_q = multiprocessing.Queue()
prc = WorkerProcess(self, main_q, rslt_q, loader, new_stdin)
prc = WorkerProcess(self, main_q, rslt_q, loader)
prc.start()
self._workers.append((prc, main_q, rslt_q))
......
......@@ -43,10 +43,12 @@ class ConnectionBase:
has_pipelining = False
become_methods = C.BECOME_METHODS
def __init__(self, connection_info, *args, **kwargs):
def __init__(self, connection_info, new_stdin, *args, **kwargs):
# All these hasattrs allow subclasses to override these parameters
if not hasattr(self, '_connection_info'):
self._connection_info = connection_info
if not hasattr(self, '_new_stdin'):
self._new_stdin = new_stdin
if not hasattr(self, '_display'):
self._display = Display(verbosity=connection_info.verbosity)
if not hasattr(self, '_connected'):
......
......@@ -50,7 +50,7 @@ class Connection(ConnectionBase):
self._cp_dir = '/tmp'
#fcntl.lockf(self.runner.process_lockfile, fcntl.LOCK_UN)
super(Connection, self).__init__(connection_info)
super(Connection, self).__init__(connection_info, *args, **kwargs)
@property
def transport(self):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment