Fixes #40626
* Due to issue in ncclient commit() method for Juniper
device (ncclient/ncclient#238)
add a workaround in junos netconf plugin to generate proper
commit-configuration xml and execute it using ncclient
generic `rpc()` method.
* Update junos_config doc
* Update changelog
(cherry picked from commit 88b966e23b
)
This commit is contained in:
parent
fdb813766a
commit
f942d71b36
3 changed files with 39 additions and 8 deletions
2
changelogs/fragments/junos_config_confirm_commit.yaml
Normal file
2
changelogs/fragments/junos_config_confirm_commit.yaml
Normal file
|
@ -0,0 +1,2 @@
|
|||
bugfixes:
|
||||
- Fix junos_config confirm commit timeout issue (https://github.com/ansible/ansible/pull/41527)
|
|
@ -73,8 +73,8 @@ options:
|
|||
default: null
|
||||
confirm:
|
||||
description:
|
||||
- The C(confirm) argument will configure a time out value for
|
||||
the commit to be confirmed before it is automatically
|
||||
- The C(confirm) argument will configure a time out value in minutes
|
||||
for the commit to be confirmed before it is automatically
|
||||
rolled back. If the C(confirm) argument is set to False, this
|
||||
argument is silently ignored. If the value for this argument
|
||||
is set to 0, the commit is confirmed immediately.
|
||||
|
|
|
@ -32,7 +32,7 @@ try:
|
|||
from ncclient import manager
|
||||
from ncclient.operations import RPCError
|
||||
from ncclient.transport.errors import SSHUnknownHostError
|
||||
from ncclient.xml_ import to_ele, to_xml, new_ele
|
||||
from ncclient.xml_ import to_ele, to_xml, new_ele, sub_ele
|
||||
except ImportError:
|
||||
raise AnsibleError("ncclient is not installed")
|
||||
|
||||
|
@ -144,11 +144,6 @@ class Netconf(NetconfBase):
|
|||
"""reboot the device"""
|
||||
return self.m.reboot().data_xml
|
||||
|
||||
@ensure_connected
|
||||
def halt(self):
|
||||
"""reboot the device"""
|
||||
return self.m.halt().data_xml
|
||||
|
||||
@ensure_connected
|
||||
def get(self, *args, **kwargs):
|
||||
try:
|
||||
|
@ -184,3 +179,37 @@ class Netconf(NetconfBase):
|
|||
@ensure_connected
|
||||
def discard_changes(self, *args, **kwargs):
|
||||
return self.m.discard_changes(*args, **kwargs).data_xml
|
||||
|
||||
# Due to issue in ncclient commit() method for Juniper (https://github.com/ncclient/ncclient/issues/238)
|
||||
# below commit() is a workaround which build's raw `commit-configuration` xml with required tags and uses
|
||||
# ncclient generic rpc() method to execute rpc on remote host.
|
||||
# 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
|
||||
"""
|
||||
obj = new_ele('commit-configuration')
|
||||
if confirmed:
|
||||
sub_ele(obj, 'confirmed')
|
||||
if check:
|
||||
sub_ele(obj, 'check')
|
||||
if synchronize:
|
||||
sub_ele(obj, 'synchronize')
|
||||
if at_time:
|
||||
subele = sub_ele(obj, 'at-time')
|
||||
subele.text = str(at_time)
|
||||
if comment:
|
||||
subele = sub_ele(obj, 'log')
|
||||
subele.text = str(comment)
|
||||
if timeout:
|
||||
subele = sub_ele(obj, 'confirm-timeout')
|
||||
subele.text = str(timeout)
|
||||
return self.rpc(obj)
|
||||
|
|
Loading…
Reference in a new issue