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

Adding a new feature to use commit timer #416

Open
wants to merge 61 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 48 commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
ab0c9ea
new version for commit timer
Apr 18, 2023
b55b8e1
testing timer
Apr 18, 2023
e08a656
adding timer
Apr 18, 2023
df49124
adding condition
Apr 18, 2023
37a4646
revert change
Apr 18, 2023
29326b6
adding module.params for timer
Apr 18, 2023
89fef5a
Use existing Ansible params to store argument_spec
Apr 19, 2023
a0df13f
Merge pull request #2 from veyloster/whall/commit_timer
veyloster Apr 19, 2023
e0a9379
adding doc for timer
Apr 19, 2023
db01e94
updating version
Apr 19, 2023
3769461
adding description
Apr 19, 2023
31ca593
updating doc
Apr 19, 2023
caa0817
updating exemple
Apr 19, 2023
3d1a3e1
Enforcing commit timer "0 < value < 24 hours"
Apr 21, 2023
df34f1e
Remove invalid type specifier from argument_spec
Apr 21, 2023
12f93b6
Merge pull request #3 from veyloster/commit_timer_validation
veyloster Apr 21, 2023
8739465
Incorrect indentation for closing comment
Apr 24, 2023
46027f8
Add changelog
Apr 24, 2023
c67088f
Add another changelog
Apr 24, 2023
d8419e5
Invalid char in description
Apr 25, 2023
68a2d51
Remove fragments
Apr 25, 2023
71f1d26
Use fragments for changelogs
Apr 25, 2023
7e78317
Removed files created during release
Apr 26, 2023
fe62007
adding example using timer with commit
Apr 26, 2023
f838ae4
fixing indentation
Apr 26, 2023
ba3b40f
adding variable
Apr 26, 2023
664edf9
fixing indentation
Apr 26, 2023
26fb9ce
moving example to module
Apr 28, 2023
a5bb0cf
adding missing space
Apr 28, 2023
01e360e
Merge branch 'mdubuc/commit_timer' into mdubuc/adding_commit_example
veyloster Apr 28, 2023
4478e45
Merge pull request #4 from veyloster/mdubuc/adding_commit_example
veyloster Apr 28, 2023
2fb546d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 2, 2023
d736a39
removing timer from rst file
May 2, 2023
6cf2016
removing timer from rst file
May 2, 2023
19b63d7
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 2, 2023
a143813
removing change from rst
May 2, 2023
c026c03
Merge branch 'mdubuc/commit_timer' of github.com:veyloster/arista.eos…
May 2, 2023
c1d707b
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 2, 2023
f587e24
removing change from rst
May 2, 2023
9db0ca4
Merge branch 'mdubuc/commit_timer' of github.com:veyloster/arista.eos…
May 2, 2023
75bba63
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 2, 2023
57b5e1d
removing change from rst
May 2, 2023
beab0c6
Merge branch 'mdubuc/commit_timer' of github.com:veyloster/arista.eos…
May 2, 2023
e0167cb
removing change from rst
May 2, 2023
b0c10af
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 2, 2023
9d0892b
Merge branch 'main' into mdubuc/commit_timer
rohitthakur2590 May 8, 2023
9d82997
Merge branch 'main' into mdubuc/commit_timer
innerhippy May 18, 2023
39e7dab
[WIP] Add timer support to EOS Cli class
sc68cal Jul 12, 2023
a40a1ee
Merge branch 'main' into mdubuc/commit_timer
sc68cal Jul 14, 2023
18cbb30
Send commit timer command when not in check mode and timer is set
sc68cal Jul 14, 2023
7b8fab0
Put commit timer in correct location and return session name
sc68cal Jul 18, 2023
284e093
Merge branch 'ansible-collections:main' into mdubuc/commit_timer
sc68cal Jul 19, 2023
cfb1806
Merge branch 'main' into mdubuc/commit_timer
rohitthakur2590 Jul 20, 2023
8f4e4b2
Merge pull request #5 from sc68cal/mdubuc/commit_timer
veyloster Jul 21, 2023
6c1e437
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 21, 2023
9c177b9
Fix for self reference in non-class function
Jul 24, 2023
a3d7647
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 24, 2023
8eff07c
Match interface for CliconfBase.edit_config
Jul 24, 2023
a33dfc2
Merge branch 'whall/fix_parse_timer' of github.com:veyloster/arista.e…
Jul 24, 2023
5c7b2b3
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 24, 2023
f242166
Merge pull request #6 from veyloster/whall/fix_parse_timer
veyloster Jul 24, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions changelogs/fragments/eos_config_commit_timer.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
minor_changes:
- Add support for commit timer
41 changes: 41 additions & 0 deletions docs/arista.eos.eos_config_module.rst
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,21 @@ Parameters
<div>The <em>src</em> argument provides a path to the configuration file to load into the remote system. The path can either be a full system path to the configuration file if the value starts with / or relative to the root of the implemented role or playbook. This argument is mutually exclusive with the <em>lines</em> and <em>parents</em> arguments. It can be a Jinja2 template as well. The configuration lines in the source file should be similar to how it will appear if present in the running-configuration (live switch config) of the device i ncluding the indentation to ensure idempotency and correct diff. Arista EOS device config has 3 spaces indentation.</div>
</td>
</tr>
<tr>
<td colspan="2">
<div class="ansibleOptionAnchor" id="parameter-"></div>
<b>timer</b>
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
<div style="font-size: small">
<span style="color: purple">string</span>
</div>
</td>
<td>
</td>
<td>
<div>This argument will configure a commit timer which will need to be confirmed before it is automatically rolled back. <em>timer</em> is define as HhMmSs and will be converted on the switches using the Arista format HH:MM:SS. Example values - 10h, 10h19m5s, 1m60s, 10s</div>
</td>
</tr>
</table>
<br/>

Expand Down Expand Up @@ -399,6 +414,15 @@ Examples
filename: backup.cfg
dir_path: /home/user

- name: deploying with a commit timer
arista.eos.eos_config:
timer: 1m
register: eos

- name: commit using the session id
arista.eos.eos_command:
commands: configure session {{ eos.session }} commit



Return Values
Expand Down Expand Up @@ -481,6 +505,23 @@ Common return values are documented `here <https://docs.ansible.com/ansible/late
<div style="font-size: smaller; color: blue; word-wrap: break-word; word-break: break-all;">eos_config.2016-07-16@22:28:34</div>
</td>
</tr>
<tr>
<td colspan="1">
<div class="ansibleOptionAnchor" id="return-"></div>
<b>session</b>
<a class="ansibleOptionLink" href="#return-" title="Permalink to this return value"></a>
<div style="font-size: small">
<span style="color: purple">string</span>
</div>
</td>
<td>always</td>
<td>
<div>Unique session ID to use when confirming changes with commit timer</div>
<br/>
<div style="font-size: smaller"><b>Sample:</b></div>
<div style="font-size: smaller; color: blue; word-wrap: break-word; word-break: break-all;">ansible_168207712846</div>
</td>
</tr>
<tr>
<td colspan="1">
<div class="ansibleOptionAnchor" id="return-"></div>
Expand Down
42 changes: 41 additions & 1 deletion plugins/module_utils/network/eos/eos.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,11 @@
__metaclass__ = type
import json
import os
import re
import time

from datetime import timedelta

from ansible.module_utils._text import to_text
from ansible.module_utils.connection import Connection, ConnectionError
from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.config import (
Expand Down Expand Up @@ -229,6 +232,10 @@ def get_capabilities(self):


class HttpApi:
_TIMER_REGEX = re.compile(
r"(^(?P<hour>\d+)h)?((?P<min>\d+)m)?((?P<sec>\d+)s)?$",
)

def __init__(self, module):
self._module = module
self._device_configs = {}
Expand Down Expand Up @@ -411,7 +418,12 @@ def edit_config(self, config, commit=False, replace=False):
"configure session %s" % session,
"show session-config diffs",
]
if commit:

timer = self._parse_timer(self._module.params["timer"])

if commit and timer:
commands.append("commit timer %s" % timer)
elif commit:
commands.append("commit")
else:
commands.append("abort")
Expand Down Expand Up @@ -490,6 +502,34 @@ def get_capabilities(self):

return json.loads(capabilities)

def _parse_timer(self, timer):
"""Parse commit timer as "HhMmSs" format.
Eg 10h, 10h19m5s, 1m60s, 10s
Returns Arista compatible string
of form "HH:MM:SS"
Value must be non-zero and below 24 hours
"""
if timer is not None:
match = self._TIMER_REGEX.match(timer)
if not match:
self._module.fail_json(
msg="Invalid value for commit timer %r" % timer,
)
vals = match.groupdict()
total_secs = (
int(vals["hour"] or 0) * 60 * 60
+ int(vals["min"] or 0) * 60
+ int(vals["sec"] or 0)
)

td = timedelta(seconds=total_secs)

if not (timedelta(0) < td < timedelta(hours=24)):
self._module.fail_json(
msg="commit timer must be > 0 and < 24 hours",
)
return str(td)


def is_json(cmd):
return to_text(cmd, errors="surrogate_then_replace").endswith("| json")
Expand Down
22 changes: 22 additions & 0 deletions plugins/modules/eos_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,13 @@
in C(filename) within I(backup) directory.
type: path
type: dict
timer:
description:
- This argument will configure a commit timer which will need to be confirmed
before it is automatically rolled back. I(timer) is define as HhMmSs and will be
converted on the switches using the Arista format HH:MM:SS.
Example values - 10h, 10h19m5s, 1m60s, 10s
type: str
"""
# noqa: E501

Expand Down Expand Up @@ -274,6 +281,15 @@
backup_options:
filename: backup.cfg
dir_path: /home/user

- name: deploying with a commit timer
arista.eos.eos_config:
timer: 1m
register: eos

- name: commit using the session id
arista.eos.eos_command:
commands: configure session {{ eos.session }} commit
"""

RETURN = """
Expand Down Expand Up @@ -312,6 +328,11 @@
returned: when backup is true
type: str
sample: "22:28:34"
session:
description: Unique session ID to use when confirming changes with commit timer
returned: always
type: str
sample: "ansible_168207712846"
"""
from ansible.module_utils._text import to_text
from ansible.module_utils.basic import AnsibleModule
Expand Down Expand Up @@ -402,6 +423,7 @@ def main():
diff_ignore_lines=dict(type="list", elements="str"),
running_config=dict(aliases=["config"]),
intended_config=dict(),
timer=dict(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this needs a type definition, and if required default value.
timer=dict(type="str" default="")

)

mutually_exclusive = [("lines", "src"), ("parents", "src")]
Expand Down