Fix junos_config confirm commit issue (#41527)

* Fix junos_config confirm commit issue

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
This commit is contained in:
Ganesh Nalawade 2018-06-29 15:09:55 +05:30 committed by GitHub
parent e41d427d1b
commit 88b966e23b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 37 additions and 3 deletions

View file

@ -63,8 +63,8 @@ options:
statements on the remote device.
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.

View file

@ -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")
@ -143,3 +143,37 @@ class Netconf(NetconfBase):
def reboot(self):
"""reboot the device"""
return self.m.reboot().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)