Skip to content

Commit 8fe41f7

Browse files
authored
Policy create, update, delete operations (#51)
1 parent c4bbcdb commit 8fe41f7

File tree

8 files changed

+848
-1
lines changed

8 files changed

+848
-1
lines changed

.ansible-lint

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ mock_modules:
4949
- cisco.catalystwan.config_groups
5050
- cisco.catalystwan.config_group_deployment
5151
- cisco.catalystwan.feature_profile_builder
52+
- cisco.catalystwan.policy
5253
# - zuul_return
5354
# # note the foo.bar is invalid as being neither a module or a collection
5455
# - fake_namespace.fake_collection.fake_module
Lines changed: 244 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,244 @@
1+
# Copyright 2024 Cisco Systems, Inc. and its affiliates
2+
# GNU General Public License v3.0+ (see LICENSE or https://www.gnu.org/licenses/gpl-3.0.txt)
3+
4+
---
5+
6+
# Helper playbooks to test modules and flows while developing them
7+
8+
# Tested operations:
9+
10+
# 0. Delete leftover objects
11+
# 1. Create Policy list
12+
# 2. Create already existing Policy list (should return not changed)
13+
# 3. Update Policy list
14+
# 4. Create Policy definition
15+
# 5. Update Policy definition
16+
# 6. Create centralized policy
17+
# 7. Activate centralized policy
18+
# 8. Create localized policy
19+
# 9. Delete all created objects
20+
21+
- name: Testing playbook to verify cisco.catalystwan.device_templates module operations
22+
hosts: localhost
23+
gather_facts: false
24+
vars_files:
25+
- configuration_file_dev_vars.yml
26+
vars:
27+
manager_authentication: &manager_authentication
28+
url: "{{ (vmanage_instances | first).mgmt_public_ip }}"
29+
username: "{{ (vmanage_instances | first).admin_username }}"
30+
password: "{{ (vmanage_instances | first).admin_password }}"
31+
32+
tasks:
33+
- name: Delete pre existing centralized policy
34+
cisco.catalystwan.policy:
35+
name: test_centralized_policy
36+
centralized:
37+
type: feature
38+
state: absent
39+
manager_credentials:
40+
<<: *manager_authentication
41+
42+
- name: Delete pre existing localized policy
43+
cisco.catalystwan.policy:
44+
name: test_localized_policy
45+
localized:
46+
type: feature
47+
state: absent
48+
manager_credentials:
49+
<<: *manager_authentication
50+
51+
- name: Delete pre existing policy definitions
52+
cisco.catalystwan.policy:
53+
name: test_hub_and_spoke_policy
54+
definition:
55+
type: "hub_and_spoke"
56+
state: absent
57+
manager_credentials:
58+
<<: *manager_authentication
59+
60+
- name: Delete pre existing policy lists
61+
cisco.catalystwan.policy:
62+
name: "{{ item['name'] }}"
63+
list:
64+
type: "{{ item['type'] }}"
65+
state: absent
66+
manager_credentials:
67+
<<: *manager_authentication
68+
loop:
69+
- name: test_vpn_list
70+
type: vpn
71+
- name: test_hub_list
72+
type: site
73+
- name: test_spoke_list
74+
type: site
75+
76+
- name: Create VPN list
77+
cisco.catalystwan.policy:
78+
name: test_vpn_list
79+
list:
80+
type: "vpn"
81+
entries:
82+
- vpn: 100
83+
manager_credentials:
84+
<<: *manager_authentication
85+
register: result_vpn_list
86+
87+
- name: Create existing VPN list again
88+
cisco.catalystwan.policy:
89+
name: test_vpn_list
90+
list:
91+
type: "vpn"
92+
entries:
93+
- vpn: 100
94+
manager_credentials:
95+
<<: *manager_authentication
96+
register: result_vpn_list
97+
failed_when: result_vpn_list['changed']
98+
99+
- name: Update VPN list
100+
cisco.catalystwan.policy:
101+
name: test_vpn_list
102+
list:
103+
type: "vpn"
104+
entries:
105+
- vpn: 101
106+
manager_credentials:
107+
<<: *manager_authentication
108+
register: result_vpn_list
109+
failed_when: not result_vpn_list['changed'] or "updated" not in result_vpn_list['msg']
110+
111+
- name: Create HUB list
112+
cisco.catalystwan.policy:
113+
name: test_hub_list
114+
list:
115+
type: "site"
116+
entries:
117+
- site_id: "100"
118+
manager_credentials:
119+
<<: *manager_authentication
120+
register: result_hub_list
121+
122+
- name: Create SPOKE list
123+
cisco.catalystwan.policy:
124+
name: test_spoke_list
125+
list:
126+
type: "site"
127+
entries:
128+
- site_id: "1001"
129+
manager_credentials:
130+
<<: *manager_authentication
131+
register: result_spoke_list
132+
133+
- name: Create hub and spoke policy
134+
cisco.catalystwan.policy:
135+
name: test_hub_and_spoke_policy
136+
definition:
137+
type: "hub_and_spoke"
138+
definition:
139+
vpnList: "{{ result_vpn_list['id'] }}"
140+
subDefinitions:
141+
- name: "My Hub-and-Spoke"
142+
equalPreference: true
143+
advertiseTloc: false
144+
spokes:
145+
- siteList: "{{ result_spoke_list['id'] }}"
146+
hubs:
147+
- siteList: "{{ result_spoke_list['id'] }}"
148+
manager_credentials:
149+
<<: *manager_authentication
150+
register: result_hub_and_spoke_policy
151+
152+
- name: Update hub and spoke policy
153+
cisco.catalystwan.policy:
154+
name: test_hub_and_spoke_policy
155+
definition:
156+
type: "hub_and_spoke"
157+
definition:
158+
vpnList: "{{ result_vpn_list['id'] }}"
159+
subDefinitions:
160+
- name: "My Hub-and-Spoke"
161+
equalPreference: true
162+
advertiseTloc: false
163+
spokes:
164+
- siteList: "{{ result_spoke_list['id'] }}"
165+
hubs:
166+
- siteList: "{{ result_hub_list['id'] }}"
167+
manager_credentials:
168+
<<: *manager_authentication
169+
register: result_hub_and_spoke_policy
170+
171+
- name: Create centralized policy
172+
cisco.catalystwan.policy:
173+
name: test_centralized_policy
174+
centralized:
175+
definition:
176+
assembly:
177+
- definitionId: "{{ result_hub_and_spoke_policy['id'] }}"
178+
type: "hubAndSpoke"
179+
manager_credentials:
180+
<<: *manager_authentication
181+
182+
- name: Activate centralized policy
183+
cisco.catalystwan.policy:
184+
state: active
185+
name: test_centralized_policy
186+
centralized:
187+
definition:
188+
assembly:
189+
- definitionId: "{{ result_hub_and_spoke_policy['id'] }}"
190+
type: "hubAndSpoke"
191+
manager_credentials:
192+
<<: *manager_authentication
193+
194+
- name: Create localized policy
195+
cisco.catalystwan.policy:
196+
name: test_localized_policy
197+
localized:
198+
definition:
199+
assembly: []
200+
manager_credentials:
201+
<<: *manager_authentication
202+
203+
- name: Delete centralized policy
204+
cisco.catalystwan.policy:
205+
name: test_centralized_policy
206+
centralized:
207+
type: feature
208+
state: absent
209+
manager_credentials:
210+
<<: *manager_authentication
211+
212+
- name: Delete localized policy
213+
cisco.catalystwan.policy:
214+
name: test_localized_policy
215+
localized:
216+
type: feature
217+
state: absent
218+
manager_credentials:
219+
<<: *manager_authentication
220+
221+
- name: Delete policy definitions
222+
cisco.catalystwan.policy:
223+
name: test_hub_and_spoke_policy
224+
definition:
225+
type: "hub_and_spoke"
226+
state: absent
227+
manager_credentials:
228+
<<: *manager_authentication
229+
230+
- name: Delete policy lists
231+
cisco.catalystwan.policy:
232+
name: "{{ item['name'] }}"
233+
list:
234+
type: "{{ item['type'] }}"
235+
state: absent
236+
manager_credentials:
237+
<<: *manager_authentication
238+
loop:
239+
- name: test_vpn_list
240+
type: vpn
241+
- name: test_hub_list
242+
type: site
243+
- name: test_spoke_list
244+
type: site
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
policy_centralized_definition = {
2+
"centralized": {
3+
"default": None,
4+
"required": False,
5+
"type": "dict",
6+
"options": {
7+
"type": {
8+
"type": "str",
9+
"choices": ["feature", "cli"],
10+
"default": "feature",
11+
},
12+
"definition": {"type": "dict"},
13+
},
14+
}
15+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
from typing import Mapping
2+
3+
from catalystwan.models.policy import (
4+
AclIPv6Policy,
5+
AclPolicy,
6+
AdvancedInspectionProfilePolicy,
7+
AdvancedMalwareProtectionPolicy,
8+
CflowdPolicy,
9+
ControlPolicy,
10+
DeviceAccessIPv6Policy,
11+
DeviceAccessPolicy,
12+
DnsSecurityPolicy,
13+
HubAndSpokePolicy,
14+
IntrusionPreventionPolicy,
15+
MeshPolicy,
16+
QoSMapPolicy,
17+
RewritePolicy,
18+
RoutePolicy,
19+
RuleSet,
20+
SecurityGroup,
21+
SslDecryptionPolicy,
22+
SslDecryptionUtdProfilePolicy,
23+
TrafficDataPolicy,
24+
UrlFilteringPolicy,
25+
VPNMembershipPolicy,
26+
ZoneBasedFWPolicy,
27+
)
28+
29+
policy_definition_type_mapping: Mapping[str, type] = {
30+
"access_control_list": AclPolicy,
31+
"access_control_policy_ipv6": AclIPv6Policy,
32+
"aip": AdvancedInspectionProfilePolicy,
33+
"amp": AdvancedMalwareProtectionPolicy,
34+
"cflowd": CflowdPolicy,
35+
"control": ControlPolicy,
36+
"device_access": DeviceAccessPolicy,
37+
"device_access_ipv6": DeviceAccessIPv6Policy,
38+
"dns_security": DnsSecurityPolicy,
39+
"hub_and_spoke": HubAndSpokePolicy,
40+
"intrusion_prevention": IntrusionPreventionPolicy,
41+
"mesh": MeshPolicy,
42+
"qos_map": QoSMapPolicy,
43+
"rewrite": RewritePolicy,
44+
"route_policy": RoutePolicy,
45+
"rule_set": RuleSet,
46+
"security_group": SecurityGroup,
47+
"ssl_decryption": SslDecryptionPolicy,
48+
"ssl_decryption_utd_profile": SslDecryptionUtdProfilePolicy,
49+
"traffic_data": TrafficDataPolicy,
50+
"url_filtering": UrlFilteringPolicy,
51+
"vpn_membership": VPNMembershipPolicy,
52+
"zone_based_firewall": ZoneBasedFWPolicy,
53+
}
54+
55+
policy_definition_definition = {
56+
"definition": {
57+
"default": None,
58+
"required": False,
59+
"type": "dict",
60+
"options": {
61+
"type": {
62+
"type": "str",
63+
"choices": policy_definition_type_mapping.keys(),
64+
"default": "feature",
65+
},
66+
"definition": {"type": "dict"},
67+
},
68+
}
69+
}

0 commit comments

Comments
 (0)