ansible: restructure to avoid intermediate imports

pull/79/head
David Wilson 7 years ago
parent 1a119cb08b
commit 8598ff07b3

@ -31,7 +31,7 @@ import os
import ansible import ansible
import ansible.plugins import ansible.plugins
import ansible.plugins.action.normal import ansible.plugins.action.normal
import mitogen.ansible.helpers import ansible_mitogen.helpers
ANSIBLE_BASEDIR = os.path.dirname(ansible.__file__) ANSIBLE_BASEDIR = os.path.dirname(ansible.__file__)
@ -57,7 +57,7 @@ class ActionModule(ansible.plugins.action.normal.ActionModule):
##################################################################### #####################################################################
py_module_name = self.get_py_module_name(module_name) py_module_name = self.get_py_module_name(module_name)
js = self._connection.py_call(mitogen.ansible.helpers.run_module, py_module_name, js = self._connection.py_call(ansible_mitogen.helpers.run_module, py_module_name,
args=json.loads(json.dumps(module_args))) args=json.loads(json.dumps(module_args)))
##################################################################### #####################################################################

@ -42,12 +42,12 @@ Enable it by:
EOF EOF
""" """
import mitogen.master from __future__ import absolute_import
import mitogen.unix
from mitogen.ansible import helpers
import ansible.errors import ansible.errors
import ansible.plugins.connection import ansible.plugins.connection
import ansible_mitogen.helpers
import mitogen.unix
class Connection(ansible.plugins.connection.ConnectionBase): class Connection(ansible.plugins.connection.ConnectionBase):
@ -78,15 +78,15 @@ class Connection(ansible.plugins.connection.ConnectionBase):
super(Connection, self).exec_command(cmd, in_data=in_data, sudoable=sudoable) super(Connection, self).exec_command(cmd, in_data=in_data, sudoable=sudoable)
if in_data: if in_data:
raise ansible.errors.AnsibleError("does not support module pipelining") raise ansible.errors.AnsibleError("does not support module pipelining")
return self.py_call(helpers.exec_command, cmd, in_data) return self.py_call(ansible_mitogen.helpers.exec_command, cmd, in_data)
def fetch_file(self, in_path, out_path): def fetch_file(self, in_path, out_path):
output = self.py_call(helpers.read_path, in_path) output = self.py_call(ansible_mitogen.helpers.read_path, in_path)
helpers.write_path(out_path, output) ansible_mitogen.helpers.write_path(out_path, output)
def put_file(self, in_path, out_path): def put_file(self, in_path, out_path):
self.py_call(helpers.write_path, out_path, self.py_call(ansible_mitogen.helpers.write_path, out_path,
helpers.read_path(in_path)) ansible_mitogen.helpers.read_path(in_path))
def close(self): def close(self):
self.router.broker.shutdown() self.router.broker.shutdown()

@ -38,8 +38,6 @@ import json
import subprocess import subprocess
import time import time
import mitogen
# Prevent accidental import of an Ansible module from hanging on stdin read. # Prevent accidental import of an Ansible module from hanging on stdin read.
import ansible.module_utils.basic import ansible.module_utils.basic
ansible.module_utils.basic._ANSIBLE_ARGS = '{}' ansible.module_utils.basic._ANSIBLE_ARGS = '{}'

@ -25,12 +25,14 @@
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
from __future__ import absolute_import
import mitogen import mitogen
import mitogen.master import mitogen.master
import mitogen.service import mitogen.service
import mitogen.unix import mitogen.unix
import mitogen.utils import mitogen.utils
import mitogen.ansible.action import ansible_mitogen.action.mitogen
import ansible.errors import ansible.errors
import ansible.plugins.strategy.linear import ansible.plugins.strategy.linear
@ -71,7 +73,7 @@ class StrategyModule(ansible.plugins.strategy.linear.StrategyModule):
real_get = action_loader.get real_get = action_loader.get
def get(name, *args, **kwargs): def get(name, *args, **kwargs):
if name == 'normal': if name == 'normal':
return mitogen.ansible.action.ActionModule(*args, **kwargs) return ansible_mitogen.action.mitogen.ActionModule(*args, **kwargs)
return real_get(name, *args, **kwargs) return real_get(name, *args, **kwargs)
action_loader.get = get action_loader.get = get

@ -407,7 +407,6 @@ class Importer(object):
def __init__(self, router, context, core_src): def __init__(self, router, context, core_src):
self._context = context self._context = context
self._present = {'mitogen': [ self._present = {'mitogen': [
'mitogen.ansible',
'mitogen.compat', 'mitogen.compat',
'mitogen.compat.pkgutil', 'mitogen.compat.pkgutil',
'mitogen.fakessh', 'mitogen.fakessh',

@ -35,7 +35,7 @@ setup(
author = 'David Wilson', author = 'David Wilson',
license = 'New BSD', license = 'New BSD',
url = 'https://github.com/dw/mitogen/', url = 'https://github.com/dw/mitogen/',
packages = ['mitogen'], packages = ['mitogen', 'ansible_mitogen'],
zip_safe = False, zip_safe = False,
classifiers = [ classifiers = [
'Development Status :: 3 - Alpha', 'Development Status :: 3 - Alpha',

Loading…
Cancel
Save