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 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.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('__.+__')
class ActionModule(ActionBase):
TRANSFERS_FILES = False
class ActionModule(_ActionModule):
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'):
try:
@ -46,10 +42,7 @@ class ActionModule(ActionBase):
except ValueError as exc:
return dict(failed=True, msg=exc.message)
action = self._task.action
result.update(self._execute_module(module_name=action,
module_args=self._task.args, task_vars=task_vars))
result = super(ActionModule, self).run(tmp, task_vars)
if self._task.args.get('backup') and result.get('__backup__'):
# 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
#
@ -25,32 +25,27 @@ import glob
import urlparse
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):
TRANSFERS_FILES = False
class ActionModule(_ActionModule):
def run(self, tmp=None, task_vars=None):
result = super(ActionModule, self).run(tmp, task_vars)
result['changed'] = False
try:
self._handle_template()
except (ValueError, AttributeError) as exc:
return dict(failed=True, msg=exc.message)
result.update(self._execute_module(module_name=self._task.action,
module_args=self._task.args, task_vars=task_vars))
result = super(ActionModule, self).run(tmp, 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.
# NOTE: If there is a parameter error, _backup key may not be in results.
self._write_backup(task_vars['inventory_hostname'], result['_backup'])
# NOTE: If there is a parameter error, __backup__ key may not be in results.
self._write_backup(task_vars['inventory_hostname'], result['__backup__'])
if '_backup' in result:
del result['_backup']
if '__backup__' in result:
del result['__backup__']
return result