Skip to content

Commit 0f32945

Browse files
More changes to previous commit
1 parent 478765f commit 0f32945

File tree

13 files changed

+56
-47
lines changed

13 files changed

+56
-47
lines changed

plugins/action/dtc/fabrics_config_save.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424

2525
__metaclass__ = type
2626

27-
2827
from ansible.utils.display import Display
2928
from ansible.plugins.action import ActionBase
3029
from .rest_module_utils import get_rest_module

plugins/action/dtc/fabrics_deploy.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424

2525
__metaclass__ = type
2626

27-
2827
from ansible.utils.display import Display
2928
from ansible.plugins.action import ActionBase
3029
from .rest_module_utils import get_rest_module

plugins/action/dtc/get_poap_data.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
__metaclass__ = type
2626

2727
from ansible.plugins.action import ActionBase
28+
from .rest_module_utils import get_rest_module
2829
import json
2930
import re
3031
import inspect
@@ -139,11 +140,11 @@ def _get_discovered(self, ip, role, hostname):
139140

140141
return discovered
141142

142-
143143
def refresh(self) -> None:
144144
"""
145145
### Summary
146146
Refresh POAP data from NDFC
147+
147148
"""
148149
self.refresh_succeeded = False
149150
self.refresh_message = None

plugins/action/dtc/manage_child_fabric_networks.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424

2525
__metaclass__ = type
2626

27-
2827
from ansible.utils.display import Display
2928
from ansible.plugins.action import ActionBase
3029
from ansible.template import Templar

plugins/action/dtc/manage_child_fabric_vrfs.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424

2525
__metaclass__ = type
2626

27-
2827
from ansible.utils.display import Display
2928
from ansible.plugins.action import ActionBase
3029
from ansible.template import Templar
@@ -55,6 +54,14 @@ def run(self, tmp=None, task_vars=None):
5554

5655
child_fabrics = msite_data['child_fabrics_data']
5756

57+
58+
network_os = task_vars['ansible_network_os']
59+
rest_module = get_rest_module(network_os)
60+
if not rest_module:
61+
results['failed'] = True
62+
results['msg'] = f"Unsupported network_os: {network_os}"
63+
return results
64+
5865
for vrf in vrfs:
5966
vrf_attach_group_switches = [
6067
vrf_attach_group_dict['switches']
@@ -132,7 +139,7 @@ def run(self, tmp=None, task_vars=None):
132139
# return results
133140

134141
ndfc_vrf = self._execute_module(
135-
module_name=task_vars['ansible_network_os_rest'],
142+
module_name=rest_module,
136143
module_args={
137144
"method": "GET",
138145
"path": f"/appcenter/cisco/ndfc/api/v1/lan-fabric/rest/top-down/fabrics/{child_fabric}/vrfs/{vrf['name']}"
@@ -197,7 +204,7 @@ def run(self, tmp=None, task_vars=None):
197204
rendered_to_nice_json = templar.environment.filters['to_nice_json'](rendered_content)
198205

199206
ndfc_vrf_update = self._execute_module(
200-
module_name=task_vars['ansible_network_os_rest'],
207+
module_name=rest_module,
201208
module_args={
202209
"method": "PUT",
203210
"path": f"/appcenter/cisco/ndfc/api/v1/lan-fabric/rest/top-down/fabrics/{child_fabric}/vrfs/{vrf['name']}",

plugins/action/dtc/manage_child_fabrics.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424

2525
__metaclass__ = type
2626

27-
2827
from ansible.utils.display import Display
2928
from ansible.plugins.action import ActionBase
3029
from .rest_module_utils import get_rest_module
@@ -44,11 +43,18 @@ def run(self, tmp=None, task_vars=None):
4443
child_fabrics = self._task.args['child_fabrics']
4544
state = self._task.args['state']
4645

46+
network_os = task_vars['ansible_network_os']
47+
rest_module = get_rest_module(network_os)
48+
if not rest_module:
49+
results['failed'] = True
50+
results['msg'] = f"Unsupported network_os: {network_os}"
51+
return results
52+
4753
if state == 'present':
4854
for fabric in child_fabrics:
4955
json_data = '{"destFabric":"%s","sourceFabric":"%s"}' % (parent_fabric, fabric)
5056
add_fabric_result = self._execute_module(
51-
module_name=task_vars['ansible_network_os_rest'],
57+
module_name=rest_module,
5258
module_args={
5359
"method": "POST",
5460
"path": "/appcenter/cisco/ndfc/api/v1/lan-fabric/rest/control/fabrics/msdAdd",
@@ -77,7 +83,7 @@ def run(self, tmp=None, task_vars=None):
7783
for fabric in child_fabrics:
7884
json_data = '{"destFabric":"%s","sourceFabric":"%s"}' % (parent_fabric, fabric)
7985
remove_fabric_result = self._execute_module(
80-
module_name=task_vars['ansible_network_os_rest'],
86+
module_name=rest_module,
8187
module_args={
8288
"method": "POST",
8389
"path": "/appcenter/cisco/ndfc/api/v1/lan-fabric/rest/control/fabrics/msdExit",

plugins/action/dtc/prepare_msite_child_fabrics_data.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424

2525
__metaclass__ = type
2626

27-
2827
from ansible.utils.display import Display
2928
from ansible.plugins.action import ActionBase
3029
from .rest_module_utils import get_rest_module
@@ -44,10 +43,17 @@ def run(self, tmp=None, task_vars=None):
4443
parent_fabric = self._task.args["parent_fabric"]
4544
child_fabrics = self._task.args["child_fabrics"]
4645

46+
network_os = task_vars['ansible_network_os']
47+
rest_module = get_rest_module(network_os)
48+
if not rest_module:
49+
results['failed'] = True
50+
results['msg'] = f"Unsupported network_os: {network_os}"
51+
return results
52+
4753
# This is actaully not an accurrate API endpoint as it returns all fabrics in NDFC, not just the fabrics associated with MSD
4854
# Therefore, we need to get the fabric associations response and filter out the fabrics that are not associated with the parent fabric (MSD)
4955
msd_fabric_associations = self._execute_module(
50-
module_name=task_vars['ansible_network_os_rest'],
56+
module_name=rest_module,
5157
module_args={
5258
"method": "GET",
5359
"path": "/appcenter/cisco/ndfc/api/v1/lan-fabric/rest/control/fabrics/msd/fabric-associations",

plugins/action/dtc/rest.py

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
from ansible.utils.display import Display
3030
from ansible.plugins.action import ActionBase
31-
31+
from .rest_module_utils import get_rest_module
3232

3333
display = Display()
3434

@@ -38,18 +38,6 @@ class ActionModule(ActionBase):
3838
Action plugin to dynamically select between cisco.nd.nd_rest and cisco.dcnm.dcnm_rest
3939
based on the ansible_network_os variable.
4040
"""
41-
REST_MODULES = {
42-
'cisco.nd.nd': 'cisco.nd.nd_rest',
43-
'cisco.dcnm.dcnm': 'cisco.dcnm.dcnm_rest'
44-
}
45-
46-
def get_rest_module(self, network_os):
47-
if not network_os:
48-
results['failed'] = True
49-
results['msg'] = "ansible_network_os is not defined in task_vars"
50-
else:
51-
results = self.REST_MODULES.get(network_os)
52-
return results
5341

5442
def run(self, tmp=None, task_vars=None):
5543
"""
@@ -75,14 +63,10 @@ def run(self, tmp=None, task_vars=None):
7563
display.vvvv(f"Using OS module: {network_os}")
7664

7765
# Determine which module to use based on network_os
78-
if network_os in self.REST_MODULES:
79-
rest_module = self.get_rest_module(network_os)
80-
else:
66+
rest_module = get_rest_module(network_os)
67+
if not rest_module:
8168
results['failed'] = True
82-
results['msg'] = (
83-
f"Unsupported network_os: {network_os}. "
84-
"Must be 'cisco.nd.nd' or 'cisco.dcnm.dcnm'"
85-
)
69+
results['msg'] = f"Unsupported network_os: {network_os}"
8670
return results
8771

8872
display.vvvv(f"Using ----------REST------------- module: {rest_module}")

plugins/plugin_utils/helper_functions.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
# For example in prepare_serice_model.py we can do the following:
2626
# from ..helper_functions import do_something
2727

28+
from .rest_module_utils import get_rest_module
2829

2930
def data_model_key_check(tested_object, keys):
3031
"""
@@ -96,8 +97,15 @@ def ndfc_get_switch_policy(self, task_vars, tmp, switch_serial_number):
9697
:Raises:
9798
N/A
9899
"""
100+
network_os = task_vars['ansible_network_os']
101+
rest_module = get_rest_module(network_os)
102+
if not rest_module:
103+
results['failed'] = True
104+
results['msg'] = f"Unsupported network_os: {network_os}"
105+
return results
106+
99107
policy_data = self._execute_module(
100-
module_name=task_vars['ansible_network_os_rest'],
108+
module_name=rest_module,
101109
module_args={
102110
"method": "GET",
103111
"path": f"/appcenter/cisco/ndfc/api/v1/lan-fabric/rest/control/policies/switches/{switch_serial_number}/SWITCH/SWITCH"
@@ -182,8 +190,15 @@ def ndfc_get_fabric_attributes(self, task_vars, tmp, fabric):
182190
:Raises:
183191
N/A
184192
"""
193+
network_os = task_vars['ansible_network_os']
194+
rest_module = get_rest_module(network_os)
195+
if not rest_module:
196+
results['failed'] = True
197+
results['msg'] = f"Unsupported network_os: {network_os}"
198+
return results
199+
185200
fabric_response = self._execute_module(
186-
module_name=task_vars['ansible_network_os_rest'],
201+
module_name=rest_module,
187202
module_args={
188203
"method": "GET",
189204
"path": f"/appcenter/cisco/ndfc/api/v1/lan-fabric/rest/control/fabrics/{fabric}",

roles/dtc/create/tasks/external/fabric.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@
2828
- "+ Manage Fabric External {{ MD_Extended.vxlan.fabric.name }}"
2929
- "----------------------------------------------------------------"
3030

31-
- name: Check if fabric External {{ MD_Extended.vxlan.fabric.name }} exists
31+
- name: Check if fabric External {{ MD_Extended.vxlan.fabric.name }} exists in NDFC
3232
cisco.nac_dc_vxlan.dtc.rest:
3333
method: GET
3434
path: "/appcenter/cisco/ndfc/api/v1/lan-fabric/rest/control/fabrics/{{ MD_Extended.vxlan.fabric.name }}"
3535
register: get_result
3636
failed_when: false
3737

38-
- name: Manage fabric External {{ MD_Extended.vxlan.fabric.name }} (PUT)
38+
- name: Manage fabric External {{ MD_Extended.vxlan.fabric.name }} in NDFC (PUT)
3939
cisco.nac_dc_vxlan.dtc.rest:
4040
method: PUT
4141
path: '/appcenter/cisco/ndfc/api/v1/lan-fabric/rest/control/fabrics/{{ MD_Extended.vxlan.fabric.name }}/External_Fabric'
@@ -45,7 +45,7 @@
4545
- get_result.response.DATA
4646
register: put_result
4747

48-
- name: Manage fabric External {{ MD_Extended.vxlan.fabric.name }} (POST)
48+
- name: Manage fabric External {{ MD_Extended.vxlan.fabric.name }} in NDFC (POST)
4949
cisco.nac_dc_vxlan.dtc.rest:
5050
method: POST
5151
path: '/appcenter/cisco/ndfc/api/v1/lan-fabric/rest/control/fabrics/{{ MD_Extended.vxlan.fabric.name }}/External_Fabric'

0 commit comments

Comments
 (0)