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

Initial MSD Support #249

Draft
wants to merge 70 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
a86f756
MSD sub-main changes
anramgop Nov 25, 2024
77532ee
MSD sub-main changes
anramgop Nov 25, 2024
d37cdc4
Added sub-main-common and service model validation
anramgop Nov 26, 2024
49dcb6d
Split validate and load functions
anramgop Nov 27, 2024
7ef9df8
Refactoring sub main common
anramgop Nov 27, 2024
0bd0e4f
MSD create role
anramgop Nov 27, 2024
075475e
Additional refactoring for MSD and VXLAN workflows
mikewiebe Dec 3, 2024
9a73ea9
updates for msd fabric templating
mtarking Dec 3, 2024
9fd9855
resolve conflicts
mtarking Dec 3, 2024
0a1b042
remove dup file
mtarking Dec 3, 2024
e413ba3
update create task for msd
mtarking Dec 3, 2024
a220edd
update create task for msd
mtarking Dec 3, 2024
87c8395
Add child fabrics logic
mikewiebe Dec 3, 2024
3b2ad70
Merge branch 'msd' of https://github.com/netascode/ansible-dc-vxlan i…
mikewiebe Dec 3, 2024
a1b5bbd
updated defaults
mtarking Dec 3, 2024
c81d63a
Merge branch 'msd' of github.com:netascode/ansible-dc-vxlan into msd
mtarking Dec 3, 2024
9070b83
Update prepare plugins
mikewiebe Dec 3, 2024
e7520ec
more work on msd & shift to overlay key from overlay_services but wit…
mtarking Dec 5, 2024
95730f2
Merge branch 'msd' of github.com:netascode/ansible-dc-vxlan into msd
mtarking Dec 5, 2024
58aca5a
Merge branch 'develop' into msd
mtarking Dec 5, 2024
f821779
updates for build and deployment of both single fabrics and msd fabrics
mtarking Dec 5, 2024
73abf69
chagnes from review with mike
mtarking Dec 5, 2024
becfbd5
update fabric name reference to use extended
mtarking Dec 5, 2024
b6cbb56
updats to msite templates
mtarking Dec 5, 2024
1e7af33
update to msd tempaltes and add conditional to only run child fabrics…
mtarking Dec 6, 2024
48019b0
first commit from hospital
mtarking Dec 9, 2024
15655e7
updates for remove child fabrics and isn
mtarking Dec 9, 2024
13c8ba6
updates to current msd workflow
mtarking Dec 11, 2024
88742d2
merge develop
mtarking Dec 11, 2024
1219609
update github templates
mtarking Dec 11, 2024
a33823f
fix pipeline errors
mtarking Dec 11, 2024
4eb8d41
fix pipeline errors
mtarking Dec 11, 2024
898fc20
fix deprecation error in pipeline
mtarking Dec 11, 2024
b0cb580
fix deprecation error in pipeline
mtarking Dec 11, 2024
58bb54a
fix deprecation error in pipeline
mtarking Dec 11, 2024
9ccf722
Fix prep_001 plugin for multisite
mikewiebe Dec 12, 2024
2e64830
Workflow fixes
mikewiebe Dec 13, 2024
597272d
Merge develop and cleanup
mikewiebe Dec 20, 2024
58dd0f0
Fix list defaults bug
mikewiebe Dec 20, 2024
e7ef318
Prepare plugin refactor
mikewiebe Dec 21, 2024
e7ee3ff
More refactoring
mikewiebe Dec 22, 2024
7c31491
Initialize shared dict vars
mikewiebe Dec 22, 2024
6293b98
refactored external network into new format
mthurstocisco Jan 8, 2025
cffab66
more refactoring for external fabrics
mthurstocisco Jan 9, 2025
e019b74
bug fix in sub_main_external in common
mthurstocisco Jan 9, 2025
c2a0c48
External plus refactoring
mikewiebe Jan 10, 2025
4ab1f16
ISN remove devices and bug fixes
mikewiebe Jan 13, 2025
fdaa9d0
Enable child fabric delete mode flag
mikewiebe Jan 14, 2025
e765809
Github actions fixes
mikewiebe Jan 14, 2025
cde1ce4
GitHub Actions Issues
mikewiebe Jan 14, 2025
c6e6d3b
More GitHub Actions Fixes
mikewiebe Jan 14, 2025
5382ce2
Deploy False for Fabrics
mikewiebe Jan 15, 2025
57b7636
Refactor for sharing code and simplification
mikewiebe Jan 16, 2025
7d7a39f
Refactoring and Multisite VRF and Network Removal Flag
mikewiebe Jan 16, 2025
2fdcaa9
Merge branch 'develop' into msd
mikewiebe Jan 16, 2025
459d305
Fix route control no data
mikewiebe Jan 25, 2025
553df9e
Fix github actions issue
mikewiebe Jan 25, 2025
d948485
Fix rule 401
mikewiebe Jan 25, 2025
573184e
update defaults for msite
mtarking Jan 28, 2025
b7c3f28
fix typo
mtarking Jan 28, 2025
3b0a958
fix defaults
mtarking Jan 28, 2025
a0d2a08
refactor template groupings for vpc and vrf loopback
mtarking Jan 28, 2025
650efef
fix to isn fabric template
mtarking Jan 28, 2025
3c9cc02
get fabric attributes, fix msd templates, & start work on mapping swi…
mtarking Jan 29, 2025
0ef58cd
fix errors
mtarking Jan 29, 2025
938458d
refactor msite build for preprocessing for vrfs/networks attachments
mtarking Jan 30, 2025
f89bb1b
fix lint errors
mtarking Jan 30, 2025
2cd93f0
add msd child fabric vrfs template & fix lint errors
mtarking Jan 30, 2025
5627f6b
fixes
mtarking Jan 30, 2025
cf01600
set msite prepare defaults
mtarking Jan 30, 2025
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
4 changes: 3 additions & 1 deletion .github/ISSUE_TEMPLATE/bug_report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,14 @@ body:
label: Which section of the data model is this issue related to?
multiple: false
options:
- vxlan.fabric
- vxlan.global
- vxlan.topology
- vxlan.underlay
- vxlan.overlay_services
- vxlan.overlay
- vxlan.overlay_extensions
- vxlan.policy
- vxlan.multisite
- defaults.vxlan
- other
validations:
Expand Down
4 changes: 3 additions & 1 deletion .github/ISSUE_TEMPLATE/documentation_report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,14 @@ body:
label: Which section of the data model is the documentation update related?
multiple: false
options:
- vxlan.fabric
- vxlan.global
- vxlan.topology
- vxlan.underlay
- vxlan.overlay_services
- vxlan.overlay
- vxlan.overlay_extensions
- vxlan.policy
- vxlan.multisite
- defaults.vxlan
- other
validations:
Expand Down
4 changes: 3 additions & 1 deletion .github/ISSUE_TEMPLATE/feature_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,14 @@ body:
label: Which section of the data model is the new feature related?
multiple: false
options:
- vxlan.fabric
- vxlan.global
- vxlan.topology
- vxlan.underlay
- vxlan.overlay_services
- vxlan.overlay
- vxlan.overlay_extensions
- vxlan.policy
- vxlan.multisite
- defaults.vxlan
- other
validations:
Expand Down
4 changes: 3 additions & 1 deletion .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@

## Related Data Model Element
<!-- If a new element to the data model, please specify -->
* [ ] vxlan.fabric
* [ ] vxlan.global
* [ ] vxlan.topology
* [ ] vxlan.underlay
* [ ] vxlan.overlay_services
* [ ] vxlan.overlay
* [ ] vxlan.overlay_extensions
* [ ] vxlan.policy
* [ ] vxlan.multisite
* [ ] defaults.vxlan
* [ ] other

Expand Down
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,13 @@ Inside the [example repository](https://github.com/netascode/ansible-dc-vxlan-ex

```yaml
# Control Parameters for 'Remove' role tasks
child_fabric_delete_mode: false
interface_delete_mode: false
inventory_delete_mode: false
link_fabric_delete_mode: false
link_vpc_delete_mode: false
multisite_network_delete_mode: false
multisite_vrf_delete_mode: false
network_delete_mode: false
policy_delete_mode: false
vpc_delete_mode: false
Expand All @@ -77,14 +80,17 @@ The following control variables are available in this collection.

| Variable | Description | Default Value |
| -------- | ------- | ------- |
| `child_fabric_delete_mode` | Remove child fabric from MSD|MCF fabric as part of the remove role | `false` |
| `force_run_all` | Force all roles in the collection to run | `false` |
| `interface_delete_mode` | Remove interface state as part of the remove role | `false` |
| `network_delete_mode` | Remove network state as part of the remove role | `false` |
| `vrf_delete_mode` | Remove vrf state as part of the remove role | `false` |
| `inventory_delete_mode` | Remove inventory state as part of the remove role | `false` |
| `link_vpc_delete_mode` | Remove vpc link state as part of the remove role | `false` |
| `vpc_delete_mode` | Remove vpc pair state as part of the remove role | `false` |
| `multisite_network_delete_mode` | Remove network state as part of the remove role for multisite (MSD and MCF) fabrics | `false` |
| `multisite_vrf_delete_mode` | Remove vrf state as part of the remove role for multisite (MSD and MCF) fabrics | `false` |
| `network_delete_mode` | Remove network state as part of the remove role | `false` |
| `policy_delete_mode` | Remove policy state as part of the remove role | `false` |
| `vrf_delete_mode` | Remove vrf state as part of the remove role | `false` |
| `vpc_delete_mode` | Remove vpc pair state as part of the remove role | `false` |

These variables are described in more detail in different sections of this document.

Expand Down
87 changes: 69 additions & 18 deletions plugins/action/common/nac_dc_validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,16 @@
from ansible.errors import AnsibleError

try:
import iac_validate.validator
from iac_validate.yaml import load_yaml_files
import iac_validate.validator
from iac_validate.cli.options import DEFAULT_SCHEMA
except ImportError as imp_exc:
IAC_VALIDATE_IMPORT_ERROR = imp_exc
else:
IAC_VALIDATE_IMPORT_ERROR = None

import os
from ...plugin_utils.helper_functions import data_model_key_check

display = Display()

Expand All @@ -48,7 +49,6 @@ def run(self, tmp=None, task_vars=None):
results = super(ActionModule, self).run(tmp, task_vars)
results['failed'] = False
results['msg'] = None
results['data'] = {}

if IAC_VALIDATE_IMPORT_ERROR:
raise AnsibleError('iac-validate not found and must be installed. Please pip install iac-validate.') from IAC_VALIDATE_IMPORT_ERROR
Expand Down Expand Up @@ -79,21 +79,72 @@ def run(self, tmp=None, task_vars=None):
if schema == '':
schema = DEFAULT_SCHEMA

validator = iac_validate.validator.Validator(schema, rules)
if schema:
validator.validate_syntax([mdata])
if rules:
validator.validate_semantics([mdata])

msg = ""
for error in validator.errors:
msg += error + "\n"

if msg:
results['failed'] = True
results['msg'] = msg

# Return Schema Validated Model Data
results['data'] = load_yaml_files([mdata])
rules_list = []
if rules and task_vars['role_path'] in rules:
# Load in-memory data model using iac-validate
# Perform the load in this if block to avoid loading the data model multiple times when custom enhanced rules are provided
results['data'] = load_yaml_files([mdata])

# Introduce common directory to the rules list by default once vrf and network rules are updated
# rules_to_run.append(f'{rules}common')
parent_keys = ['vxlan', 'fabric']
check = data_model_key_check(results['data'], parent_keys)
if 'fabric' in check['keys_found'] and 'fabric' in check['keys_data']:
if 'type' in results['data']['vxlan']['fabric']:
if results['data']['vxlan']['fabric']['type'] in ('VXLAN_EVPN'):
rules_list.append(f'{rules}vxlan/')
elif results['data']['vxlan']['fabric']['type'] in ('MSD', 'MCF'):
rules_list.append(f'{rules}multisite/')
elif results['data']['vxlan']['fabric']['type'] in ('ISN', 'External'):
rules_list.append(f'{rules}isn/')
else:
results['failed'] = True
results['msg'] = f"vxlan.fabric.type {results['data']['vxlan']['fabric']['type']} is not a supported fabric type."
else:
results['failed'] = True
results['msg'] = "vxlan.fabric.type is not defined in the data model."
else:
# This else block is to be removed after the deprecation of vxlan.global.fabric_type
parent_keys = ['vxlan', 'global']
check = data_model_key_check(results['data'], parent_keys)
if 'global' in check['keys_found'] and 'global' in check['keys_data']:
if 'fabric_type' in results['data']['vxlan']['global']:
deprecated_msg = (
"Attempting to use vxlan.global.fabric_type due to vxlan.fabric.type not being found. "
"vxlan.global.fabric_type is being deprecated. Please use vxlan.fabric.type."
)
display.deprecated(msg=deprecated_msg, version='1.0.0', collection_name='cisco.nac_dc_vxlan')

if results['data']['vxlan']['global']['fabric_type'] in ('VXLAN_EVPN'):
rules_list.append(f'{rules}vxlan/')
elif results['data']['vxlan']['global']['fabric_type'] in ('MSD', 'MCF'):
rules_list.append(f'{rules}multisite/')
elif results['data']['vxlan']['global']['fabric_type'] in ('ISN', 'External'):
rules_list.append(f'{rules}isn/')
else:
results['failed'] = True
results['msg'] = f"vxlan.fabric.type {results['data']['vxlan']['global']['fabric_type']} is not a supported fabric type."
else:
results['failed'] = True
results['msg'] = "vxlan.fabric.type is not defined in the data model."
else:
# Else block to pickup custom enhanced rules provided by the user
rules_list.append(f'{rules}')

for rules_item in rules_list:
validator = iac_validate.validator.Validator(schema, rules_item)
if schema:
validator.validate_syntax([mdata])
if rules_item:
validator.validate_semantics([mdata])

msg = ""
for error in validator.errors:
msg += error + "\n"

if msg:
results['failed'] = True
results['msg'] = msg
break

return results
142 changes: 142 additions & 0 deletions plugins/action/common/prepare_plugins/prep_001_fabric.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
# Copyright (c) 2024 Cisco Systems, Inc. and its affiliates
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of
# this software and associated documentation files (the "Software"), to deal in
# the Software without restriction, including without limitation the rights to
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
# the Software, and to permit persons to whom the Software is furnished to do so,
# subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
# SPDX-License-Identifier: MIT

from ansible.utils.display import Display
from ....plugin_utils.helper_functions import data_model_key_check

display = Display()


class PreparePlugin:
def __init__(self, **kwargs):
self.kwargs = kwargs
self.keys = []

def prepare(self):
model_data = self.kwargs['results']['model_extended']

# !!! WARNING !!!
# ------------------------------------------------------------------------------------------
# If you are debugging problems with the data model and sections are missing make sure
# you don't have any data files with only the toplevel vxlan: key. This can cause problems
# where IaC validate removes sections of the model data, like the vxlan.underlay section
# ------------------------------------------------------------------------------------------

if not bool(model_data):
msg = 'Model data is empty! It is possible there is no data in host_vars or there'
msg += ' might be a bug in the model data. Please check host_vars for this fabric.'
msg += ' Possible reasons: duplicate keys, unsupported keys, invalid yaml etc...'
self.kwargs['results']['failed'] = True
self.kwargs['results']['msg'] = msg
return self.kwargs['results']

# Checking for fabric key in the data model.
# This type of check should be done in a rule, but fabric.name and fabric.type are foundational for the collection so we need to ensure it is set.
# This prepare plugin also helps retain backwards compatibility with global.name and global.fabric_type keys previously used.
parent_keys = ['vxlan', 'fabric']
dm_check = data_model_key_check(model_data, parent_keys)
if 'fabric' in dm_check['keys_not_found'] or 'fabric' in dm_check['keys_no_data']:
deprecated_msg = (
"Attempting to use vxlan.global.name and vxlan.global.fabric_type due to "
"vxlan.fabric.name and vxlan.fabric.type not being defined. "
"vxlan.global.name and vxlan.global.fabric_type is being deprecated. Please use vxlan.fabric."
)
display.deprecated(msg=deprecated_msg, version="1.0.0", collection_name='cisco.nac_dc_vxlan')

parent_keys = ['vxlan', 'global']
dm_check = data_model_key_check(model_data, parent_keys)
if 'global' in dm_check['keys_found'] and 'global' in dm_check['keys_data']:
model_data['vxlan'].update({'fabric': {}})
parent_keys = ['vxlan', 'global', 'name']
dm_check = data_model_key_check(model_data, parent_keys)
if 'name' in dm_check['keys_found'] and 'name' in dm_check['keys_data']:
model_data['vxlan']['fabric'].update({'name': model_data['vxlan']['global']['name']})
else:
self.kwargs['results']['failed'] = True
self.kwargs['results']['msg'] = "vxlan.global.name is not defined in the data model. Please set vxlan.fabric.name."

parent_keys = ['vxlan', 'global', 'fabric_type']
dm_check = data_model_key_check(model_data, parent_keys)
if 'fabric_type' in dm_check['keys_found'] and 'fabric_type' in dm_check['keys_data']:
model_data['vxlan']['fabric'].update({'type': model_data['vxlan']['global']['fabric_type']})
else:
self.kwargs['results']['failed'] = True
self.kwargs['results']['msg'] = "vxlan.global.fabric_type is not defined in the data model. Please set vxlan.fabric.type."
else:
self.kwargs['results']['failed'] = True
self.kwargs['results']['msg'] = "vxlan.fabric is not set in the model data."

else:
# Prepare the data model to ensure vxlan.fabric.name is set
parent_keys = ['vxlan', 'fabric', 'name']
dm_check = data_model_key_check(model_data, parent_keys)
if 'name' in dm_check['keys_no_data'] or 'name' in dm_check['keys_not_found']:
deprecated_msg = (
"Attempting to use vxlan.global.name due to vxlan.fabric.name not being defined. "
"vxlan.global.name is being deprecated. Please use vxlan.fabric."
)
display.deprecated(msg=deprecated_msg, version="1.0.0", collection_name='cisco.nac_dc_vxlan')
parent_keys = ['vxlan', 'global', 'name']
dm_check = data_model_key_check(model_data, parent_keys)
if 'name' in dm_check['keys_data']:
model_data['vxlan']['fabric'].update({'name': model_data['vxlan']['global']['name']})
else:
self.kwargs['results']['failed'] = True
self.kwargs['results']['msg'] = "vxlan.fabric.name is not defined in the data model."

# Prepare the data model to ensure vxlan.fabric.type is set
parent_keys = ['vxlan', 'fabric', 'type']
dm_check = data_model_key_check(model_data, parent_keys)
if 'type' in dm_check['keys_no_data'] or 'type' in dm_check['keys_not_found']:
deprecated_msg = (
"Attempting to use vxlan.global.type due to vxlan.fabric.type not being defined. "
"vxlan.global.type is being deprecated. Please use vxlan.fabric."
)
display.deprecated(msg=deprecated_msg, version="1.0.0", collection_name='cisco.nac_dc_vxlan')
parent_keys = ['vxlan', 'global', 'fabric_type']
dm_check = data_model_key_check(model_data, parent_keys)
if 'fabric_type' in dm_check['keys_data']:
model_data['vxlan']['fabric'].update({'type': model_data['vxlan']['global']['fabric_type']})
else:
self.kwargs['results']['failed'] = True
self.kwargs['results']['msg'] = "vxlan.fabric.type is not defined in the data model."

# For backwards compatibility, replace 'overlay_services' key with 'overlay'
# NOTE: No prepare plugin, jinja2 template or ansible task should reference 'overlay_services' after this replacement.
# NOTE: Rules are different since rules run BEFORE prepare plugins
parent_keys = ['vxlan', 'overlay_services']
dm_check = data_model_key_check(model_data, parent_keys)
if 'overlay_services' in dm_check['keys_found']:
deprecated_msg = (
"vxlan.overlay_services is being deprecated. "
"Please use vxlan.overlay instead"
)
display.deprecated(msg=deprecated_msg, version="1.0.0", collection_name='cisco.nac_dc_vxlan')
model_data['vxlan']['overlay'] = model_data['vxlan']['overlay_services']
del model_data['vxlan']['overlay_services']

parent_keys = ['vxlan', 'multisite', 'overlay']
dm_check = data_model_key_check(model_data, parent_keys)
if 'multisite' in dm_check['keys_found'] and 'overlay' in dm_check['keys_found']:
model_data['vxlan']['overlay'] = model_data['vxlan']['multisite']['overlay']

self.kwargs['results']['model_extended'] = model_data
return self.kwargs['results']
Loading