mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-25 20:01:25 -07:00
Update netconf plugins for junos and iosxr (#44157)
* Update netconf plugins for junos and iosxr Fixes #39160 * Update api signature for netcon api's from variable arguments to named arguments * Udpate get default rpc supported * Fix CI issue
This commit is contained in:
parent
615337c3d7
commit
d9ee693652
3 changed files with 188 additions and 109 deletions
|
@ -61,23 +61,29 @@ class Netconf(NetconfBase):
|
|||
|
||||
@ensure_connected
|
||||
def execute_rpc(self, name):
|
||||
"""RPC to be execute on remote device
|
||||
:name: Name of rpc in string format"""
|
||||
"""
|
||||
RPC to be execute on remote device
|
||||
:param name: Name of rpc in string format
|
||||
:return: Received rpc response from remote host
|
||||
"""
|
||||
return self.rpc(name)
|
||||
|
||||
@ensure_connected
|
||||
def load_configuration(self, *args, **kwargs):
|
||||
"""Loads given configuration on device
|
||||
:format: Format of configuration (xml, text, set)
|
||||
:action: Action to be performed (merge, replace, override, update)
|
||||
:target: is the name of the configuration datastore being edited
|
||||
:config: is the configuration in string format."""
|
||||
if kwargs.get('config'):
|
||||
if kwargs.get('format', 'xml') == 'xml':
|
||||
kwargs['config'] = to_ele(kwargs['config'])
|
||||
def load_configuration(self, format='xml', action='merge', target='candidate', config=None):
|
||||
"""
|
||||
Load given configuration on device
|
||||
:param format: Format of configuration (xml, text, set)
|
||||
:param action: Action to be performed (merge, replace, override, update)
|
||||
:param target: The name of the configuration datastore being edited
|
||||
:param config: The configuration to be loaded on remote host in string format
|
||||
:return: Received rpc response from remote host in string format
|
||||
"""
|
||||
if config:
|
||||
if format == 'xml':
|
||||
config = to_ele(config)
|
||||
|
||||
try:
|
||||
return self.m.load_configuration(*args, **kwargs).data_xml
|
||||
return self.m.load_configuration(format=format, action=action, target=target, config=config).data_xml
|
||||
except RPCError as exc:
|
||||
raise Exception(to_xml(exc.xml))
|
||||
|
||||
|
@ -96,7 +102,11 @@ class Netconf(NetconfBase):
|
|||
|
||||
@staticmethod
|
||||
def guess_network_os(obj):
|
||||
|
||||
"""
|
||||
Guess the remote network os name
|
||||
:param obj: Netconf connection class object
|
||||
:return: Network OS name
|
||||
"""
|
||||
try:
|
||||
m = manager.connect(
|
||||
host=obj._play_context.remote_addr,
|
||||
|
@ -121,18 +131,25 @@ class Netconf(NetconfBase):
|
|||
return guessed_os
|
||||
|
||||
@ensure_connected
|
||||
def get_configuration(self, *args, **kwargs):
|
||||
"""Retrieve all or part of a specified configuration.
|
||||
:format: format in configuration should be retrieved
|
||||
:filter: specifies the portion of the configuration to retrieve
|
||||
(by default entire configuration is retrieved)"""
|
||||
return self.m.get_configuration(*args, **kwargs).data_xml
|
||||
def get_configuration(self, format='xml', filter=None):
|
||||
"""
|
||||
Retrieve all or part of a specified configuration.
|
||||
:param format: format in which configuration should be retrieved
|
||||
:param filter: specifies the portion of the configuration to retrieve
|
||||
:return: Received rpc response from remote host in string format
|
||||
"""
|
||||
return self.m.get_configuration(format=format, filter=filter).data_xml
|
||||
|
||||
@ensure_connected
|
||||
def compare_configuration(self, *args, **kwargs):
|
||||
"""Compare configuration
|
||||
:rollback: rollback id"""
|
||||
return self.m.compare_configuration(*args, **kwargs).data_xml
|
||||
def compare_configuration(self, rollback=0):
|
||||
"""
|
||||
Compare the candidate configuration with running configuration
|
||||
by default. The candidate configuration can be compared with older
|
||||
committed configuration by providing rollback id.
|
||||
:param rollback: Rollback id of previously commited configuration
|
||||
:return: Received rpc response from remote host in string format
|
||||
"""
|
||||
return self.m.compare_configuration(rollback=rollback).data_xml
|
||||
|
||||
@ensure_connected
|
||||
def halt(self):
|
||||
|
@ -150,15 +167,21 @@ class Netconf(NetconfBase):
|
|||
# Remove below method after the issue in ncclient is fixed.
|
||||
@ensure_connected
|
||||
def commit(self, confirmed=False, check=False, timeout=None, comment=None, synchronize=False, at_time=None):
|
||||
"""Commit the candidate configuration as the device's new current configuration.
|
||||
Depends on the `:candidate` capability.
|
||||
A confirmed commit (i.e. if *confirmed* is `True`) is reverted if there is no
|
||||
followup commit within the *timeout* interval. If no timeout is specified the
|
||||
confirm timeout defaults to 600 seconds (10 minutes).
|
||||
A confirming commit may have the *confirmed* parameter but this is not required.
|
||||
Depends on the `:confirmed-commit` capability.
|
||||
:confirmed: whether this is a confirmed commit
|
||||
:timeout: specifies the confirm timeout in seconds
|
||||
"""
|
||||
Commit the candidate configuration as the device's new current configuration.
|
||||
Depends on the `:candidate` capability.
|
||||
A confirmed commit (i.e. if *confirmed* is `True`) is reverted if there is no
|
||||
followup commit within the *timeout* interval. If no timeout is specified the
|
||||
confirm timeout defaults to 600 seconds (10 minutes).
|
||||
A confirming commit may have the *confirmed* parameter but this is not required.
|
||||
Depends on the `:confirmed-commit` capability.
|
||||
:param confirmed: whether this is a confirmed commit
|
||||
:param check: Check correctness of syntax
|
||||
:param timeout: specifies the confirm timeout in seconds
|
||||
:param comment: Message to write to commit log
|
||||
:param synchronize: Synchronize commit on remote peers
|
||||
:param at_time: Time at which to activate configuration changes
|
||||
:return: Received rpc response from remote host
|
||||
"""
|
||||
obj = new_ele('commit-configuration')
|
||||
if confirmed:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue