Skip to content

Commit d33a7d2

Browse files
authored
Merge pull request #35 from cisco-en-programmability/sda_extranet_policy_bug_fix
Extranet Policies Module Bug Fix
2 parents 9551636 + 4893548 commit d33a7d2

3 files changed

Lines changed: 183 additions & 78 deletions

File tree

plugins/modules/sda_extranet_policies_workflow_manager.py

Lines changed: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from __future__ import absolute_import, division, print_function
77

88
__metaclass__ = type
9-
__author__ = "Rugvedi Kapse, Madhan Sankaranarayanan, Archit Soni"
9+
__author__ = "Rugvedi Kapse, Madhan Sankaranarayanan, Archit Soni, Sunil Shatagopa"
1010
DOCUMENTATION = r"""
1111
---
1212
module: sda_extranet_policies_workflow_manager
@@ -25,8 +25,11 @@
2525
version_added: "6.17.0"
2626
extends_documentation_fragment:
2727
- cisco.catalystcenter.workflow_manager_params
28-
author: Rugvedi Kapse (@rukapse) Madhan Sankaranarayanan
29-
(@madhansansel) Archit Soni (@koderchit)
28+
author:
29+
- Rugvedi Kapse (@rukapse)
30+
- Madhan Sankaranarayanan (@madhansansel)
31+
- Archit Soni (@koderchit)
32+
- Sunil Shatagopa (@shatagopasunil)
3033
options:
3134
config_verify:
3235
description: Set to True to verify the Cisco Catalyst
@@ -70,7 +73,9 @@
7073
Providers having overlapping routes, traffic
7174
will be load-balanced across those Provider
7275
Virtual Networks.
73-
- Required for creating or updating the policy.
76+
- Required for creating the policy. Optional
77+
for updating; if not provided, the existing
78+
value from Cisco Catalyst Center is used.
7479
- Updating this field is not allowed.
7580
type: str
7681
subscriber_virtual_networks:
@@ -80,7 +85,9 @@
8085
Network containing shared services resources.
8186
- A Virtual Network previously defined as
8287
a Provider cannot be selected as a subscriber.
83-
- Required for creating or updating the policy.
88+
- Required for creating the policy. Optional
89+
for updating; if not provided, the existing
90+
value from Cisco Catalyst Center is used.
8491
- Can be modified.
8592
- Example - ["VN_2", "VN_4"]
8693
type: list
@@ -153,7 +160,7 @@
153160
- extranet_policy_name: "test_extranet_policy_1"
154161
provider_virtual_network: "VN_1"
155162
subscriber_virtual_networks: ["VN_2", "VN_3"]
156-
fabric_sites: ["Global/Test_Extranet_Polcies/USA", "Global/Test_Extranet_Polcies/India"]
163+
fabric_sites: ["Global/Test_Extranet_Policies/USA", "Global/Test_Extranet_Policies/India"]
157164
- name: Update existing Extranet Policy
158165
cisco.catalystcenter.sda_extranet_policies_workflow_manager:
159166
catalystcenter_host: "{{catalystcenter_host}}"
@@ -185,7 +192,7 @@
185192
state: merged
186193
config:
187194
- extranet_policy_name: "test_extranet_policy_1"
188-
fabric_sites: ["Global/Test_Extranet_Polcies/USA", "Global/Test_Extranet_Polcies/India"]
195+
fabric_sites: ["Global/Test_Extranet_Policies/USA", "Global/Test_Extranet_Policies/India"]
189196
provider_virtual_network: "VN_1"
190197
subscriber_virtual_networks: ["VN_2", "VN_4"]
191198
- name: Delete Extranet Policy
@@ -337,7 +344,7 @@ def get_fabric_ids_list(self, site_details):
337344
def validate_merged_parameters(self, config):
338345
"""
339346
Validate that the required parameters are present in the configuration for performing
340-
Add or Update Extranet Policy operations.
347+
Add Extranet Policy operations.
341348
Parameters:
342349
- config (dict): A dictionary containing the configuration parameters to be validated.
343350
Returns:
@@ -348,14 +355,17 @@ def validate_merged_parameters(self, config):
348355
'provider_virtual_network' and 'subscriber_virtual_networks'. If any of these parameters
349356
are missing, it logs an error message and raises an exception to halt execution. If all
350357
required parameters are present, it logs a success message indicating successful validation.
358+
Note: This validation is only invoked for create operations. For update operations,
359+
these parameters are optional as missing values are populated from the existing
360+
policy in Cisco Catalyst Center.
351361
"""
352362
# Check for provider_virtual_network
353363
provider_virtual_network = config.get("provider_virtual_network")
354364
if provider_virtual_network is None:
355365
msg = (
356366
"Missing required parameter: 'provider_virtual_network'. "
357367
"(extranet_policy_name, provider_virtual_network, and subscriber_virtual_networks) - "
358-
"are the required parameters for performing Add or Update Extranet Policy operations."
368+
"are the required parameters for performing Add Extranet Policy operations."
359369
)
360370
self.log(msg, "ERROR")
361371
self.module.fail_json(msg)
@@ -366,7 +376,7 @@ def validate_merged_parameters(self, config):
366376
msg = (
367377
"Missing required parameter: 'subscriber_virtual_networks'. "
368378
"(extranet_policy_name, provider_virtual_network, and subscriber_virtual_networks) - "
369-
"are the required parameters for performing Add or Update Extranet Policy operations."
379+
"are the required parameters for performing Add Extranet Policy operations."
370380
)
371381
self.log(msg, "ERROR")
372382
self.module.fail_json(msg)
@@ -988,7 +998,6 @@ def get_want(self, config, state):
988998
extranet_policy_details = self.have.get("current_extranet_policy")
989999

9901000
if state == "merged":
991-
self.validate_merged_parameters(config)
9921001
fabric_sites = config.get("fabric_sites")
9931002
if fabric_sites:
9941003
self.log(
@@ -1007,6 +1016,24 @@ def get_want(self, config, state):
10071016
site_details = self.get_fabric_sites_ids(site_details)
10081017

10091018
if extranet_policy_exists:
1019+
# For update operations, fill in missing parameters from the existing policy
1020+
if config.get("provider_virtual_network") is None:
1021+
config["provider_virtual_network"] = extranet_policy_details.get("providerVirtualNetworkName")
1022+
self.log(
1023+
"Using existing 'provider_virtual_network': '{0}' from Cisco Catalyst Center.".format(
1024+
config["provider_virtual_network"]
1025+
),
1026+
"INFO",
1027+
)
1028+
if config.get("subscriber_virtual_networks") is None:
1029+
config["subscriber_virtual_networks"] = extranet_policy_details.get("subscriberVirtualNetworkNames")
1030+
self.log(
1031+
"Using existing 'subscriber_virtual_networks': '{0}' from Cisco Catalyst Center.".format(
1032+
config["subscriber_virtual_networks"]
1033+
),
1034+
"INFO",
1035+
)
1036+
10101037
self.log(
10111038
"Extranet Policy - '{0}' exists in the Cisco Catalyst Center, "
10121039
"therefore setting 'update_extranet_policy_params'.".format(
@@ -1033,6 +1060,7 @@ def get_want(self, config, state):
10331060
self.status = "success"
10341061
return self
10351062
else:
1063+
self.validate_merged_parameters(config)
10361064
self.log(
10371065
"Extranet Policy - '{0}' does not exist in the Cisco Catalyst Center, "
10381066
"therefore setting 'add_extranet_policy_params'.".format(
Lines changed: 106 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,122 +1,161 @@
11
{
2-
"playbook_config_create_sda_extranet_policies":[
2+
"playbook_config_create_sda_extranet_policies": [
33
{
4-
"extranet_policy_name":"extranet_policy_1",
5-
"fabric_sites":[
4+
"extranet_policy_name": "extranet_policy_1",
5+
"fabric_sites": [
66
"Global/USA/San Jose/BLDG_23"
77
],
8-
"provider_virtual_network":"L3VN1",
9-
"subscriber_virtual_networks":[
8+
"provider_virtual_network": "L3VN1",
9+
"subscriber_virtual_networks": [
1010
"VN_PROV_10",
1111
"VN_PROV_11",
1212
"VN_PROV_12"
1313
]
1414
}
1515
],
16-
"playbook_config_update_sda_extranet_policies":[
16+
"playbook_config_update_sda_extranet_policies": [
1717
{
18-
"extranet_policy_name":"extranet_policy_1",
19-
"fabric_sites":[
18+
"extranet_policy_name": "extranet_policy_1",
19+
"fabric_sites": [
2020
"Global/USA/San Jose/BLDG23"
2121
],
22-
"provider_virtual_network":"L3VN1",
23-
"subscriber_virtual_networks":[
22+
"provider_virtual_network": "L3VN1",
23+
"subscriber_virtual_networks": [
2424
"VN_PROV_13",
2525
"VN_PROV_14",
2626
"VN_PROV_15"
2727
]
2828
}
2929
],
30-
"playbook_config_delete_sda_extranet_policies":[
30+
"playbook_config_delete_sda_extranet_policies": [
3131
{
32-
"extranet_policy_name":"extranet_policy_1"
32+
"extranet_policy_name": "extranet_policy_1"
3333
}
3434
],
35-
"response_get_sites":{
36-
"response":[
35+
"response_get_sites": {
36+
"response": [
3737
{
38-
"id":"5a9bb391-fb8f-47a5-8dd9-31c6fa7d8289",
39-
"parentId":"19ef7e22-457d-4bc8-ab7d-4446f9fb196c",
40-
"name":"BLDG23",
41-
"nameHierarchy":"Global/USA/San Jose/BLDG23",
42-
"type":"building",
43-
"latitude":37.41864,
44-
"longitude":-121.9193,
45-
"address":"Cisco - Building 23, 560 McCarthy Blvd, Milpitas, California 95035, United States",
46-
"country":"United States"
38+
"id": "5a9bb391-fb8f-47a5-8dd9-31c6fa7d8289",
39+
"parentId": "19ef7e22-457d-4bc8-ab7d-4446f9fb196c",
40+
"name": "BLDG23",
41+
"nameHierarchy": "Global/USA/San Jose/BLDG23",
42+
"type": "building",
43+
"latitude": 37.41864,
44+
"longitude": -121.9193,
45+
"address": "Cisco - Building 23, 560 McCarthy Blvd, Milpitas, California 95035, United States",
46+
"country": "United States"
4747
}
4848
],
49-
"version":"1.0"
49+
"version": "1.0"
5050
},
51-
"response_get_fabric_sites":{
52-
"response":[
51+
"response_get_fabric_sites": {
52+
"response": [
5353
{
54-
"id":"b6af9074-b1d8-4b40-82f9-776d34adb0fc",
55-
"siteId":"5a9bb391-fb8f-47a5-8dd9-31c6fa7d8289",
56-
"authenticationProfileName":"No Authentication",
57-
"isPubSubEnabled":false
54+
"id": "b6af9074-b1d8-4b40-82f9-776d34adb0fc",
55+
"siteId": "5a9bb391-fb8f-47a5-8dd9-31c6fa7d8289",
56+
"authenticationProfileName": "No Authentication",
57+
"isPubSubEnabled": false
5858
}
5959
],
60-
"version":"1.0"
60+
"version": "1.0"
6161
},
62-
"response_get_extranet_policies_1":{
63-
"response":[
64-
65-
],
66-
"version":"1.0"
62+
"response_get_extranet_policies_1": {
63+
"response": [],
64+
"version": "1.0"
6765
},
68-
"response_get_task_id":{
69-
"response":{
70-
"taskId":"0195ff77-c942-7b58-b171-69f32b82e11b",
71-
"url":"/dna/intent/api/v1/task/0195ff77-c942-7b58-b171-69f32b82e11b"
66+
"response_get_task_id": {
67+
"response": {
68+
"taskId": "0195ff77-c942-7b58-b171-69f32b82e11b",
69+
"url": "/dna/intent/api/v1/task/0195ff77-c942-7b58-b171-69f32b82e11b"
7270
},
73-
"version":"1.0"
71+
"version": "1.0"
7472
},
75-
"response_get_task_status_by_id":{
76-
"response":{
77-
"endTime":1743747798480,
78-
"lastUpdate":1743747796510,
79-
"status":"SUCCESS",
80-
"startTime":1743747795266,
81-
"resultLocation":"/dna/intent/api/v1/tasks/0195ff77-c942-7b58-b171-69f32b82e11b/detail",
82-
"id":"0195ff77-c942-7b58-b171-69f32b82e11b"
73+
"response_get_task_status_by_id": {
74+
"response": {
75+
"endTime": 1743747798480,
76+
"lastUpdate": 1743747796510,
77+
"status": "SUCCESS",
78+
"startTime": 1743747795266,
79+
"resultLocation": "/dna/intent/api/v1/tasks/0195ff77-c942-7b58-b171-69f32b82e11b/detail",
80+
"id": "0195ff77-c942-7b58-b171-69f32b82e11b"
8381
},
84-
"version":"1.0"
82+
"version": "1.0"
8583
},
86-
"response_get_extranet_policies_2":{
87-
"response":[
84+
"response_get_extranet_policies_2": {
85+
"response": [
8886
{
89-
"id":"098ab4d3-d9fe-46cc-a3b8-4f2405d4da1e",
90-
"extranetPolicyName":"extranet_policy_1",
91-
"fabricIds":[
87+
"id": "098ab4d3-d9fe-46cc-a3b8-4f2405d4da1e",
88+
"extranetPolicyName": "extranet_policy_1",
89+
"fabricIds": [
9290
"b6af9074-b1d8-4b40-82f9-776d34adb0fc"
9391
],
94-
"providerVirtualNetworkName":"L3VN1",
95-
"subscriberVirtualNetworkNames":[
92+
"providerVirtualNetworkName": "L3VN1",
93+
"subscriberVirtualNetworkNames": [
9694
"VN_PROV_12",
9795
"VN_PROV_10",
9896
"VN_PROV_11"
9997
]
10098
}
10199
],
102-
"version":"1.0"
100+
"version": "1.0"
103101
},
104-
"response_get_extranet_policies_3":{
105-
"response":[
102+
"response_get_extranet_policies_3": {
103+
"response": [
106104
{
107-
"id":"098ab4d3-d9fe-46cc-a3b8-4f2405d4da1e",
108-
"extranetPolicyName":"extranet_policy_1",
109-
"fabricIds":[
105+
"id": "098ab4d3-d9fe-46cc-a3b8-4f2405d4da1e",
106+
"extranetPolicyName": "extranet_policy_1",
107+
"fabricIds": [
110108
"b6af9074-b1d8-4b40-82f9-776d34adb0fc"
111109
],
112-
"providerVirtualNetworkName":"L3VN1",
113-
"subscriberVirtualNetworkNames":[
110+
"providerVirtualNetworkName": "L3VN1",
111+
"subscriberVirtualNetworkNames": [
114112
"VN_PROV_14",
115113
"VN_PROV_15",
116114
"VN_PROV_13"
117115
]
118116
}
119117
],
120-
"version":"1.0"
118+
"version": "1.0"
119+
},
120+
"playbook_config_update_extranet_policy_partial": [
121+
{
122+
"extranet_policy_name": "corp_extranet_policy_01",
123+
"fabric_sites": [
124+
"Global/USA/San Jose/BLDG23"
125+
],
126+
"subscriber_virtual_networks": [
127+
"SUBSCRIBER_VN_A"
128+
]
129+
}
130+
],
131+
"response_get_extranet_policies_partial_existing": {
132+
"response": [
133+
{
134+
"id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
135+
"extranetPolicyName": "corp_extranet_policy_01",
136+
"fabricIds": [],
137+
"providerVirtualNetworkName": "PROVIDER_VN_CORE",
138+
"subscriberVirtualNetworkNames": [
139+
"SUBSCRIBER_VN_B"
140+
]
141+
}
142+
],
143+
"version": "1.0"
144+
},
145+
"response_get_extranet_policies_partial_updated": {
146+
"response": [
147+
{
148+
"id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
149+
"extranetPolicyName": "corp_extranet_policy_01",
150+
"fabricIds": [
151+
"b6af9074-b1d8-4b40-82f9-776d34adb0fc"
152+
],
153+
"providerVirtualNetworkName": "PROVIDER_VN_CORE",
154+
"subscriberVirtualNetworkNames": [
155+
"SUBSCRIBER_VN_A"
156+
]
157+
}
158+
],
159+
"version": "1.0"
121160
}
122-
}
161+
}

0 commit comments

Comments
 (0)