Skip to content

Commit

Permalink
Refactor for sharing code and simplification
Browse files Browse the repository at this point in the history
  • Loading branch information
mikewiebe committed Jan 16, 2025
1 parent 5382ce2 commit 57b7636
Show file tree
Hide file tree
Showing 60 changed files with 2,557 additions and 105 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def prepare(self):
model_data = self.kwargs['results']['model_extended']

# This plugin does not apply to the follwing fabric types
if model_data['vxlan']['fabric']['type'] in ['ISN', 'MSD', 'MCF']:
if model_data['vxlan']['fabric']['type'] in ['MSD', 'MCF']:
return self.kwargs['results']

# Loop over all the roles in vxlan.topology.switches.role
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def prepare(self):
model_data = self.kwargs['results']['model_extended']

# We don't have switches for Multisite fabrics so need special handling
if model_data['vxlan']['fabric']['type'] in ('MSD', 'MCF', 'ISN'):
if model_data['vxlan']['fabric']['type'] in ('MSD', 'MCF'):
switches = []
else:
switches = model_data['vxlan']['topology']['switches']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def prepare(self):
model_data = self.kwargs['results']['model_extended']

# This plugin does not apply to the follwing fabric types
if model_data['vxlan']['fabric']['type'] in ['ISN', 'MSD', 'MCF']:
if model_data['vxlan']['fabric']['type'] in ['MSD', 'MCF']:
return self.kwargs['results']

model_data['vxlan']['topology']['interfaces'] = {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ def __init__(self, **kwargs):
def prepare(self):
model_data = self.kwargs['results']['model_extended']

if model_data['vxlan']['fabric']['type'] == 'ISN':
return self.kwargs['results']
# if model_data['vxlan']['fabric']['type'] == 'ISN':
# return self.kwargs['results']

# Check if vxlan.topology is defined
if model_data.get('vxlan').get('topology') is not None:
Expand Down
4 changes: 2 additions & 2 deletions plugins/action/dtc/get_poap_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,8 @@ def run(self, tmp=None, task_vars=None):
params = {}
params['model_data'] = self._task.args["model_data"]

if params['model_data']['vxlan']['fabric']['type'] == 'ISN':
return results
# if params['model_data']['vxlan']['fabric']['type'] == 'ISN':
# return results

params['action_plugin'] = self._execute_module
params['task_vars'] = task_vars
Expand Down
6 changes: 3 additions & 3 deletions plugins/action/dtc/update_switch_hostname_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ def run(self, tmp=None, task_vars=None):
)

dm_switches = []
if model_data["vxlan"]["fabric"]["type"] in ('VXLAN_EVPN', 'External'):
if model_data["vxlan"]["fabric"]["type"] in ('VXLAN_EVPN', 'ISN', 'External'):
dm_switches = model_data["vxlan"]["topology"]["switches"]
elif model_data["vxlan"]["fabric"]["type"] in ('ISN'):
dm_switches = model_data["vxlan"]["multisite"]["isn"]["topology"]["switches"]
# elif model_data["vxlan"]["fabric"]["type"] in ('ISN'):
# dm_switches = model_data["vxlan"]["multisite"]["isn"]["topology"]["switches"]

switch_match = next((item for item in dm_switches if item["serial_number"] == switch_serial_number))

Expand Down
22 changes: 15 additions & 7 deletions plugins/plugin_utils/data_model_keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,21 @@
model_keys['VXLAN_EVPN']['policy.groups'] = [root_key, 'policy', 'groups', 'LIST']
model_keys['VXLAN_EVPN']['policy.switches'] = [root_key, 'policy', 'switches', 'LIST']

# ISN KEYS

model_keys['ISN']['topology'] = [root_key, 'topology', 'KEY']
model_keys['ISN']['topology.edge_connections'] = [root_key, 'topology', 'edge_connections', 'LIST']
model_keys['ISN']['topology.fabric_links'] = [root_key, 'topology', 'fabric_links', 'LIST']
model_keys['ISN']['topology.switches'] = [root_key, 'topology', 'switches', 'LIST']
model_keys['ISN']['topology.switches.freeform'] = [root_key, 'topology', 'switches', 'freeform', 'LIST_INDEX']
model_keys['ISN']['topology.switches.interfaces'] = [root_key, 'topology', 'switches', 'interfaces', 'LIST_INDEX']
model_keys['ISN']['topology.vpc_peers'] = [root_key, 'topology', 'vpc_peers', 'LIST']
# ---
model_keys['ISN']['policy'] = [root_key, 'policy', 'KEY']
model_keys['ISN']['policy.policies'] = [root_key, 'policy', 'policies', 'LIST']
model_keys['ISN']['policy.groups'] = [root_key, 'policy', 'groups', 'LIST']
model_keys['ISN']['policy.switches'] = [root_key, 'policy', 'switches', 'LIST']

# MSD KEYS

# ---
Expand All @@ -77,10 +92,3 @@
model_keys['MSD']['multisite.overlay.networks'] = [root_key, 'multisite', 'overlay', 'networks', 'LIST']
model_keys['MSD']['multisite.overlay.network_attach_groups'] = [root_key, 'multisite', 'overlay', 'network_attach_groups', 'LIST']
model_keys['MSD']['multisite.overlay.network_attach_groups.switches'] = [root_key, 'multisite', 'overlay', 'network_attach_groups', 'switches', 'LIST_INDEX']

# ISN KEYS

# ---
model_keys['ISN']['multisite.isn'] = [root_key, 'multisite', 'isn', 'KEY']
model_keys['ISN']['multisite.isn.topology'] = [root_key, 'multisite', 'isn', 'topology', 'KEY']
model_keys['ISN']['multisite.isn.topology.switches'] = [root_key, 'multisite', 'isn', 'topology', 'switches', 'LIST']
77 changes: 77 additions & 0 deletions roles/dtc/common/tasks/common/ndfc_fabric.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# 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

---

- name: Initialize changes_detected Var
ansible.builtin.set_fact:
changes_detected_fabric: false
delegate_to: localhost

- name: Set file_name Var
ansible.builtin.set_fact:
file_name: "ndfc_fabric.yml"
delegate_to: localhost

- name: Stat Previous File If It Exists
ansible.builtin.stat:
path: "{{ path_name }}{{ file_name }}"
register: data_file_previous
delegate_to: localhost
# TODO: Add capability to overridde path variable above for CI/CD pipeline

- name: Backup Previous Data File If It Exists
ansible.builtin.copy:
src: "{{ path_name }}{{ file_name }}"
dest: "{{ path_name }}{{ file_name }}.old"
when: data_file_previous.stat.exists

- name: Delete Previous Data File If It Exists
ansible.builtin.file:
state: absent
path: "{{ path_name }}{{ file_name }}"
delegate_to: localhost
when: data_file_previous.stat.exists

- name: Build Fabric Creation Parameters From Template
ansible.builtin.template:
src: ndfc_fabric.j2
dest: "{{ path_name }}{{ file_name }}"
delegate_to: localhost

- ansible.builtin.set_fact:
fabric_config: "{{ lookup('file', path_name + file_name) | from_yaml }}"
delegate_to: localhost

- name: Diff Previous and Current Data Files
cisco.nac_dc_vxlan.dtc.diff_model_changes:
file_name_previous: "{{ path_name }}{{ file_name }}.old"
file_name_current: "{{ path_name }}{{ file_name }}"
register: file_diff_result
delegate_to: localhost

- name: Set File Change Flag Based on File Diff Result
ansible.builtin.set_fact:
changes_detected_fabric: true
delegate_to: localhost
when:
- file_diff_result.file_data_changed
- check_roles['save_previous']
83 changes: 83 additions & 0 deletions roles/dtc/common/tasks/common/ndfc_fabric_links.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# 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

---

- name: Initialize changes_detected Var
ansible.builtin.set_fact:
changes_detected_fabric_links: false
delegate_to: localhost

- name: Set file_name Var
ansible.builtin.set_fact:
file_name: "ndfc_fabric_links.yml"
delegate_to: localhost

- name: Stat Previous File If It Exists
ansible.builtin.stat:
path: "{{ path_name }}{{ file_name }}"
register: data_file_previous
delegate_to: localhost

- name: Backup Previous Data File If It Exists
ansible.builtin.copy:
src: "{{ path_name }}{{ file_name }}"
dest: "{{ path_name }}{{ file_name }}.old"
when: data_file_previous.stat.exists

- name: Delete Previous Data File If It Exists
ansible.builtin.file:
state: absent
path: "{{ path_name }}{{ file_name }}"
delegate_to: localhost
when: data_file_previous.stat.exists

- name: Build Fabric Links
ansible.builtin.template:
src: ndfc_fabric_links.j2
dest: "{{ path_name }}{{ file_name }}"
delegate_to: localhost

- name: Set fabric_links Var default
ansible.builtin.set_fact:
fabric_links: []
delegate_to: localhost

- name: Set fabric_links Var
ansible.builtin.set_fact:
fabric_links: "{{ lookup('file', path_name + file_name) | from_yaml }}"
when: MD_Extended.vxlan.topology.fabric_links | length > 0
delegate_to: localhost

- name: Diff Previous and Current Data Files
cisco.nac_dc_vxlan.dtc.diff_model_changes:
file_name_previous: "{{ path_name }}{{ file_name }}.old"
file_name_current: "{{ path_name }}{{ file_name }}"
register: file_diff_result
delegate_to: localhost

- name: Set File Change Flag Based on File Diff Result
ansible.builtin.set_fact:
changes_detected_fabric_links: true
delegate_to: localhost
when:
- file_diff_result.file_data_changed
- check_roles['save_previous']
83 changes: 83 additions & 0 deletions roles/dtc/common/tasks/common/ndfc_interface_access.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# 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

---

- name: Initialize changes_detected Var
ansible.builtin.set_fact:
changes_detected_interface_access: false
delegate_to: localhost

- name: Set file_name Var
ansible.builtin.set_fact:
file_name: "ndfc_interface_access.yml"
delegate_to: localhost

- name: Stat Previous File If It Exists
ansible.builtin.stat:
path: "{{ path_name }}{{ file_name }}"
register: data_file_previous
delegate_to: localhost

- name: Backup Previous Data File If It Exists
ansible.builtin.copy:
src: "{{ path_name }}{{ file_name }}"
dest: "{{ path_name }}{{ file_name }}.old"
when: data_file_previous.stat.exists

- name: Delete Previous Data File If It Exists
ansible.builtin.file:
state: absent
path: "{{ path_name }}{{ file_name }}"
delegate_to: localhost
when: data_file_previous.stat.exists

- name: Build Interface
ansible.builtin.template:
src: ndfc_interfaces/ndfc_interface_access.j2
dest: "{{ path_name }}{{ file_name }}"
delegate_to: localhost

- name: Set interface_access Var
ansible.builtin.set_fact:
interface_access: []
delegate_to: localhost

- name: Set interface_access Var
ansible.builtin.set_fact:
interface_access: "{{ lookup('file', path_name + file_name) | from_yaml }}"
when: MD_Extended.vxlan.topology.interfaces.modes.access.count > 0
delegate_to: localhost

- name: Diff Previous and Current Data Files
cisco.nac_dc_vxlan.dtc.diff_model_changes:
file_name_previous: "{{ path_name }}{{ file_name }}.old"
file_name_current: "{{ path_name }}{{ file_name }}"
register: file_diff_result
delegate_to: localhost

- name: Set File Change Flag Based on File Diff Result
ansible.builtin.set_fact:
changes_detected_interface_access: true
delegate_to: localhost
when:
- file_diff_result.file_data_changed
- check_roles['save_previous']
Loading

0 comments on commit 57b7636

Please sign in to comment.