mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Fix netconf_config module default_operation issue (#44958)
* Pass parameters as dict to edit_config api as either dict or args can be passed over jsonrpc 2.0 and not combination of args and kwargs
This commit is contained in:
parent
eee406dfd2
commit
b0d6867fbb
3 changed files with 16 additions and 11 deletions
|
@ -356,12 +356,13 @@ def main():
|
||||||
before = to_text(conn.get_config(source=target), errors='surrogate_then_replace').strip()
|
before = to_text(conn.get_config(source=target), errors='surrogate_then_replace').strip()
|
||||||
|
|
||||||
kwargs = {
|
kwargs = {
|
||||||
|
'config': config,
|
||||||
'target': target,
|
'target': target,
|
||||||
'default_operation': module.params['default_operation'],
|
'default_operation': module.params['default_operation'],
|
||||||
'error_option': module.params['error_option'],
|
'error_option': module.params['error_option'],
|
||||||
'format': module.params['format'],
|
'format': module.params['format'],
|
||||||
}
|
}
|
||||||
conn.edit_config(config, **kwargs)
|
conn.edit_config(**kwargs)
|
||||||
if supports_commit and module.params['commit']:
|
if supports_commit and module.params['commit']:
|
||||||
if not module.check_mode:
|
if not module.check_mode:
|
||||||
timeout = confirm if confirm > 0 else None
|
timeout = confirm if confirm > 0 else None
|
||||||
|
|
|
@ -153,7 +153,7 @@ class NetconfBase(AnsiblePlugin):
|
||||||
return response
|
return response
|
||||||
|
|
||||||
@ensure_connected
|
@ensure_connected
|
||||||
def edit_config(self, config, format='xml', target='candidate', default_operation=None, test_option=None, error_option=None):
|
def edit_config(self, config=None, format='xml', target='candidate', default_operation=None, test_option=None, error_option=None):
|
||||||
"""
|
"""
|
||||||
Loads all or part of the specified *config* to the *target* configuration datastore.
|
Loads all or part of the specified *config* to the *target* configuration datastore.
|
||||||
:param config: Is the configuration, which must be rooted in the `config` element.
|
:param config: Is the configuration, which must be rooted in the `config` element.
|
||||||
|
@ -166,6 +166,8 @@ class NetconfBase(AnsiblePlugin):
|
||||||
The `"rollback-on-error"` *error_option* depends on the `:rollback-on-error` capability.
|
The `"rollback-on-error"` *error_option* depends on the `:rollback-on-error` capability.
|
||||||
:return: Returns xml string containing the RPC response received from remote host
|
:return: Returns xml string containing the RPC response received from remote host
|
||||||
"""
|
"""
|
||||||
|
if config is None:
|
||||||
|
raise ValueError('config value must be provided')
|
||||||
resp = self.m.edit_config(config, format=format, target=target, default_operation=default_operation, test_option=test_option,
|
resp = self.m.edit_config(config, format=format, target=target, default_operation=default_operation, test_option=test_option,
|
||||||
error_option=error_option)
|
error_option=error_option)
|
||||||
return resp.data_xml if hasattr(resp, 'data_xml') else resp.xml
|
return resp.data_xml if hasattr(resp, 'data_xml') else resp.xml
|
||||||
|
@ -194,7 +196,7 @@ class NetconfBase(AnsiblePlugin):
|
||||||
return resp.data_xml if hasattr(resp, 'data_xml') else resp.xml
|
return resp.data_xml if hasattr(resp, 'data_xml') else resp.xml
|
||||||
|
|
||||||
@ensure_connected
|
@ensure_connected
|
||||||
def dispatch(self, rpc_command, source=None, filter=None):
|
def dispatch(self, rpc_command=None, source=None, filter=None):
|
||||||
"""
|
"""
|
||||||
Execute rpc on the remote device eg. dispatch('clear-arp-table')
|
Execute rpc on the remote device eg. dispatch('clear-arp-table')
|
||||||
:param rpc_command: specifies rpc command to be dispatched either in plain text or in xml element format (depending on command)
|
:param rpc_command: specifies rpc command to be dispatched either in plain text or in xml element format (depending on command)
|
||||||
|
@ -202,9 +204,8 @@ class NetconfBase(AnsiblePlugin):
|
||||||
:param filter: specifies the portion of the configuration to retrieve (by default entire configuration is retrieved)
|
:param filter: specifies the portion of the configuration to retrieve (by default entire configuration is retrieved)
|
||||||
:return: Returns xml string containing the RPC response received from remote host
|
:return: Returns xml string containing the RPC response received from remote host
|
||||||
"""
|
"""
|
||||||
"""Execute operation on the remote device
|
if rpc_command:
|
||||||
:request: is the rpc request including attributes as XML string
|
raise ValueError('rpc_command value must be provided')
|
||||||
"""
|
|
||||||
req = fromstring(rpc_command)
|
req = fromstring(rpc_command)
|
||||||
resp = self.m.dispatch(req, source=source, filter=filter)
|
resp = self.m.dispatch(req, source=source, filter=filter)
|
||||||
return resp.data_xml if hasattr(resp, 'data_xml') else resp.xml
|
return resp.data_xml if hasattr(resp, 'data_xml') else resp.xml
|
||||||
|
@ -261,7 +262,7 @@ class NetconfBase(AnsiblePlugin):
|
||||||
return resp.data_xml if hasattr(resp, 'data_xml') else resp.xml
|
return resp.data_xml if hasattr(resp, 'data_xml') else resp.xml
|
||||||
|
|
||||||
@ensure_connected
|
@ensure_connected
|
||||||
def get_schema(self, identifier, version=None, format=None):
|
def get_schema(self, identifier=None, version=None, format=None):
|
||||||
"""
|
"""
|
||||||
Retrieve a named schema, with optional revision and type.
|
Retrieve a named schema, with optional revision and type.
|
||||||
:param identifier: name of the schema to be retrieved
|
:param identifier: name of the schema to be retrieved
|
||||||
|
@ -269,6 +270,8 @@ class NetconfBase(AnsiblePlugin):
|
||||||
:param format: format of the schema to be retrieved, yang is the default
|
:param format: format of the schema to be retrieved, yang is the default
|
||||||
:return: Returns xml string containing the RPC response received from remote host
|
:return: Returns xml string containing the RPC response received from remote host
|
||||||
"""
|
"""
|
||||||
|
if identifier:
|
||||||
|
raise ValueError('identifier value must be provided')
|
||||||
resp = self.m.get_schema(identifier, version=version, format=format)
|
resp = self.m.get_schema(identifier, version=version, format=format)
|
||||||
return resp.data_xml if hasattr(resp, 'data_xml') else resp.xml
|
return resp.data_xml if hasattr(resp, 'data_xml') else resp.xml
|
||||||
|
|
||||||
|
@ -283,9 +286,8 @@ class NetconfBase(AnsiblePlugin):
|
||||||
return resp.data_xml if hasattr(resp, 'data_xml') else resp.xml
|
return resp.data_xml if hasattr(resp, 'data_xml') else resp.xml
|
||||||
|
|
||||||
@ensure_connected
|
@ensure_connected
|
||||||
def locked(self, *args, **kwargs):
|
def locked(self, target):
|
||||||
resp = self.m.locked(*args, **kwargs)
|
return self.m.locked(target)
|
||||||
return resp.data_xml if hasattr(resp, 'data_xml') else resp.xml
|
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def get_capabilities(self):
|
def get_capabilities(self):
|
||||||
|
|
|
@ -144,7 +144,9 @@ class Netconf(NetconfBase):
|
||||||
raise Exception(to_xml(exc.xml))
|
raise Exception(to_xml(exc.xml))
|
||||||
|
|
||||||
@ensure_connected
|
@ensure_connected
|
||||||
def edit_config(self, config, format='xml', target='candidate', default_operation=None, test_option=None, error_option=None):
|
def edit_config(self, config=None, format='xml', target='candidate', default_operation=None, test_option=None, error_option=None):
|
||||||
|
if config is None:
|
||||||
|
raise ValueError('config value must be provided')
|
||||||
try:
|
try:
|
||||||
response = self.m.edit_config(config, format=format, target=target, default_operation=default_operation, test_option=test_option,
|
response = self.m.edit_config(config, format=format, target=target, default_operation=default_operation, test_option=test_option,
|
||||||
error_option=error_option)
|
error_option=error_option)
|
||||||
|
|
Loading…
Reference in a new issue