Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Aug 14, 2023
1 parent ab6ae6d commit d473625
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 37 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ Name | Description
[cisco.ios.ios_static_routes](https://github.com/ansible-collections/cisco.ios/blob/main/docs/cisco.ios.ios_static_routes_module.rst)|Resource module to configure static routes.
[cisco.ios.ios_system](https://github.com/ansible-collections/cisco.ios/blob/main/docs/cisco.ios.ios_system_module.rst)|Module to manage the system attributes.
[cisco.ios.ios_user](https://github.com/ansible-collections/cisco.ios/blob/main/docs/cisco.ios.ios_user_module.rst)|Module to manage the aggregates of local users.
[cisco.ios.ios_user_global](https://github.com/ansible-collections/cisco.ios/blob/main/docs/cisco.ios.ios_user_global_module.rst)|Resource module to configure user and enable
[cisco.ios.ios_vlans](https://github.com/ansible-collections/cisco.ios/blob/main/docs/cisco.ios.ios_vlans_module.rst)|Resource module to configure VLANs.
[cisco.ios.ios_vrf](https://github.com/ansible-collections/cisco.ios/blob/main/docs/cisco.ios.ios_vrf_module.rst)|Module to configure VRF definitions.

Expand Down
2 changes: 1 addition & 1 deletion docs/cisco.ios.ios_facts_module.rst
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ Parameters
<td>
</td>
<td>
<div>When supplied, this argument will restrict the facts collected to a given subset. Possible values for this argument include all and the resources like interfaces, vlans etc. Can specify a list of values to include a larger subset. Values can also be used with an initial <code>!</code> to specify that a specific subset should not be collected. Valid subsets are &#x27;bgp_global&#x27;, &#x27;l3_interfaces&#x27;, &#x27;lag_interfaces&#x27;, &#x27;ntp_global&#x27;, &#x27;acls&#x27;, &#x27;hostname&#x27;, &#x27;interfaces&#x27;, &#x27;lldp_interfaces&#x27;, &#x27;logging_global&#x27;, &#x27;ospf_interfaces&#x27;, &#x27;ospfv2&#x27;, &#x27;prefix_lists&#x27;, &#x27;static_routes&#x27;, &#x27;acl_interfaces&#x27;, &#x27;all&#x27;, &#x27;bgp_address_family&#x27;, &#x27;l2_interfaces&#x27;, &#x27;lacp&#x27;, &#x27;lacp_interfaces&#x27;, &#x27;lldp_global&#x27;, &#x27;ospfv3&#x27;, &#x27;snmp_server&#x27;, &#x27;vlans&#x27;, &#x27;service&#x27;.</div>
<div>When supplied, this argument will restrict the facts collected to a given subset. Possible values for this argument include all and the resources like interfaces, vlans etc. Can specify a list of values to include a larger subset. Values can also be used with an initial <code>!</code> to specify that a specific subset should not be collected. Valid subsets are &#x27;bgp_global&#x27;, &#x27;l3_interfaces&#x27;, &#x27;lag_interfaces&#x27;, &#x27;ntp_global&#x27;, &#x27;acls&#x27;, &#x27;hostname&#x27;, &#x27;interfaces&#x27;, &#x27;lldp_interfaces&#x27;, &#x27;logging_global&#x27;, &#x27;ospf_interfaces&#x27;, &#x27;ospfv2&#x27;, &#x27;prefix_lists&#x27;, &#x27;static_routes&#x27;, &#x27;acl_interfaces&#x27;, &#x27;all&#x27;, &#x27;bgp_address_family&#x27;, &#x27;l2_interfaces&#x27;, &#x27;lacp&#x27;, &#x27;lacp_interfaces&#x27;, &#x27;lldp_global&#x27;, &#x27;ospfv3&#x27;, &#x27;snmp_server&#x27;, &#x27;vlans&#x27;, &#x27;service&#x27;, &#x27;user_global&#x27;.</div>
</td>
</tr>
<tr>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from __future__ import absolute_import, division, print_function


__metaclass__ = type

#############################################
Expand All @@ -18,19 +19,18 @@
#
# To update the argspec make the desired changes
# in the documentation in the module file and re-run
# ansible.content_builder commenting out
# ansible.content_builder commenting out
# the path to external 'docstring' in build.yaml.
#
##############################################
##############################################

"""
The arg spec for the ios_user_global module
"""


class User_globalArgs(object): # pylint: disable=R0903
"""The arg spec for the ios_user_global module
"""
"""The arg spec for the ios_user_global module"""

argument_spec = {
"config": {
Expand Down
31 changes: 17 additions & 14 deletions plugins/module_utils/network/ios/config/user_global/user_global.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from __future__ import absolute_import, division, print_function


__metaclass__ = type

"""
Expand All @@ -17,25 +18,27 @@
created.
"""

import pprint

from copy import deepcopy

from ansible.module_utils.six import iteritems
from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import (
dict_merge,
)
from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module import (
ResourceModule,
)
from ansible_collections.cisco.ios.plugins.module_utils.network.ios.facts.facts import (
Facts,
from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import (
dict_merge,
)

from ansible_collections.cisco.ios.plugins.module_utils.network.ios.facts.facts import Facts
from ansible_collections.cisco.ios.plugins.module_utils.network.ios.rm_templates.user_global import (
User_globalTemplate,
)

import pprint

pp = pprint.PrettyPrinter(indent=4)


class User_global(ResourceModule):
"""
The ios_user_global config class
Expand All @@ -56,7 +59,7 @@ def __init__(self, module):
]

def execute_module(self):
""" Execute the module
"""Execute the module
:rtype: A dictionary
:returns: The result from module execution
Expand All @@ -67,13 +70,13 @@ def execute_module(self):
return self.result

def generate_commands(self):
""" Generate configuration commands to send based on
want, have and desired state.
"""Generate configuration commands to send based on
want, have and desired state.
"""
wantd = self._users_list_to_dict(self.want)
haved = self._users_list_to_dict(self.have)

pp.pprint([wantd,haved])
pp.pprint([wantd, haved])

# if state is merged, merge want onto have and then compare
if self.state == "merged":
Expand All @@ -87,9 +90,9 @@ def generate_commands(self):

def _compare(self, want, have):
"""Leverages the base class `compare()` method and
populates the list of commands to be run by comparing
the `want` and `have` data with the `parsers` defined
for the User_global network resource.
populates the list of commands to be run by comparing
the `want` and `have` data with the `parsers` defined
for the User_global network resource.
"""
self.compare(parsers=self.parsers, want=want, have=have)
self._compare_lists_attrs(want, have)
Expand Down Expand Up @@ -118,7 +121,7 @@ def _users_list_to_dict(self, data):
for k, _v in p_key.items():
if k in tmp_data:
if k == "enable":
tmp_data[k] = {str(i.get(_v,15)) : i for i in tmp_data[k]}
tmp_data[k] = {str(i.get(_v, 15)): i for i in tmp_data[k]}
else:
tmp_data[k] = {str(i[_v]): i for i in tmp_data[k]}
return tmp_data
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@
User_globalTemplate,
)


class User_globalFacts(object):
""" The ios user_global facts class
"""
"""The ios user_global facts class"""

def __init__(self, module, subspec='config', options='options'):
def __init__(self, module, subspec="config", options="options"):
self._module = module
self.argument_spec = User_globalArgs.argument_spec

Expand All @@ -45,13 +45,13 @@ def sort_list_dicts(self, objs):
for k, _v in p_key.items():
if k in objs:
if k == "enable":
objs[k] = sorted(objs[k], key=lambda _k: str(_k.get(_v,15)))
objs[k] = sorted(objs[k], key=lambda _k: str(_k.get(_v, 15)))
else:
objs[k] = sorted(objs[k], key=lambda _k: str(_k[_v]))
return objs

def populate_facts(self, connection, ansible_facts, data=None):
""" Populate the facts for User_global network resource
"""Populate the facts for User_global network resource
:param connection: the device connection
:param ansible_facts: Facts dictionary
Expand All @@ -74,13 +74,13 @@ def populate_facts(self, connection, ansible_facts, data=None):
if objs:
self.sort_list_dicts(objs)

ansible_facts['ansible_network_resources'].pop('user_global', None)
ansible_facts["ansible_network_resources"].pop("user_global", None)

params = utils.remove_empties(
user_global_parser.validate_config(self.argument_spec, {"config": objs}, redact=True)
user_global_parser.validate_config(self.argument_spec, {"config": objs}, redact=True),
)

facts['user_global'] = params['config']
ansible_facts['ansible_network_resources'].update(facts)
facts["user_global"] = params["config"]
ansible_facts["ansible_network_resources"].update(facts)

return ansible_facts
7 changes: 5 additions & 2 deletions plugins/module_utils/network/ios/rm_templates/user_global.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
NetworkTemplate,
)


class User_globalTemplate(NetworkTemplate):
def __init__(self, lines=None, module=None):
super(User_globalTemplate, self).__init__(lines=lines, tmplt=self, module=module)
Expand All @@ -36,7 +37,8 @@ def __init__(self, lines=None, module=None):
(\slevel\s(?P<level>\d+))?
(\s(?P<hash>[56789]))?
(\s(?P<value>\S+))?
""", re.VERBOSE),
""", re.VERBOSE,
),
"setval": "enable"
"{% if 'type' in password and password.type == 'password' %}"
"{{ ' password' }}"
Expand Down Expand Up @@ -72,7 +74,8 @@ def __init__(self, lines=None, module=None):
(\s(?P<type>password|secret))?
(\s(?P<hash>[56789]))?
(\s(?P<value>\S+))?
""", re.VERBOSE),
""", re.VERBOSE,
),
"setval": "username {{ name }}"
"{{ ' privilege ' + privilege|string if privilege is defined and 0 <= privilege|int <= 15 and privilege|int != 1 else '' }}"
"{% if 'type' in password and password.type == 'password' %}"
Expand Down
6 changes: 4 additions & 2 deletions plugins/modules/ios_user_global.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

from __future__ import absolute_import, division, print_function


__metaclass__ = type

DOCUMENTATION = """
Expand Down Expand Up @@ -158,7 +159,7 @@
transforms it into JSON format as per the resource module parameters and the
value is returned in the I(parsed) key within the result. The value of C(running_config)
option should be the same format as the output of command
I(show running-config | section ^username|^enable) executed on device. For state I(parsed)
I(show running-config | section ^username|^enable) executed on device. For state I(parsed)
active connection to remote host is not required.
type: str
"""
Expand Down Expand Up @@ -369,7 +370,7 @@
# "parsed": {
# "enable": [
# {
# {
# "password": {
# "type": "secret",
# "hash": 9,
Expand Down Expand Up @@ -439,6 +440,7 @@
"""

from ansible.module_utils.basic import AnsibleModule

from ansible_collections.cisco.ios.plugins.module_utils.network.ios.argspec.user_global.user_global import (
User_globalArgs,
)
Expand Down
13 changes: 8 additions & 5 deletions tests/unit/modules/network/ios/test_ios_user_global.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
Expand All @@ -21,6 +21,8 @@

__metaclass__ = type

import pprint

from textwrap import dedent

from ansible_collections.cisco.ios.plugins.modules import ios_user_global
Expand All @@ -29,9 +31,10 @@

from .ios_module import TestIosModule

import pprint

pp = pprint.PrettyPrinter(indent=4)


class TestIosUserGlobalModule(TestIosModule):
module = ios_user_global

Expand Down Expand Up @@ -195,7 +198,7 @@ def test_ios_user_global_overridden_idempotent(self):
"""\
enable secret 9 $9$q3zuC3f3vjWnWk$4BwPgPt25AUkm8Gts6aqW.NLK/90zBDnmWtOeMQqoDo
username admin secret 9 $9$oV7t.SyAkhiemE$D7GYIpVS/IOc0c15ev/n3p4Wo509XwQpPfyL1fuC5Dg
"""
""",
)

playbook = {
Expand Down Expand Up @@ -238,7 +241,7 @@ def test_ios_user_global_parsed(self):
""",
),
state="parsed",
)
),
)
parsed = {
"enable": [
Expand Down Expand Up @@ -270,7 +273,7 @@ def test_ios_user_global_gathered(self):
"""\
enable secret 9 $9$q3zuC3f3vjWnWk$4BwPgPt25AUkm8Gts6aqW.NLK/90zBDnmWtOeMQqoDo
username admin secret 9 $9$oV7t.SyAkhiemE$D7GYIpVS/IOc0c15ev/n3p4Wo509XwQpPfyL1fuC5Dg
"""
""",
)
set_module_args(dict(state="gathered"))
gathered = {
Expand Down

0 comments on commit d473625

Please sign in to comment.