Debian Codegraph @

ansible_collections/cisco/intersight/plugins/modules/intersight_switch_control_policy.py

raw
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
5
6 from __future__ import absolute_import, division, print_function
7 __metaclass__ = type
8
9 ANSIBLE_METADATA = {'metadata_version': '1.1',
10 'status': ['preview'],
11 'supported_by': 'community'}
12
13 DOCUMENTATION = r'''
14 ---
15 module: intersight_switch_control_policy
16 short_description: Switch Control Policy configuration for Cisco Intersight
17 description:
18 - Manages Switch Control Policy configuration on Cisco Intersight.
19 - A policy to configure switching modes, VLAN optimization, MAC address aging, and UDLD settings for Cisco Intersight managed fabric interconnects.
20 - For more information see L(Cisco Intersight,https://intersight.com/apidocs/fabric/SwitchControlPolicies/get/).
21 extends_documentation_fragment: intersight
22 options:
23 state:
24 description:
25 - If C(present), will verify the resource is present and will create if needed.
26 - If C(absent), will verify the resource is absent and will delete if needed.
27 type: str
28 choices: [present, absent]
29 default: present
30 organization:
31 description:
32 - The name of the Organization this resource is assigned to.
33 - Profiles and Policies that are created within a Custom Organization are applicable only to devices in the same Organization.
34 type: str
35 default: default
36 name:
37 description:
38 - The name assigned to the Switch Control Policy.
39 - The name must be between 1 and 62 alphanumeric characters, allowing special characters :-_.
40 type: str
41 required: true
42 description:
43 description:
44 - The user-defined description for the Switch Control Policy.
45 - Description can contain letters(a-z, A-Z), numbers(0-9), hyphen(-), period(.), colon(:), or an underscore(_).
46 type: str
47 aliases: [descr]
48 tags:
49 description:
50 - List of tags in Key:<user-defined key> Value:<user-defined value> format.
51 type: list
52 elements: dict
53 ethernet_switching_mode:
54 description:
55 - Enable or Disable Ethernet End Host Switching Mode.
56 - Ethernet End Host Switching Mode is not applicable for Unified Edge; the value defaults to Ethernet Switch Mode.
57 - C(end-host) - Ethernet End Host Switching Mode (default).
58 - C(switch) - Ethernet Switch Mode.
59 type: str
60 choices: [end-host, switch]
61 default: end-host
62 fc_switching_mode:
63 description:
64 - Enable or Disable FC End Host Switching Mode.
65 - FC is not supported on Unified Edge, so this setting cannot be configured and is ignored.
66 - C(end-host) - FC End Host Switching Mode (default).
67 - C(switch) - FC Switch Mode.
68 type: str
69 choices: [end-host, switch]
70 default: end-host
71 vlan_port_optimization_enabled:
72 description:
73 - To enable or disable the VLAN port count optimization.
74 - This feature will always be enabled for Cisco UCS Fabric Interconnect 9108 100G.
75 - Also enabled on the IMM 6.x Bundle version and onwards.
76 - VLAN Port Count Optimization is not applicable for Unified Edge.
77 type: bool
78 default: false
79 reserved_vlan_start_id:
80 description:
81 - The starting ID for VLANs reserved for internal use within the Fabric Interconnect.
82 - This VLAN ID is the starting ID of a contiguous block of 128 VLANs that cannot be configured for user data.
83 - This range of VLANs cannot be configured in VLAN policy.
84 - If this property is not configured, VLAN range 3915 - 4042 is reserved for internal use by default.
85 - The reserved VLAN range is fixed for Unified Edge, so this setting cannot be configured and is ignored.
86 type: int
87 default: 3915
88 mac_aging_option:
89 description:
90 - MAC address aging time configuration option.
91 - C(default) - Use default MAC aging time with UDLD message interval (default).
92 - C(custom) - Use custom MAC aging time in seconds.
93 - C(never) - MAC addresses never age out.
94 type: str
95 choices: [default, custom, never]
96 default: default
97 mac_aging_time:
98 description:
99 - Define the MAC address aging time in seconds.
100 - This field is valid when the C(mac_aging_option) is set to C(custom).
101 - Valid range is 120-918000 seconds.
102 type: int
103 default: 14500
104 message_interval:
105 description:
106 - Configures the time between UDLD probe messages on the UDLD enabled ports.
107 - Valid values are from 7 to 90 seconds.
108 type: int
109 default: 15
110 recovery_action:
111 description:
112 - UDLD recovery action when enabled, attempts to bring an UDLD error-disabled port out of reset.
113 - C(none) - No recovery action (default).
114 - C(reset) - Reset the port to recover from UDLD error-disabled state.
115 type: str
116 choices: [none, reset]
117 default: none
118 fabric_pc_vhba_reset:
119 description:
120 - When enabled, a Registered State Change Notification (RSCN) is sent to the VIC adapter.
121 - This occurs when any member port within the fabric port-channel goes down and vHBA would reset to restore the connection immediately.
122 - When disabled (default), vHBA reset is done only when all the members of a fabric port-channel are down.
123 - Fabric port-channel vHBA reset is not supported on Unified Edge and cannot be enabled.
124 - C(enabled) - Enable fabric port-channel vHBA reset.
125 - C(disabled) - Disable fabric port-channel vHBA reset (default).
126 type: str
127 choices: [enabled, disabled]
128 default: disabled
129 primary_key:
130 description:
131 - Encrypts MACsec keys in type-6 format.
132 - If a MACsec key is already provided in a type-6 format, the primary key decrypts it.
133 - MACSec is not supported on Unified Edge, so the primary key cannot be configured.
134 - Must be 16-64 characters in length when specified.
135 type: str
136 author:
137 - Ron Gershburg (@rgershbu)
138 '''
139
140 EXAMPLES = r'''
141 - name: Create a Switch Control Policy with default settings
142 cisco.intersight.intersight_switch_control_policy:
143 api_private_key: "{{ api_private_key }}"
144 api_key_id: "{{ api_key_id }}"
145 organization: "default"
146 name: "SwitchControl-Policy-01"
147 description: "Switch control policy with default settings"
148 tags:
149 - Key: "Site"
150 Value: "DataCenter-A"
151 state: present
152
153 - name: Create a Switch Control Policy with custom settings
154 cisco.intersight.intersight_switch_control_policy:
155 api_private_key: "{{ api_private_key }}"
156 api_key_id: "{{ api_key_id }}"
157 name: "SwitchControl-Custom-Policy"
158 description: "Switch control policy with custom MAC aging"
159 ethernet_switching_mode: switch
160 fc_switching_mode: switch
161 vlan_port_optimization_enabled: true
162 reserved_vlan_start_id: 3915
163 mac_aging_option: custom
164 mac_aging_time: 14500
165 message_interval: 15
166 recovery_action: reset
167 fabric_pc_vhba_reset: enabled
168 primary_key: "mySecureKey12345"
169 state: present
170
171 - name: Create a Switch Control Policy with end-host mode
172 cisco.intersight.intersight_switch_control_policy:
173 api_private_key: "{{ api_private_key }}"
174 api_key_id: "{{ api_key_id }}"
175 name: "SwitchControl-EndHost-Policy"
176 ethernet_switching_mode: end-host
177 fc_switching_mode: end-host
178 vlan_port_optimization_enabled: false
179 recovery_action: none
180 fabric_pc_vhba_reset: disabled
181 state: present
182
183 - name: Create a Switch Control Policy with never aging MAC addresses
184 cisco.intersight.intersight_switch_control_policy:
185 api_private_key: "{{ api_private_key }}"
186 api_key_id: "{{ api_key_id }}"
187 name: "SwitchControl-NeverAge-Policy"
188 mac_aging_option: never
189 message_interval: 20
190 state: present
191
192 - name: Update a Switch Control Policy
193 cisco.intersight.intersight_switch_control_policy:
194 api_private_key: "{{ api_private_key }}"
195 api_key_id: "{{ api_key_id }}"
196 name: "SwitchControl-Policy-01"
197 description: "Updated switch control policy"
198 ethernet_switching_mode: switch
199 vlan_port_optimization_enabled: true
200 state: present
201
202 - name: Delete a Switch Control Policy
203 cisco.intersight.intersight_switch_control_policy:
204 api_private_key: "{{ api_private_key }}"
205 api_key_id: "{{ api_key_id }}"
206 name: "SwitchControl-Policy-01"
207 state: absent
208 '''
209
210 RETURN = r'''
211 api_response:
212 description: The API response output returned by the specified resource.
213 returned: always
214 type: dict
215 sample:
216 "api_response": {
217 "Name": "SwitchControl-Policy-01",
218 "ObjectType": "fabric.SwitchControlPolicy",
219 "EthernetSwitchingMode": "end-host",
220 "FcSwitchingMode": "end-host",
221 "VlanPortOptimizationEnabled": false,
222 "ReservedVlanStartId": 3915,
223 "MacAgingSettings": {
224 "MacAgingOption": "Default"
225 },
226 "UdldSettings": {
227 "MessageInterval": 15,
228 "RecoveryAction": "none"
229 },
230 "FabricPcVhbaReset": "Disabled",
231 "Tags": [
232 {
233 "Key": "Site",
234 "Value": "DataCenter-A"
235 }
236 ]
237 }
238 '''
239
240 from ansible.module_utils.basic import AnsibleModule
241 from ansible_collections.cisco.intersight.plugins.module_utils.intersight import IntersightModule, intersight_argument_spec
242
243
244 def main():
245 argument_spec = intersight_argument_spec.copy()
246 argument_spec.update(
247 state=dict(type='str', choices=['present', 'absent'], default='present'),
248 organization=dict(type='str', default='default'),
249 name=dict(type='str', required=True),
250 description=dict(type='str', aliases=['descr']),
251 tags=dict(type='list', elements='dict'),
252 ethernet_switching_mode=dict(type='str', choices=['end-host', 'switch'], default='end-host'),
253 fc_switching_mode=dict(type='str', choices=['end-host', 'switch'], default='end-host'),
254 vlan_port_optimization_enabled=dict(type='bool', default=False),
255 reserved_vlan_start_id=dict(type='int', default=3915),
256 mac_aging_option=dict(type='str', choices=['default', 'custom', 'never'], default='default'),
257 mac_aging_time=dict(type='int', default=14500),
258 message_interval=dict(type='int', default=15),
259 recovery_action=dict(type='str', choices=['none', 'reset'], default='none'),
260 fabric_pc_vhba_reset=dict(type='str', choices=['enabled', 'disabled'], default='disabled'),
261 primary_key=dict(type='str', no_log=True)
262 )
263 module = AnsibleModule(
264 argument_spec,
265 supports_check_mode=True
266 )
267
268 intersight = IntersightModule(module)
269 intersight.result['api_response'] = {}
270 intersight.result['trace_id'] = ''
271
272 # Resource path used to configure policy
273 resource_path = '/fabric/SwitchControlPolicies'
274
275 # Define API body used in compares or create
276 intersight.api_body = {
277 'Organization': {
278 'Name': intersight.module.params['organization'],
279 },
280 'Name': intersight.module.params['name'],
281 }
282
283 if intersight.module.params['state'] == 'present':
284 intersight.set_tags_and_description()
285
286 # Convert lowercase choices to API format
287 ethernet_mode = intersight.module.params['ethernet_switching_mode']
288 intersight.api_body['EthernetSwitchingMode'] = ethernet_mode
289
290 fc_mode = intersight.module.params['fc_switching_mode']
291 intersight.api_body['FcSwitchingMode'] = fc_mode
292
293 intersight.api_body['VlanPortOptimizationEnabled'] = intersight.module.params['vlan_port_optimization_enabled']
294 intersight.api_body['ReservedVlanStartId'] = intersight.module.params['reserved_vlan_start_id']
295
296 # Build MacAgingSettings object
297 mac_aging_option = intersight.module.params['mac_aging_option']
298 mac_aging_settings = {
299 'MacAgingOption': mac_aging_option.capitalize()
300 }
301 if mac_aging_option == 'custom':
302 mac_aging_settings['MacAgingTime'] = intersight.module.params['mac_aging_time']
303
304 intersight.api_body['MacAgingSettings'] = mac_aging_settings
305
306 # Build UdldSettings object
307 intersight.api_body['UdldSettings'] = {
308 'MessageInterval': intersight.module.params['message_interval'],
309 'RecoveryAction': intersight.module.params['recovery_action']
310 }
311
312 # Set fabric port-channel vHBA reset
313 fabric_pc_vhba_reset = intersight.module.params['fabric_pc_vhba_reset']
314 intersight.api_body['FabricPcVhbaReset'] = fabric_pc_vhba_reset.capitalize()
315
316 # Set primary key if provided
317 if intersight.module.params.get('primary_key'):
318 intersight.api_body['AesPrimaryKey'] = intersight.module.params['primary_key']
319 else:
320 intersight.api_body['AesPrimaryKey'] = ""
321
322 # Configure the policy
323 intersight.configure_policy_or_profile(resource_path=resource_path)
324
325 module.exit_json(**intersight.result)
326
327
328 if __name__ == '__main__':
329 main()