Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix junos_config confirm commit issue #41527

Merged
merged 2 commits into from
Jun 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/ansible/modules/network/junos/junos_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@
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.
Expand Down
36 changes: 35 additions & 1 deletion lib/ansible/plugins/netconf/junos.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
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")

Expand Down Expand Up @@ -144,3 +144,37 @@ def halt(self):
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)