ansible: rename helpers.py to target.py, to reflect its purpose

pull/193/head
David Wilson 7 years ago
parent a643f13ebe
commit 71057c78f9

@ -39,7 +39,7 @@ import ansible.plugins.connection
import mitogen.unix
import mitogen.utils
import ansible_mitogen.helpers
import ansible_mitogen.target
import ansible_mitogen.process
from ansible_mitogen.services import ContextService
@ -306,7 +306,7 @@ class Connection(ansible.plugins.connection.ConnectionBase):
def exec_command(self, cmd, in_data='', sudoable=True, mitogen_chdir=None):
"""
Implement exec_command() by calling the corresponding
ansible_mitogen.helpers function in the target.
ansible_mitogen.target function in the target.
:param str cmd:
Shell command to execute.
@ -317,7 +317,7 @@ class Connection(ansible.plugins.connection.ConnectionBase):
"""
emulate_tty = (not in_data and sudoable)
rc, stdout, stderr = self.call(
ansible_mitogen.helpers.exec_command,
ansible_mitogen.target.exec_command,
cmd=mitogen.utils.cast(cmd),
in_data=mitogen.utils.cast(in_data),
chdir=mitogen_chdir,
@ -333,39 +333,39 @@ class Connection(ansible.plugins.connection.ConnectionBase):
def fetch_file(self, in_path, out_path):
"""
Implement fetch_file() by calling the corresponding
ansible_mitogen.helpers function in the target.
ansible_mitogen.target function in the target.
:param str in_path:
Remote filesystem path to read.
:param str out_path:
Local filesystem path to write.
"""
output = self.call(ansible_mitogen.helpers.read_path,
output = self.call(ansible_mitogen.target.read_path,
mitogen.utils.cast(in_path))
ansible_mitogen.helpers.write_path(out_path, output)
ansible_mitogen.target.write_path(out_path, output)
def put_data(self, out_path, data):
"""
Implement put_file() by caling the corresponding
ansible_mitogen.helpers function in the target.
ansible_mitogen.target function in the target.
:param str in_path:
Local filesystem path to read.
:param str out_path:
Remote filesystem path to write.
"""
self.call(ansible_mitogen.helpers.write_path,
self.call(ansible_mitogen.target.write_path,
mitogen.utils.cast(out_path),
mitogen.utils.cast(data))
def put_file(self, in_path, out_path):
"""
Implement put_file() by caling the corresponding
ansible_mitogen.helpers function in the target.
ansible_mitogen.target function in the target.
:param str in_path:
Local filesystem path to read.
:param str out_path:
Remote filesystem path to write.
"""
self.put_data(out_path, ansible_mitogen.helpers.read_path(in_path))
self.put_data(out_path, ansible_mitogen.target.read_path(in_path))

@ -54,7 +54,7 @@ from mitogen.utils import cast
import ansible_mitogen.connection
import ansible_mitogen.planner
import ansible_mitogen.helpers
import ansible_mitogen.target
from ansible.module_utils._text import to_text
@ -117,7 +117,7 @@ class ActionModuleMixin(ansible.plugins.action.ActionBase):
"""
Arrange for a Python function to be called in the target context, which
should be some function from the standard library or
ansible_mitogen.helpers module. This junction point exists mainly as a
ansible_mitogen.target module. This junction point exists mainly as a
nice place to insert print statements during debugging.
"""
return self._connection.call(func, *args, **kwargs)
@ -200,7 +200,7 @@ class ActionModuleMixin(ansible.plugins.action.ActionBase):
# The copy action plugin violates layering and grabs this attribute
# directly.
self._connection._shell.tmpdir = self.call(
ansible_mitogen.helpers.make_temp_directory,
ansible_mitogen.target.make_temp_directory,
base_dir=self._get_remote_tmp(),
)
LOG.debug('Temporary directory: %r', self._connection._shell.tmpdir)
@ -255,7 +255,7 @@ class ActionModuleMixin(ansible.plugins.action.ActionBase):
paths, mode, sudoable)
return self.fake_shell(lambda: mitogen.master.Select.all(
self._connection.call_async(
ansible_mitogen.helpers.set_file_mode, path, mode
ansible_mitogen.target.set_file_mode, path, mode
)
for path in paths
))
@ -299,7 +299,7 @@ class ActionModuleMixin(ansible.plugins.action.ActionBase):
delete_remote_tmp=True, wrap_async=False):
"""
Collect up a module's execution environment then use it to invoke
helpers.run_module() or helpers.run_module_async() in the target
target.run_module() or helpers.run_module_async() in the target
context.
"""
if module_name is None:
@ -358,7 +358,7 @@ class ActionModuleMixin(ansible.plugins.action.ActionBase):
chdir=None):
"""
Override the base implementation by simply calling
helpers.exec_command() in the target context.
target.exec_command() in the target context.
"""
LOG.debug('_low_level_execute_command(%r, in_data=%r, exe=%r, dir=%r)',
cmd, type(in_data), executable, chdir)

@ -48,7 +48,7 @@ except ImportError: # Ansible <2.4
import mitogen
import mitogen.service
import ansible_mitogen.helpers
import ansible_mitogen.target
import ansible_mitogen.services
@ -89,7 +89,7 @@ def parse_script_interpreter(source):
class Invocation(object):
"""
Collect up a module's execution environment then use it to invoke
helpers.run_module() or helpers.run_module_async() in the target context.
target.run_module() or helpers.run_module_async() in the target context.
"""
def __init__(self, action, connection, module_name, module_args,
remote_tmp, task_vars, templar, env, wrap_async):
@ -335,9 +335,9 @@ def invoke(invocation):
kwargs = planner.plan(invocation)
if invocation.wrap_async:
helper = ansible_mitogen.helpers.run_module_async
helper = ansible_mitogen.target.run_module_async
else:
helper = ansible_mitogen.helpers.run_module
helper = ansible_mitogen.target.run_module
try:
js = invocation.connection.call(helper, kwargs)

@ -28,7 +28,7 @@
import ansible.plugins.action
import mitogen.core
import ansible_mitogen.helpers
import ansible_mitogen.target
from mitogen.utils import cast
@ -37,7 +37,7 @@ class ActionModule(ansible.plugins.action.ActionBase):
job_id = self._task.args['jid']
try:
result = self._connection.call(
ansible_mitogen.helpers.get_async_result,
ansible_mitogen.target.get_async_result,
cast(job_id),
)
except mitogen.core.CallError, e:

@ -29,7 +29,7 @@
"""
These classes implement execution for each style of Ansible module. They are
instantiated in the target context by way of helpers.py::run_module().
instantiated in the target context by way of target.py::run_module().
Each class in here has a corresponding Planner class in planners.py that knows
how to build arguments for it, preseed related data, etc.
@ -45,7 +45,7 @@ import sys
import tempfile
import types
import ansible_mitogen.helpers # TODO: circular import
import ansible_mitogen.target # TODO: circular import
try:
from shlex import quote as shlex_quote
@ -97,7 +97,7 @@ class Runner(object):
def get_temp_dir(self):
if not self._temp_dir:
self._temp_dir = ansible_mitogen.helpers.make_temp_directory(
self._temp_dir = ansible_mitogen.target.make_temp_directory(
self.remote_tmp,
)
return self._temp_dir
@ -220,7 +220,7 @@ class ProgramRunner(Runner):
"""
Fetch the module binary from the master if necessary.
"""
return ansible_mitogen.helpers.get_file(
return ansible_mitogen.target.get_file(
context=self.service_context,
path=self.path,
)
@ -241,7 +241,7 @@ class ProgramRunner(Runner):
def _run(self):
try:
rc, stdout, stderr = ansible_mitogen.helpers.exec_args(
rc, stdout, stderr = ansible_mitogen.target.exec_args(
args=self._get_program_args(),
emulate_tty=True,
)
@ -362,7 +362,7 @@ class NewStyleRunner(ScriptRunner):
return self._code_by_path[self.path]
except KeyError:
return self._code_by_path.setdefault(self.path, compile(
source=ansible_mitogen.helpers.get_file(
source=ansible_mitogen.target.get_file(
context=self.service_context,
path=self.path,
),

@ -131,12 +131,12 @@ class StrategyMixin(object):
For action plug-ins, the original class is looked up as usual, but a
new subclass is created dynamically in order to mix-in
ansible_mitogen.helpers.ActionModuleMixin, which overrides many of the
ansible_mitogen.target.ActionModuleMixin, which overrides many of the
methods usually inherited from ActionBase in order to replace them with
pure-Python equivalents that avoid the use of shell.
In particular, _execute_module() is overridden with an implementation
that uses ansible_mitogen.helpers.run_module() executed in the target
that uses ansible_mitogen.target.run_module() executed in the target
Context. run_module() implements module execution by importing the
module as if it were a normal Python module, and capturing its output
in the remote process. Since the Mitogen module loader is active in the

Loading…
Cancel
Save