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 May 13, 2024
1 parent 16c08a2 commit b1cdef3
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 48 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.iosxr.iosxr_static_routes](https://github.com/ansible-collections/cisco.iosxr/blob/main/docs/cisco.iosxr.iosxr_static_routes_module.rst)|Resource module to configure static routes.
[cisco.iosxr.iosxr_system](https://github.com/ansible-collections/cisco.iosxr/blob/main/docs/cisco.iosxr.iosxr_system_module.rst)|Module to manage the system attributes.
[cisco.iosxr.iosxr_user](https://github.com/ansible-collections/cisco.iosxr/blob/main/docs/cisco.iosxr.iosxr_user_module.rst)|Module to manage the aggregates of local users.
[cisco.iosxr.iosxr_vrf_address_family](https://github.com/ansible-collections/cisco.iosxr/blob/main/docs/cisco.iosxr.iosxr_vrf_address_family_module.rst)|Resource module to configure VRF Address family.
[cisco.iosxr.iosxr_vrfs](https://github.com/ansible-collections/cisco.iosxr/blob/main/docs/cisco.iosxr.iosxr_vrfs_module.rst)|Manages global VRF configuration.

<!--end collection content-->
Expand Down
6 changes: 3 additions & 3 deletions changelogs/fragments/add_vrfs_module.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
minor_changes:
- Adds a new module `iosxr_vrfs` to manage VRFs on Cisco IOS-XR devices.
- The module provides the ability to manage VRFs, VRF address families, and VRF VPNs.
- https://github.com/ansible-collections/cisco.iosxr/pull/467
- Adds a new module `iosxr_vrfs` to manage VRFs on Cisco IOS-XR devices.
- The module provides the ability to manage VRFs, VRF address families, and VRF VPNs.
- https://github.com/ansible-collections/cisco.iosxr/pull/467
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 @@ -29,8 +30,7 @@


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

argument_spec = {
"config": {
Expand All @@ -57,15 +57,15 @@ class Vrf_address_familyArgs(object): # pylint: disable=R0903
"default_vrf": {
"type": "dict",
"options": {
"route_policy": {"type": "str"}
"route_policy": {"type": "str"},
},
},
"vrf": {
"type": "dict",
"options": {
"allow_imported_vpn": {
"type": "bool"
}
"type": "bool",
},
},
},
},
Expand All @@ -84,22 +84,22 @@ class Vrf_address_familyArgs(object): # pylint: disable=R0903
"type": "dict",
"options": {
"advertise_as_vpn": {
"type": "bool"
}
"type": "bool",
},
},
},
"default_vrf": {
"type": "dict",
"options": {
"route_policy": {"type": "str"}
"route_policy": {"type": "str"},
},
},
"vrf": {
"type": "dict",
"options": {
"advertise_as_vpn": {
"type": "bool"
}
"type": "bool",
},
},
},
},
Expand Down
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 @@ -20,15 +21,14 @@
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.iosxr.plugins.module_utils.network.iosxr.facts.facts import (
Facts,
from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import (
dict_merge,
)

from ansible_collections.cisco.iosxr.plugins.module_utils.network.iosxr.facts.facts import Facts
from ansible_collections.cisco.iosxr.plugins.module_utils.network.iosxr.rm_templates.vrf_address_family import (
Vrf_address_familyTemplate,
)
Expand All @@ -47,11 +47,10 @@ def __init__(self, module):
resource="vrf_address_family",
tmplt=Vrf_address_familyTemplate(),
)
self.parsers = [
]
self.parsers = []

def execute_module(self):
""" Execute the module
"""Execute the module
:rtype: A dictionary
:returns: The result from module execution
Expand All @@ -62,21 +61,19 @@ 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 = {entry['name']: entry for entry in self.want}
haved = {entry['name']: entry for entry in self.have}
wantd = {entry["name"]: entry for entry in self.want}
haved = {entry["name"]: entry for entry in self.have}

# if state is merged, merge want onto have and then compare
if self.state == "merged":
wantd = dict_merge(haved, wantd)

# if state is deleted, empty out wantd and set haved to wantd
if self.state == "deleted":
haved = {
k: v for k, v in iteritems(haved) if k in wantd or not wantd
}
haved = {k: v for k, v in iteritems(haved) if k in wantd or not wantd}
wantd = {}

# remove superfluous config for overridden and deleted
Expand All @@ -90,8 +87,8 @@ 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 Vrf_address_family network resource.
populates the list of commands to be run by comparing
the `want` and `have` data with the `parsers` defined
for the Vrf_address_family network resource.
"""
self.compare(parsers=self.parsers, want=want, have=have)
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 @@ -17,26 +18,25 @@
from copy import deepcopy

from ansible.module_utils.six import iteritems
from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import (
utils,
from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import utils

from ansible_collections.cisco.iosxr.plugins.module_utils.network.iosxr.argspec.vrf_address_family.vrf_address_family import (
Vrf_address_familyArgs,
)
from ansible_collections.cisco.iosxr.plugins.module_utils.network.iosxr.rm_templates.vrf_address_family import (
Vrf_address_familyTemplate,
)
from ansible_collections.cisco.iosxr.plugins.module_utils.network.iosxr.argspec.vrf_address_family.vrf_address_family import (
Vrf_address_familyArgs,
)


class Vrf_address_familyFacts(object):
""" The iosxr vrf_address_family facts class
"""
"""The iosxr vrf_address_family facts class"""

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

def populate_facts(self, connection, ansible_facts, data=None):
""" Populate the facts for Vrf_address_family network resource
"""Populate the facts for Vrf_address_family network resource
:param connection: the device connection
:param ansible_facts: Facts dictionary
Expand All @@ -52,16 +52,20 @@ def populate_facts(self, connection, ansible_facts, data=None):
data = connection.get()

# parse native config using the Vrf_address_family template
vrf_address_family_parser = Vrf_address_familyTemplate(lines=data.splitlines(), module=self._module)
vrf_address_family_parser = Vrf_address_familyTemplate(
lines=data.splitlines(), module=self._module
)
objs = list(vrf_address_family_parser.parse().values())

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

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

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

return ansible_facts
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 @@ -15,10 +16,12 @@
"""

import re

from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.network_template import (
NetworkTemplate,
)


class Vrf_address_familyTemplate(NetworkTemplate):
def __init__(self, lines=None, module=None):
super(Vrf_address_familyTemplate, self).__init__(lines=lines, tmplt=self, module=module)
Expand All @@ -30,18 +33,20 @@ def __init__(self, lines=None, module=None):
"getval": re.compile(
r"""
^key_a\s(?P<key_a>\S+)
$""", re.VERBOSE),
$""", re.VERBOSE,
),
"setval": "",
"result": {
},
"shared": True
"shared": True,
},
{
"name": "key_b",
"getval": re.compile(
r"""
\s+key_b\s(?P<key_b>\S+)
$""", re.VERBOSE),
$""", re.VERBOSE,
),
"setval": "",
"result": {
},
Expand Down
2 changes: 2 additions & 0 deletions plugins/modules/iosxr_vrf_address_family.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 @@ -185,6 +186,7 @@
"""

from ansible.module_utils.basic import AnsibleModule

from ansible_collections.cisco.iosxr.plugins.module_utils.network.iosxr.argspec.vrf_address_family.vrf_address_family import (
Vrf_address_familyArgs,
)
Expand Down

0 comments on commit b1cdef3

Please sign in to comment.