-
Notifications
You must be signed in to change notification settings - Fork 171
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ios_user_global - Take in count no username question
Currently, on IOS devices, when you enter a `no username` command, the system request you a question to confirm the suppression. To handle this part, I have done some change: - I have "created" the module IosNetworkTemplate, a override class of NetworkTemplate that take care the case of commands with a specific prompt - The ios_user_global module use this class for the User_globalTemplate Second point, this module allow you to create the username by using the old command line (C(username)) or the new one (C(user-name)). I have done this part in a super class to allow other template module to use this possibility. I don't have done a super class for the assert function in tests module. If you want, I can try to do it also.
- Loading branch information
1 parent
fc60ee7
commit cf1e56d
Showing
7 changed files
with
468 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright 2023 Red Hat | ||
# GNU General Public License v3.0+ | ||
# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) | ||
|
||
from __future__ import absolute_import, division, print_function | ||
|
||
|
||
__metaclass__ = type | ||
|
||
""" | ||
The User_global parser templates file. This contains | ||
a list of parser definitions and associated functions that | ||
facilitates both facts gathering and native command generation for | ||
the given network resource. | ||
""" | ||
|
||
from copy import deepcopy | ||
|
||
from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.network_template import ( | ||
NetworkTemplate, | ||
) | ||
|
||
|
||
class IosNetworkTemplate(NetworkTemplate): | ||
def __init__(self, lines=None, tmplt=None, prefix=None, module=None): | ||
super(IosNetworkTemplate, self).__init__( | ||
lines=lines, | ||
tmplt=tmplt, | ||
prefix=prefix, | ||
module=module, | ||
) | ||
|
||
def _render(self, tmplt, data, negate): | ||
if isinstance(tmplt, dict) and "command" in tmplt: | ||
res = deepcopy(tmplt) | ||
try: | ||
if callable(res["command"]): | ||
res["command"] = res["command"](data) | ||
else: | ||
res["command"] = self._template( | ||
value=res["command"], | ||
variables=data, | ||
fail_on_undefined=False, | ||
) | ||
except KeyError: | ||
return None | ||
|
||
if res: | ||
if negate: | ||
rem = "{0} ".format(self._prefix.get("remove", "no")) | ||
if isinstance(res["command"], list): | ||
res["command"] = list(map(rem, res["command"])) | ||
else: | ||
res["command"] = rem + res["command"] | ||
return res | ||
else: | ||
set_cmd = "{0} ".format(self._prefix.get("set", "")) | ||
if isinstance(res["command"], list): | ||
res["command"] = list(map(set_cmd, res["command"])) | ||
else: | ||
res["command"] = set_cmd + res["command"] | ||
return res | ||
return super(IosNetworkTemplate, self)._render(tmplt, data, negate) |
Oops, something went wrong.