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

Add ios_vxlan_vtep resource module #902

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
93 commits
Select commit Hold shift + click to select a range
0dce9ae
add_vxlan_vtep
PadminiSivaraj Aug 7, 2023
89d7427
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 7, 2023
a32d327
Update vxlan_vtep.py line length correction
PadminiSivaraj Aug 28, 2023
eaf1251
Update vxlan_vtep.py fixed replication type choices
PadminiSivaraj Aug 28, 2023
6c42310
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 28, 2023
d271f13
Update cisco.ios.ios_vxlan_vtep_module.rst
PadminiSivaraj Aug 28, 2023
693c949
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 28, 2023
9d126ac
Update ios_vxlan_vtep.py
PadminiSivaraj Aug 28, 2023
9457dda
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 28, 2023
a9c6d72
Update cisco.ios.ios_acl_interfaces_module.rst
PadminiSivaraj Aug 28, 2023
50727a2
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 28, 2023
870ce28
Update cisco.ios.ios_vxlan_vtep_module.rst
PadminiSivaraj Aug 28, 2023
b1f78f3
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 28, 2023
9422b59
Update cisco.ios.ios_acl_interfaces_module.rst
PadminiSivaraj Aug 28, 2023
7892cc7
Merge branch 'main' into add_vxlan_vtep_plugin
PadminiSivaraj Aug 28, 2023
acfc914
Update ios_vxlan_vtep.py
PadminiSivaraj Aug 28, 2023
3a1a2d2
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 28, 2023
81e97bc
Fixed test_ios_vxlan_vtep.py - wrong fact module
PadminiSivaraj Aug 28, 2023
4812a0d
changed host_reachability_bgp key
PadminiSivaraj Aug 29, 2023
2af8305
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 29, 2023
0b06ce6
Update merged.yaml
PadminiSivaraj Aug 29, 2023
3d85bc4
Update cisco.ios.ios_vxlan_vtep_module.rst
PadminiSivaraj Aug 29, 2023
8736d3a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 29, 2023
25fbd21
Update main.yaml
PadminiSivaraj Aug 29, 2023
1ecffdd
Update test_ios_vxlan_vtep.py
PadminiSivaraj Aug 29, 2023
d90ce7f
Merge branch 'main' into add_vxlan_vtep_plugin
PadminiSivaraj Aug 31, 2023
88d39d3
Merge branch 'main' into add_vxlan_vtep_plugin
KB-perByte Sep 4, 2023
ec452aa
Update test_ios_vxlan_vtep.py - list issue fix
PadminiSivaraj Sep 5, 2023
552064e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 5, 2023
8814bf4
Merge branch 'main' into add_vxlan_vtep_plugin
PadminiSivaraj Sep 7, 2023
f4b5aac
Merge branch 'main' into add_vxlan_vtep_plugin
PadminiSivaraj Sep 7, 2023
814f4e7
Update test_ios_vxlan_vtep.py
PadminiSivaraj Sep 19, 2023
11d0bd5
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 19, 2023
d74633b
Update test_ios_vxlan_vtep.py
PadminiSivaraj Sep 19, 2023
0f0d8dc
Update vxlan_vtep.py
PadminiSivaraj Sep 19, 2023
0602b47
Merge branch 'main' into add_vxlan_vtep_plugin
PadminiSivaraj Sep 19, 2023
55f5d48
Update ios_vxlan_vtep.py
PadminiSivaraj Sep 26, 2023
d6d77a1
Merge branch 'main' into add_vxlan_vtep_plugin
PadminiSivaraj Sep 26, 2023
211b3fa
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 26, 2023
28656fe
Update cisco.ios.ios_vxlan_vtep_module.rst
PadminiSivaraj Sep 26, 2023
1494dec
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 26, 2023
e6d1802
Update vxlan_vtep.py
PadminiSivaraj Sep 26, 2023
2d1b703
Update vxlan_vtep.py - removed unused imports
PadminiSivaraj Sep 27, 2023
7ee6abd
Update vxlan_vtep.py - removed unused import
PadminiSivaraj Sep 27, 2023
cc9d2f0
Update test_ios_vxlan_vtep.py - removed trailing comma
PadminiSivaraj Sep 27, 2023
0de3dd8
Merge branch 'main' into add_vxlan_vtep_plugin
KB-perByte Oct 4, 2023
d6102da
Merge branch 'main' into add_vxlan_vtep_plugin
KB-perByte Oct 11, 2023
9443794
Merge branch 'main' into add_vxlan_vtep_plugin
KB-perByte Oct 31, 2023
a51e474
Update merged.yaml
PadminiSivaraj Nov 1, 2023
1b55afa
Update replaced.yaml
PadminiSivaraj Nov 1, 2023
0b023cd
Update gathered.yaml
PadminiSivaraj Nov 1, 2023
d39db56
Update overridden.yaml
PadminiSivaraj Nov 1, 2023
009bb46
Update parsed.yaml
PadminiSivaraj Nov 1, 2023
a40a542
Update rendered.yaml
PadminiSivaraj Nov 1, 2023
bbad657
Update gathered.yaml
PadminiSivaraj Nov 1, 2023
93c0f9d
Update parsed.yaml
PadminiSivaraj Nov 1, 2023
f5b24db
Update _populate_config.yaml
PadminiSivaraj Nov 1, 2023
e1e55c2
Update vxlan_vtep.py
PadminiSivaraj Nov 1, 2023
cd9e3e5
Update main.yaml
PadminiSivaraj Nov 1, 2023
23180c8
Update main.yaml
PadminiSivaraj Nov 1, 2023
7fad1a9
Update main.yaml
PadminiSivaraj Nov 1, 2023
b9d7347
Update _populate_config.yaml
PadminiSivaraj Nov 1, 2023
2ee5363
Update _parsed.cfg
PadminiSivaraj Nov 1, 2023
4df444f
Update vxlan_vtep.py
PadminiSivaraj Nov 1, 2023
c0748b6
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 1, 2023
ad416cf
Update merged.yaml
PadminiSivaraj Nov 1, 2023
21b1d99
Update overridden.yaml
PadminiSivaraj Nov 1, 2023
c116982
Update replaced.yaml
PadminiSivaraj Nov 1, 2023
6e21362
Update main.yaml
PadminiSivaraj Nov 1, 2023
1875bc9
Merge branch 'main' into add_vxlan_vtep_plugin
PadminiSivaraj Nov 8, 2023
ac5f05e
Merge branch 'main' into add_vxlan_vtep_plugin
PadminiSivaraj Nov 9, 2023
33d88df
Update ios_vxlan_vtep.py
PadminiSivaraj Nov 9, 2023
1ca7d87
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 9, 2023
a0d9016
Update cisco.ios.ios_vxlan_vtep_module.rst
PadminiSivaraj Nov 9, 2023
d56523b
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 9, 2023
7b57d8d
added vlan config files
PadminiSivaraj Nov 9, 2023
d2b4ecc
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 9, 2023
a0f2e9a
Update _populate_vlan_config.yaml
PadminiSivaraj Nov 9, 2023
aaad0cf
Rename _populate_vlan_config.yaml to _populate_vlan_vrf_config.yaml
PadminiSivaraj Nov 9, 2023
ef4d6e7
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 9, 2023
17c6872
Update overridden.yaml
PadminiSivaraj Nov 9, 2023
c28b971
Update replaced.yaml
PadminiSivaraj Nov 9, 2023
505bf8e
Update deleted.yaml
PadminiSivaraj Nov 9, 2023
fc2b281
Update merged.yaml
PadminiSivaraj Nov 9, 2023
ecffb68
Update gathered.yaml
PadminiSivaraj Nov 9, 2023
e98b838
Update test_ios_vxlan_vtep.py
PadminiSivaraj Nov 9, 2023
c53f14f
Update _populate_vlan_vrf_config.yaml
PadminiSivaraj Nov 9, 2023
966eb18
Update ios_vxlan_vtep.py
PadminiSivaraj Nov 9, 2023
c43b669
Merge branch 'main' into add_vxlan_vtep_plugin
KB-perByte Nov 16, 2023
0a4c6d6
Merge branch 'main' into add_vxlan_vtep_plugin
KB-perByte Nov 16, 2023
84e8f25
Merge branch 'main' into add_vxlan_vtep_plugin
PadminiSivaraj Nov 17, 2023
27c540d
Update plugins/modules/ios_vxlan_vtep.py
KB-perByte Nov 20, 2023
e4f141f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 20, 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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ Name | Description
[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_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.
[cisco.ios.ios_vxlan_vtep](https://github.com/ansible-collections/cisco.ios/blob/main/docs/cisco.ios.ios_vxlan_vtep_module.rst)|Resource module to configure VXLAN VTEP interface.

<!--end collection content-->

Expand Down
2 changes: 2 additions & 0 deletions changelogs/fragments/add_ios_vxlan_vtep.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- Added ios_vxlan_vtep resource module.
701 changes: 701 additions & 0 deletions docs/cisco.ios.ios_vxlan_vtep_module.rst

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions meta/runtime.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---

Check failure on line 1 in meta/runtime.yml

View workflow job for this annotation

GitHub Actions / Ansible Lint

meta-runtime[unsupported-version]

requires_ansible key must be set to a supported version.
plugin_routing:
action:
acl_interfaces:
Expand Down Expand Up @@ -71,6 +71,8 @@
redirect: cisco.ios.ios
ios_system:
redirect: cisco.ios.ios
ios_vxlan_vtep:
redirect: cisco.ios.ios
l2_interfaces:
redirect: cisco.ios.ios
l3_interfaces:
Expand Down Expand Up @@ -119,6 +121,8 @@
redirect: cisco.ios.ios
vrf:
redirect: cisco.ios.ios
vxlan_vtep:
redirect: cisco.ios.ios
modules:
acl_interfaces:
redirect: cisco.ios.ios_acl_interfaces
Expand Down Expand Up @@ -218,4 +222,6 @@
redirect: cisco.ios.ios_vlans
vrf:
redirect: cisco.ios.ios_vrf
vxlan_vtep:
redirect: cisco.ios.ios_vxlan_vtep
requires_ansible: ">=2.9.10"
Empty file.
102 changes: 102 additions & 0 deletions plugins/module_utils/network/ios/argspec/vxlan_vtep/vxlan_vtep.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
# -*- 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

#############################################
# WARNING #
#############################################
#
# This file is auto generated by the
# ansible.content_builder.
#
# Manually editing this file is not advised.
#
# To update the argspec make the desired changes
# in the documentation in the module file and re-run
# ansible.content_builder commenting out
# the path to external 'docstring' in build.yaml.
#
##############################################

"""
The arg spec for the ios_vxlan_vtep module
"""


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

argument_spec = {
"config": {
"type": "list",
"elements": "dict",
"options": {
"interface": {"type": "str", "required": True},
"source_interface": {"type": "str"},
"host_reachability_bgp": {
"type": "bool",
},
"member": {
"type": "dict",
"options": {
"vni": {
"type": "dict",
"options": {
"l2vni": {
"type": "list",
"elements": "dict",
"options": {
"vni": {"type": "int"},
"replication": {
"type": "dict",
"options": {
"type": {
"type": "str",
"choices": ["ingress", "static"],
},
"mcast_group": {
"type": "dict",
"options": {
"ipv4": {"type": "str"},
"ipv6": {"type": "str"},
},
},
},
},
},
},
"l3vni": {
"type": "list",
"elements": "dict",
"options": {
"vni": {"type": "int"},
"vrf": {"type": "str"},
},
},
},
},
},
},
},
},
"running_config": {"type": "str"},
"state": {
"type": "str",
"choices": [
"merged",
"replaced",
"overridden",
"deleted",
"rendered",
"gathered",
"parsed",
],
"default": "merged",
},
} # pylint: disable=C0301
Empty file.
190 changes: 190 additions & 0 deletions plugins/module_utils/network/ios/config/vxlan_vtep/vxlan_vtep.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
#
# -*- 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 ios_vxlan_vtep config file.
It is in this file where the current configuration (as dict)
is compared to the provided configuration (as dict) and the command set
necessary to bring the current configuration to its desired end-state is
created.
"""

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

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.vxlan_vtep import (
Vxlan_vtepTemplate,
)


class Vxlan_vtep(ResourceModule):
"""
The ios_vxlan_vtep config class
"""

def __init__(self, module):
super(Vxlan_vtep, self).__init__(
empty_fact_val={},
facts_module=Facts(module),
module=module,
resource="vxlan_vtep",
tmplt=Vxlan_vtepTemplate(),
)
self.parsers = [
"source_interface",
"host_reachability_bgp",
]

def execute_module(self):
"""Execute the module

:rtype: A dictionary
:returns: The result from module execution
"""

if self.state not in ["parsed", "gathered"]:
self.generate_commands()
self.run_commands()
return self.result

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

wantd, haved = self._interface_list_to_dict(self.want, 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}
wantd_copy = wantd.copy()
wantd = {}

# remove superfluous config for deleted
if self.state in ["overridden", "deleted"]:
for k, have in iteritems(haved):
if k not in wantd:
have = self._filtered_dict(wantd_copy.get(k), have)
self._compare(want={}, have=have)

for k, want in iteritems(wantd):
self._compare(want=want, have=haved.pop(k, {}))

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 Vxlan_vtep network resource.
"""

begin = len(self.commands)
self.compare(parsers=self.parsers, want=want, have=have)

self._compare_member_vnis(
want.pop("member", {}).get("vni", {}),
have.pop("member", {}).get("vni", {}),
)

if len(self.commands) != begin:
self.commands.insert(
begin,
self._tmplt.render(want or have, "interface", False),
)

def _compare_member_vnis(self, wantmv, havemv):
"""Compare member VNIs dict"""

PARSER_DICT = {
"l2vni": "replication",
"l3vni": "vrf",
}

for vni_type in ["l2vni", "l3vni"]:
wantd = wantmv.get(vni_type, {})
haved = havemv.get(vni_type, {})
undel_vnis = haved.copy()

for wvni, want in wantd.items():
have = haved.pop(wvni, {})
if want != have:
# remove exiting config of the member VNI
self.addcmd(undel_vnis.pop(wvni, {}), PARSER_DICT[vni_type], True)
if vni_type == "l3vni":
undel_vnis = self._remove_existing_vnis_vrfs(want["vrf"], undel_vnis)
self.addcmd(want, PARSER_DICT[vni_type])

# remove remaining configs in have for replaced state
for hvni, have in haved.items():
if hvni in undel_vnis:
self.addcmd(have, PARSER_DICT[vni_type], True)

def _interface_list_to_dict(self, want, have):
"""Convert all list of dicts to dicts of dicts"""

wantd = {entry["interface"]: entry for entry in want}
haved = {entry["interface"]: entry for entry in have}

for each in wantd, haved:
if each:
for nvi, nvid in each.items():
member_vni = nvid.get("member", {}).get("vni")
if member_vni:
for vni_type in member_vni:
member_vni[vni_type] = param_list_to_dict(
member_vni[vni_type],
unique_key="vni",
remove_key=False,
)

return wantd, haved

def _remove_existing_vnis_vrfs(self, want_vrf, haved):
"""Remove member VNIs of corresponding VRF"""

vrf_haved = next(
(h for h in haved.values() if h["vrf"] == want_vrf),
None,
)
if vrf_haved:
self.addcmd(haved.pop(vrf_haved["vni"]), "vrf", True)
return haved

def _filtered_dict(self, want, have):
"""Remove other config from 'have' if 'member' key is present"""

if "member" in want:
have_member = {}
want_vni_dict = want.get("member", {}).get("vni", {})
have_vni_dict = have.get("member", {}).get("vni", {})

for vni_type, have_vnis in have_vni_dict.items():
want_vnis = want_vni_dict.get(vni_type, {})
have_member[vni_type] = {
vni: have_vni_dict[vni_type].get(vni) for vni in have_vnis if vni in want_vnis
}
have = {
"interface": have["interface"],
"member": {"vni": have_member},
}

return have
4 changes: 4 additions & 0 deletions plugins/module_utils/network/ios/facts/facts.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@
from ansible_collections.cisco.ios.plugins.module_utils.network.ios.facts.vlans.vlans import (
VlansFacts,
)
from ansible_collections.cisco.ios.plugins.module_utils.network.ios.facts.vxlan_vtep.vxlan_vtep import (
Vxlan_vtepFacts,
)


FACT_LEGACY_SUBSETS = dict(default=Default, hardware=Hardware, interfaces=Interfaces, config=Config)
Expand Down Expand Up @@ -128,6 +131,7 @@
service=ServiceFacts,
snmp_server=Snmp_serverFacts,
hostname=HostnameFacts,
vxlan_vtep=Vxlan_vtepFacts,
evpn_global=Evpn_globalFacts,
evpn_evi=Evpn_eviFacts,
)
Expand Down
Empty file.
Loading
Loading