@@ -61,8 +61,8 @@ def run(self, tmp=None, task_vars=None):
6161 # Set defaults for management IP addresses, current switch policies, and unmanaged policies
6262 dm_management_ipv4_address = ""
6363 dm_management_ipv6_address = ""
64- # For each switch current_sw_policies will be used to store a list of policies currently associated to the switch
6564 current_sw_policies = []
65+ # For each switch current_sw_policies will be used to store a list of policies currently associated to the switch
6666 # For each switch that has unmanaged policies, the switch IP address and the list of unmanaged policies will be stored
6767 # This default dict is the start of what is required for the NDFC policy module
6868 unmanaged_policies = [
@@ -110,87 +110,87 @@ def run(self, tmp=None, task_vars=None):
110110 )
111111 )
112112
113- # Query NDFC for the current switch's serial number to get back any policy that exists for that switch
114- # with the description prepended with "nac_"
115- ndfc_policies_with_nac_desc = ndfc_get_nac_switch_policy_using_desc (self , task_vars , tmp , ndfc_sw_serial_number )
113+ # Query NDFC for the current switch's serial number to get back any policy that exists for that switch
114+ # with the description prepended with "nac_"
115+ ndfc_policies_with_nac_desc = ndfc_get_nac_switch_policy_using_desc (self , task_vars , tmp , ndfc_sw_serial_number )
116116
117- # Currently, check two things to determine an unmanaged policy:
118- # Check no matching policy in the data model against the policy returned from NDFC for the current switch
119- # This check uses the prepended "nac_"
120- # Additionally, as of now, check no matching policy is from the VRF Lite policy of the data model
121- if any (
122- ((ndfc_policy_with_desc ["description" ] not in current_sw_policies ) and (ndfc_policy_with_desc ["description" ] not in vrf_lites ))
123- for ndfc_policy_with_desc in ndfc_policies_with_nac_desc
124- ):
125- # If found, do the following:
126- # Update Ansible result status
127- # Add the switch to unmanaged_policies payload
128- # Get the last index of where the switch was added
129- # Build specific unmanaged policy entry
130- # Add unmanaged policy entry to last switch added to list
131-
132- # Update Ansible for a configuration change
133- results ['changed' ] = True
134-
135- # Update unmanaged_policies with the IP address of the switch that now has unmanaged policy
136- # The NDFC policy module can take a list of various dictionaries with the switch key previously being pre-stored
137- # Given this, each update the switch element with a new switch entry is the zeroth reference location always in unmanaged_policies
138- # Example:
139- # [
140- # {
141- # "switch": [
142- # {
143- # "ip": <mgmt_ip_address>,
144- # }
145- # ]
146- # }
147- # ]
148- unmanaged_policies [0 ]["switch" ].append (
149- {
150- "ip" : dm_management_ipv4_address if dm_management_ipv4_address else dm_management_ipv6_address
151- }
152- )
117+ # Currently, check two things to determine an unmanaged policy:
118+ # Check no matching policy in the data model against the policy returned from NDFC for the current switch
119+ # This check uses the prepended "nac_"
120+ # Additionally, as of now, check no matching policy is from the VRF Lite policy of the data model
121+ if any (
122+ ((ndfc_policy_with_desc ["description" ] not in current_sw_policies ) and (ndfc_policy_with_desc ["description" ] not in vrf_lites ))
123+ for ndfc_policy_with_desc in ndfc_policies_with_nac_desc
124+ ):
125+ # If found, do the following:
126+ # Update Ansible result status
127+ # Add the switch to unmanaged_policies payload
128+ # Get the last index of where the switch was added
129+ # Build specific unmanaged policy entry
130+ # Add unmanaged policy entry to last switch added to list
131+
132+ # Update Ansible for a configuration change
133+ results ['changed' ] = True
134+
135+ # Update unmanaged_policies with the IP address of the switch that now has unmanaged policy
136+ # The NDFC policy module can take a list of various dictionaries with the switch key previously being pre-stored
137+ # Given this, each update the switch element with a new switch entry is the zeroth reference location always in unmanaged_policies
138+ # Example:
139+ # [
140+ # {
141+ # "switch": [
142+ # {
143+ # "ip": <mgmt_ip_address>,
144+ # }
145+ # ]
146+ # }
147+ # ]
148+ unmanaged_policies [0 ]["switch" ].append (
149+ {
150+ "ip" : dm_management_ipv4_address if dm_management_ipv4_address else dm_management_ipv6_address
151+ }
152+ )
153153
154- # Grab the last index of a switch added
155- last_idx = len (unmanaged_policies [0 ]["switch" ]) - 1
156-
157- # Since initially found there is indeed an unmananged policy, build a list of unmanaged policy
158- _unmanaged_policies = [
159- {
160- "name" : ndfc_policy_with_desc ["policyId" ],
161- "description" : ndfc_policy_with_desc ["description" ]
162- }
163- for ndfc_policy_with_desc in ndfc_policies_with_nac_desc
164- if ((ndfc_policy_with_desc ["description" ] not in current_sw_policies ) and (ndfc_policy_with_desc ["description" ] not in vrf_lites ))
165- ]
166-
167- # Update the dictionary entry for the last switch with the expected policies key the NDFC policy module expects
168- unmanaged_policies [0 ]["switch" ][last_idx ].update (
169- {
170- "policies" : _unmanaged_policies
171- }
172- )
154+ # Grab the last index of a switch added
155+ last_idx = len (unmanaged_policies [0 ]["switch" ]) - 1
156+
157+ # Since initially found there is indeed an unmananged policy, build a list of unmanaged policy
158+ _unmanaged_policies = [
159+ {
160+ "name" : ndfc_policy_with_desc ["policyId" ],
161+ "description" : ndfc_policy_with_desc ["description" ]
162+ }
163+ for ndfc_policy_with_desc in ndfc_policies_with_nac_desc
164+ if ((ndfc_policy_with_desc ["description" ] not in current_sw_policies ) and (ndfc_policy_with_desc ["description" ] not in vrf_lites ))
165+ ]
166+
167+ # Update the dictionary entry for the last switch with the expected policies key the NDFC policy module expects
168+ unmanaged_policies [0 ]["switch" ][last_idx ].update (
169+ {
170+ "policies" : _unmanaged_policies
171+ }
172+ )
173173
174- # Example of unmanaged policy payload:
175- # [
176- # {
177- # "switch": [
178- # {
179- # "ip": '<ip_address>',
180- # "policies": [
181- # {
182- # "name": <Policy ID>,
183- # "description": "nac_<description>"
184- # },
185- # {
186- # "name": <Policy ID>,
187- # "description": "nac_<description>"
188- # },
189- # ]
190- # },
191- # ]
192- # }
193- # ]
174+ # Example of unmanaged policy payload:
175+ # [
176+ # {
177+ # "switch": [
178+ # {
179+ # "ip": '<ip_address>',
180+ # "policies": [
181+ # {
182+ # "name": <Policy ID>,
183+ # "description": "nac_<description>"
184+ # },
185+ # {
186+ # "name": <Policy ID>,
187+ # "description": "nac_<description>"
188+ # },
189+ # ]
190+ # },
191+ # ]
192+ # }
193+ # ]
194194
195195 # Store the unmanaged policy payload for return and usage in the NDFC policy module to delete from NDFC
196196 results ['unmanaged_policies' ] = unmanaged_policies
0 commit comments