mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-05-09 18:51:29 -07:00
Adding RPC attribute parameters to junos_rpc network module (#32649)
* Adding RPC attribute arguments to `junos_rpc` network module. * Specifying module argument version. * Fixing DOCUMENTATION block. * First attempt at new test fixture. * Updated RPC_CLI_MAP. * Use `result` instead of `reply`.
This commit is contained in:
parent
e24e771b88
commit
d9a52db17d
3 changed files with 30 additions and 1 deletions
|
@ -39,6 +39,11 @@ options:
|
||||||
accepts a set of key=value arguments.
|
accepts a set of key=value arguments.
|
||||||
required: false
|
required: false
|
||||||
default: null
|
default: null
|
||||||
|
attrs:
|
||||||
|
description:
|
||||||
|
- The C(attrs) arguments defines a list of attributes and their values
|
||||||
|
to set for the RPC call. This accepts a dictionary of key-values.
|
||||||
|
version_added: "2.5"
|
||||||
output:
|
output:
|
||||||
description:
|
description:
|
||||||
- The C(output) argument specifies the desired output of the
|
- The C(output) argument specifies the desired output of the
|
||||||
|
@ -66,6 +71,13 @@ EXAMPLES = """
|
||||||
- name: get system information
|
- name: get system information
|
||||||
junos_rpc:
|
junos_rpc:
|
||||||
rpc: get-system-information
|
rpc: get-system-information
|
||||||
|
|
||||||
|
- name: load configuration
|
||||||
|
junos_rpc:
|
||||||
|
rpc: load-configuration
|
||||||
|
attrs:
|
||||||
|
action: override
|
||||||
|
url: /tmp/config.conf
|
||||||
"""
|
"""
|
||||||
|
|
||||||
RETURN = """
|
RETURN = """
|
||||||
|
@ -101,6 +113,7 @@ def main():
|
||||||
argument_spec = dict(
|
argument_spec = dict(
|
||||||
rpc=dict(required=True),
|
rpc=dict(required=True),
|
||||||
args=dict(type='dict'),
|
args=dict(type='dict'),
|
||||||
|
attrs=dict(type='dict'),
|
||||||
output=dict(default='xml', choices=['xml', 'json', 'text']),
|
output=dict(default='xml', choices=['xml', 'json', 'text']),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -120,9 +133,13 @@ def main():
|
||||||
module.fail_json(msg='invalid rpc for running in check_mode')
|
module.fail_json(msg='invalid rpc for running in check_mode')
|
||||||
|
|
||||||
args = module.params['args'] or {}
|
args = module.params['args'] or {}
|
||||||
|
attrs = module.params['attrs'] or {}
|
||||||
|
|
||||||
xattrs = {'format': module.params['output']}
|
xattrs = {'format': module.params['output']}
|
||||||
|
|
||||||
|
for key, value in iteritems(attrs):
|
||||||
|
xattrs.update({key: value})
|
||||||
|
|
||||||
element = Element(module.params['rpc'], xattrs)
|
element = Element(module.params['rpc'], xattrs)
|
||||||
|
|
||||||
for key, value in iteritems(args):
|
for key, value in iteritems(args):
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
<rpc-reply>
|
||||||
|
<load-configuration-results>
|
||||||
|
<load-success/>
|
||||||
|
<load-error-count>0</load-error-count>
|
||||||
|
</load-configuration-results>
|
||||||
|
</rpc-reply>
|
|
@ -35,7 +35,8 @@ RPC_CLI_MAP = {
|
||||||
'get-interface-information': 'show interfaces details',
|
'get-interface-information': 'show interfaces details',
|
||||||
'get-system-memory-information': 'show system memory',
|
'get-system-memory-information': 'show system memory',
|
||||||
'get-chassis-inventory': 'show chassis hardware',
|
'get-chassis-inventory': 'show chassis hardware',
|
||||||
'get-system-storage': 'show system storage'
|
'get-system-storage': 'show system storage',
|
||||||
|
'load-configuration': 'load configuration'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -91,3 +92,8 @@ class TestJunosCommandModule(TestJunosModule):
|
||||||
args, kwargs = self.send_request.call_args
|
args, kwargs = self.send_request.call_args
|
||||||
reply = tostring(args[1]).decode()
|
reply = tostring(args[1]).decode()
|
||||||
self.assertTrue(reply.find('<interface>em0</interface><media /></get-software-information>'))
|
self.assertTrue(reply.find('<interface>em0</interface><media /></get-software-information>'))
|
||||||
|
|
||||||
|
def test_junos_rpc_attrs(self):
|
||||||
|
set_module_args(dict(rpc='load-configuration', output='xml', attrs={'url': '/var/tmp/config.conf'}))
|
||||||
|
result = self.execute_module(format='xml')
|
||||||
|
self.assertTrue(result['xml'].find('<load-success/>'))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue