Skip to content

Commit

Permalink
fix review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ganeshrn committed Jun 21, 2021
1 parent 4010e99 commit 0f07bc7
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
29 changes: 22 additions & 7 deletions plugins/action/network_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,23 +81,36 @@ def run(self, task_vars=None):

run_mode = self._get_run_mode()

result = {}
if run_mode == RunMode.RM_LIST:
return self._list_resource_modules()
result = self._list_resource_modules()
elif run_mode in [RunMode.RM_GET, RunMode.RM_CONFIG]:
return self._run_resource_module()
result = self._run_resource_module()

result.update(
{
"ansible_network_os": self._task_vars.get(
"ansible_network_os"
),
"ansible_connection": self._task_vars.get(
"ansible_connection"
),
}
)
return result

def _run_resource_module(self):
new_task = self._task.copy()

module = self._get_resource_module()
if not module:
self._module = self._get_resource_module()
if not self._module:
msg = "Could not find resource module '%s' for os name '%s'" % (
self._name,
self._os_name,
)
raise AnsibleActionFail(msg)

new_task.action = module
new_task.action = self._module

action = self._shared_loader_obj.action_loader.get(
self._rm_play_context.network_os,
Expand All @@ -108,12 +121,14 @@ def _run_resource_module(self):
templar=self._templar,
shared_loader_obj=self._shared_loader_obj,
)
display.vvvv("Running resource module %s" % module)
display.vvvv("Running resource module %s" % self._module)
for option in ["os_name", "name"]:
if option in new_task.args:
new_task.args.pop(option)

return action.run(task_vars=self._task_vars)
result = action.run(task_vars=self._task_vars)
result.update({"resource_module_name": self._module})
return result

def _get_resource_module(self):
if "." in self._name:
Expand Down
10 changes: 5 additions & 5 deletions plugins/modules/network_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

DOCUMENTATION = """
module: network_resource
author:
author:
- Ganesh B. Nalawade (@ganeshrn)
short_description: Manage resource modules
description:
Expand All @@ -23,10 +23,10 @@
type: str
description:
- The name of the os to manage the resource modules.
- The name should be fully qualified collection name format,
- The name should be fully qualified collection name format,
that is I(<namespace>.<collection-name>.<plugin-name>).
- If value of this option is not set the os value will be
read from I(ansible_network_os) variable.
read from I(ansible_network_os) variable.
- If value of both I(os_name) and I(ansible_network_os)
is not set it will result in error.
name:
Expand All @@ -36,7 +36,7 @@
- The resource module should be supported for given I(os_name),
if not supported it will result in error.
config:
description:
description:
- The resource module configuration. For details on the type and
structure of this option refer the individual resource module
platform documentation.
Expand Down Expand Up @@ -66,7 +66,7 @@
ansible.netcommon.network_resource:
register: result
- name: fetch acl config for
- name: fetch acl config for
ansible.netcommon.network_resource:
os_name: cisco.ios.ios
name: acls
Expand Down

0 comments on commit 0f07bc7

Please sign in to comment.