updates action plugins for network_cli connection (#19849)

* net_config now subclasses action plugin network
* net_template now subclasses action plugin network

This will break existing modules until those modules have been refactored.
This commit is contained in:
Peter Sprygada 2017-01-04 21:52:46 -05:00 committed by GitHub
parent fdb24bb5d7
commit 630d10a27a
2 changed files with 12 additions and 24 deletions

View file

@ -24,7 +24,7 @@ import re
import time import time
import glob import glob
from ansible.plugins.action import ActionBase from ansible.plugins.action.network import ActionModule as _ActionModule
from ansible.module_utils._text import to_text from ansible.module_utils._text import to_text
from ansible.module_utils.six.moves.urllib.parse import urlsplit from ansible.module_utils.six.moves.urllib.parse import urlsplit
@ -32,13 +32,9 @@ from ansible.module_utils.six.moves.urllib.parse import urlsplit
PRIVATE_KEYS_RE = re.compile('__.+__') PRIVATE_KEYS_RE = re.compile('__.+__')
class ActionModule(ActionBase): class ActionModule(_ActionModule):
TRANSFERS_FILES = False
def run(self, tmp=None, task_vars=None): def run(self, tmp=None, task_vars=None):
result = super(ActionModule, self).run(tmp, task_vars)
result['changed'] = False
if self._task.args.get('src'): if self._task.args.get('src'):
try: try:
@ -46,10 +42,7 @@ class ActionModule(ActionBase):
except ValueError as exc: except ValueError as exc:
return dict(failed=True, msg=exc.message) return dict(failed=True, msg=exc.message)
action = self._task.action result = super(ActionModule, self).run(tmp, task_vars)
result.update(self._execute_module(module_name=action,
module_args=self._task.args, task_vars=task_vars))
if self._task.args.get('backup') and result.get('__backup__'): if self._task.args.get('backup') and result.get('__backup__'):
# User requested backup and no error occurred in module. # User requested backup and no error occurred in module.

View file

@ -1,5 +1,5 @@
# #
# Copyright 2015 Peter Sprygada <psprygada@ansible.com> # (c) 2016 Red Hat Inc.
# #
# This file is part of Ansible # This file is part of Ansible
# #
@ -25,32 +25,27 @@ import glob
import urlparse import urlparse
from ansible.module_utils._text import to_text from ansible.module_utils._text import to_text
from ansible.plugins.action import ActionBase from ansible.plugins.network import ActionModule as _ActionModule
class ActionModule(ActionBase): class ActionModule(_ActionModule):
TRANSFERS_FILES = False
def run(self, tmp=None, task_vars=None): def run(self, tmp=None, task_vars=None):
result = super(ActionModule, self).run(tmp, task_vars)
result['changed'] = False
try: try:
self._handle_template() self._handle_template()
except (ValueError, AttributeError) as exc: except (ValueError, AttributeError) as exc:
return dict(failed=True, msg=exc.message) return dict(failed=True, msg=exc.message)
result.update(self._execute_module(module_name=self._task.action, result = super(ActionModule, self).run(tmp, task_vars)
module_args=self._task.args, task_vars=task_vars))
if self._task.args.get('backup') and result.get('_backup'): if self._task.args.get('backup') and result.get('__backup__'):
# User requested backup and no error occurred in module. # User requested backup and no error occurred in module.
# NOTE: If there is a parameter error, _backup key may not be in results. # NOTE: If there is a parameter error, __backup__ key may not be in results.
self._write_backup(task_vars['inventory_hostname'], result['_backup']) self._write_backup(task_vars['inventory_hostname'], result['__backup__'])
if '_backup' in result: if '__backup__' in result:
del result['_backup'] del result['__backup__']
return result return result