Debian Codegraph @

ansible_collections/cisco/intersight/plugins/modules/intersight_san_connectivity_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_san_connectivity_policy
16 short_description: Manage SAN Connectivity Policies and vHBAs for Cisco Intersight
17 description:
18 - Create, update, and delete SAN Connectivity Policies on Cisco Intersight.
19 - Manage individual vHBAs (virtual Host Bus Adapters) within SAN Connectivity policies.
20 - Supports Standalone and FIAttached target platforms with different configuration options.
21 - Note SAN Connectivity policies are not supported on Unified Edge Servers.
22 - SAN Connectivity policies define storage connectivity settings for server profiles.
23 - For more information see L(Cisco Intersight,https://intersight.com/apidocs/vnic/SanConnectivityPolicy/get/).
24 extends_documentation_fragment: intersight
25 options:
26 state:
27 description:
28 - If C(present), will verify the resource is present and will create if needed.
29 - If C(absent), will verify the resource is absent and will delete if needed.
30 type: str
31 choices: [present, absent]
32 default: present
33 organization:
34 description:
35 - The name of the Organization this resource is assigned to.
36 - Policies created within a Custom Organization are applicable only to devices in the same Organization.
37 - Use 'default' for the default organization.
38 type: str
39 default: default
40 name:
41 description:
42 - The name assigned to the SAN Connectivity Policy.
43 - Must be unique within the organization.
44 - The name must be between 1 and 62 alphanumeric characters, allowing special characters :-_.
45 type: str
46 required: true
47 description:
48 description:
49 - The user-defined description for the SAN Connectivity Policy.
50 - Description can contain letters(a-z, A-Z), numbers(0-9), hyphen(-), period(.), colon(:), or an underscore(_).
51 type: str
52 aliases: [descr]
53 tags:
54 description:
55 - List of tags in Key:<user-defined key> Value:<user-defined value> format.
56 type: list
57 elements: dict
58 target_platform:
59 description:
60 - The platform type for which the SAN Connectivity policy is intended.
61 - C(Standalone) for Standalone servers.
62 - C(FIAttached) for fabric interconnect attached servers.
63 - Note SAN Connectivity policies are not supported on unified edge servers.
64 type: str
65 choices: ['Standalone', 'FIAttached']
66 default: 'Standalone'
67 placement_mode:
68 description:
69 - The mode used for placement of vHBAs on network adapters.
70 - C(custom) requires manual placement specification for each vHBA.
71 - C(auto) automatically distributes vHBAs between adapters during profile deployment.
72 - Only applicable for FIAttached target platform.
73 type: str
74 choices: ['custom', 'auto']
75 default: 'custom'
76 wwnn_address_type:
77 description:
78 - Type of WWNN address assignment.
79 - C(pool) to use a WWNN pool.
80 - C(static) to manually assign a static WWNN address.
81 - Only applicable when target_platform is FIAttached.
82 type: str
83 choices: ['pool', 'static']
84 default: 'pool'
85 wwnn_pool:
86 description:
87 - The WWNN pool that is assigned for WWNN address assignment.
88 - Required when wwnn_address_type is pool and target platform is FIAttached.
89 - Only applicable for FIAttached target platform.
90 type: str
91 static_wwnn_address:
92 description:
93 - The WWNN address for the server node must be in hexadecimal format xx:xx:xx:xx:xx:xx:xx:xx.
94 - Allowed ranges are 20:00:00:00:00:00:00:00 to 20:FF:FF:FF:FF:FF:FF:FF or from 50:00:00:00:00:00:00:00 to 5F:FF:FF:FF:FF:FF:FF:FF.
95 - To ensure uniqueness of WWN's in the SAN fabric, you are strongly encouraged to use the WWN prefix - 20:00:00:25:B5:xx:xx:xx.
96 - Required when wwnn_address_type is static and target platform is FIAttached.
97 - Only applicable for FIAttached target platform.
98 type: str
99 vhbas:
100 description:
101 - List of vHBAs to be created and attached to the SAN Connectivity policy.
102 - Each vHBA will be configured with the specified fibre channel policies.
103 - Configuration options vary based on target_platform.
104 type: list
105 elements: dict
106 suboptions:
107 name:
108 description:
109 - Name of the virtual fibre channel interface.
110 - Must be unique within the SAN Connectivity policy.
111 type: str
112 required: true
113 state:
114 description:
115 - Whether to create/update or delete the vHBA.
116 type: str
117 choices: ['present', 'absent']
118 default: present
119 vhba_type:
120 description:
121 - vHBA Type configuration for SAN Connectivity Policy.
122 - This configuration is supported only on Cisco VIC 14XX series and higher series of adapters.
123 - Required when vHBA state is present.
124 type: str
125 choices: ['fc-initiator', 'fc-nvme-initiator', 'fc-nvme-target', 'fc-target']
126 slot_id:
127 description:
128 - PCIe Slot where the VIC adapter is installed.
129 - Supported values are (1-15) and MLOM.
130 - Required for Standalone when vHBA state is present.
131 - Required for FIAttached when vHBA state is present and auto_slot_id is false.
132 type: str
133 pci_link:
134 description:
135 - The PCI Link used as transport for the virtual interface.
136 - PCI Link is only applicable for select Cisco UCS VIC 1300 models (UCSC-PCIE-C40Q-03, UCSB-MLOM-40G-03, UCSB-VIC-M83-8P) that support two PCI links.
137 - The value, if specified, for any other VIC model will be ignored.
138 - For Standalone, this is used directly.
139 - For FIAttached, required when pci_link_assignment_mode is Custom.
140 type: int
141 choices: [0, 1]
142 default: 0
143 uplink_port:
144 description:
145 - Adapter port on which the virtual interface will be created.
146 - Only applicable for Standalone platform.
147 type: int
148 choices: [0, 1, 2, 3]
149 default: 0
150 pci_order:
151 description:
152 - The order in which the virtual interface is brought up.
153 - The order assigned to an interface should be unique for all the Ethernet and Fibre-Channel interfaces on each PCI link on a VIC adapter.
154 - The order should start from zero with no overlaps.
155 - The maximum value of PCI order is limited by the number of virtual interfaces (Ethernet and Fibre-Channel) on each PCI link on a VIC adapter.
156 - All VIC adapters have a single PCI link except VIC 1340, VIC 1380 and VIC 1385 which have two.
157 type: int
158 default: 0
159 persistent_lun_bindings:
160 description:
161 - Enables retention of LUN ID associations in memory until they are manually cleared.
162 type: bool
163 default: false
164 fibre_channel_network_policy:
165 description:
166 - Name of the Fibre Channel Network Policy.
167 - Required when vHBA state is present.
168 type: str
169 fibre_channel_qos_policy:
170 description:
171 - Name of the Fibre Channel QoS Policy.
172 - Required when vHBA state is present.
173 type: str
174 fibre_channel_adapter_policy:
175 description:
176 - Name of the Fibre Channel Adapter Policy.
177 - Required when vHBA state is present.
178 type: str
179 pin_group_name:
180 description:
181 - Pingroup name associated to vHBA for static pinning.
182 - SCP deploy will resolve pingroup name and fetches the corresponding uplink port/port channel to pin the vHBA traffic.
183 - Optional field for FIAttached target platform.
184 type: str
185 wwpn_address_type:
186 description:
187 - Type of WWPN address assignment.
188 - C(pool) to use a WWPN pool.
189 - C(static) to manually assign a static WWPN address.
190 - Only applicable for FIAttached target platform.
191 type: str
192 choices: ['pool', 'static']
193 default: 'pool'
194 wwpn_pool:
195 description:
196 - The WWPN pool used for assigning the WWPN address to the vHBA.
197 - Required when wwpn_address_type is pool and target platform is FIAttached.
198 - Only applicable for FIAttached target platform.
199 type: str
200 static_wwpn_address:
201 description:
202 - The WWPN address must be in hexadecimal format xx:xx:xx:xx:xx:xx:xx:xx.
203 - Allowed ranges are 20:00:00:00:00:00:00:00 to 20:FF:FF:FF:FF:FF:FF:FF or from 50:00:00:00:00:00:00:00 to 5F:FF:FF:FF:FF:FF:FF:FF.
204 - To ensure uniqueness of WWN's in the SAN fabric, you are strongly encouraged to use the WWN prefix - 20:00:00:25:B5:xx:xx:xx.
205 - Required when wwpn_address_type is static and target platform is FIAttached.
206 - Only applicable for FIAttached target platform.
207 type: str
208 switch_id:
209 description:
210 - The fabric port to which the vHBA will be associated.
211 - Only applicable for FIAttached target platform.
212 type: str
213 choices: ['a', 'b']
214 default: 'a'
215 auto_slot_id:
216 description:
217 - Enable or disable automatic assignment of the VIC slot ID.
218 - If enabled and the server has only one VIC, the same VIC is chosen for all the vHBAs.
219 - If enabled and the server has multiple VICs, the vHBA is deployed on the first VIC.
220 - If disabled, slot_id must be specified.
221 - Only applicable for FIAttached target platform.
222 type: bool
223 default: true
224 auto_pci_link:
225 description:
226 - Enable or disable automatic assignment of the PCI Link in a dual-link adapter.
227 - This option applies only to 13xx series VICs that support dual-link.
228 - If enabled, the system determines the placement of the vHBA on either of the PCI Links.
229 - If disabled, pci_link_assignment_mode must be specified.
230 - Only applicable for FIAttached target platform.
231 type: bool
232 default: true
233 pci_link_assignment_mode:
234 description:
235 - PCI Link assignment mode when auto_pci_link is disabled.
236 - C(custom) allows manual selection of PCI link via pci_link parameter.
237 - C(load-balanced) automatically distributes vHBAs across available PCI links.
238 - Required when auto_pci_link is false.
239 - Only applicable for FIAttached target platform.
240 type: str
241 choices: ['custom', 'load-balanced']
242 fibre_channel_zone_policies:
243 description:
244 - List of Fibre Channel Zone Policy names.
245 - Relationship to the FC Zone policy to configure Zones on the switch.
246 - Optional field for FIAttached target platform.
247 type: list
248 elements: str
249 author:
250 - Ron Gershburg (@rgershbu)
251 '''
252
253 EXAMPLES = r'''
254 - name: Create a SAN Connectivity Policy for Standalone servers
255 cisco.intersight.intersight_san_connectivity_policy:
256 api_private_key: "{{ api_private_key }}"
257 api_key_id: "{{ api_key_id }}"
258 organization: "default"
259 name: "standalone-san-policy"
260 description: "SAN connectivity policy for standalone servers"
261 target_platform: "Standalone"
262 tags:
263 - Key: "Environment"
264 Value: "Production"
265 - Key: "Site"
266 Value: "DataCenter-A"
267 vhbas:
268 - name: "vhba0"
269 vhba_type: "fc-initiator"
270 slot_id: "1"
271 pci_link: 0
272 uplink_port: 0
273 pci_order: 0
274 persistent_lun_bindings: false
275 fibre_channel_network_policy: "fc-network-policy"
276 fibre_channel_qos_policy: "fc-qos-policy"
277 fibre_channel_adapter_policy: "fc-adapter-policy"
278 - name: "vhba1"
279 vhba_type: "fc-nvme-initiator"
280 slot_id: "4"
281 pci_link: 0
282 uplink_port: 2
283 pci_order: 5
284 persistent_lun_bindings: true
285 fibre_channel_network_policy: "fc-network-policy"
286 fibre_channel_qos_policy: "fc-qos-policy"
287 fibre_channel_adapter_policy: "fc-adapter-policy"
288 state: present
289
290 - name: Create a SAN Connectivity Policy with auto placement
291 cisco.intersight.intersight_san_connectivity_policy:
292 api_private_key: "{{ api_private_key }}"
293 api_key_id: "{{ api_key_id }}"
294 organization: "default"
295 name: "auto-placement-san-policy"
296 description: "SAN policy with automatic vHBA placement"
297 target_platform: "FIAttached"
298 placement_mode: "auto"
299 wwnn_address_type: "pool"
300 wwnn_pool: "default-wwnn-pool"
301 vhbas:
302 - name: "vhba-auto-1"
303 vhba_type: "fc-initiator"
304 wwpn_address_type: "pool"
305 wwpn_pool: "default-wwpn-pool"
306 switch_id: "a"
307 fibre_channel_network_policy: "fc-network-policy"
308 fibre_channel_qos_policy: "fc-qos-policy"
309 fibre_channel_adapter_policy: "fc-adapter-policy"
310 - name: "vhba-auto-2"
311 vhba_type: "fc-initiator"
312 wwpn_address_type: "pool"
313 wwpn_pool: "default-wwpn-pool"
314 switch_id: "b"
315 fibre_channel_network_policy: "fc-network-policy"
316 fibre_channel_qos_policy: "fc-qos-policy"
317 fibre_channel_adapter_policy: "fc-adapter-policy"
318 state: present
319
320 - name: Create a SAN Connectivity Policy for FI-Attached servers with WWNN pool
321 cisco.intersight.intersight_san_connectivity_policy:
322 api_private_key: "{{ api_private_key }}"
323 api_key_id: "{{ api_key_id }}"
324 organization: "default"
325 name: "fi-attached-san-policy"
326 description: "SAN connectivity policy for FI-attached servers"
327 target_platform: "FIAttached"
328 placement_mode: "custom"
329 wwnn_address_type: "pool"
330 wwnn_pool: "default-wwnn-pool"
331 tags:
332 - Key: "Environment"
333 Value: "Production"
334 vhbas:
335 - name: "vhba-a"
336 vhba_type: "fc-initiator"
337 wwpn_address_type: "pool"
338 wwpn_pool: "default-wwpn-pool"
339 switch_id: "a"
340 auto_slot_id: true
341 auto_pci_link: true
342 pci_order: 0
343 persistent_lun_bindings: false
344 fibre_channel_network_policy: "fc-network-policy"
345 fibre_channel_qos_policy: "fc-qos-policy"
346 fibre_channel_adapter_policy: "fc-adapter-policy"
347 fibre_channel_zone_policies:
348 - "fc-zone-policy-1"
349 - name: "vhba-b"
350 vhba_type: "fc-initiator"
351 wwpn_address_type: "pool"
352 wwpn_pool: "default-wwpn-pool"
353 switch_id: "b"
354 auto_slot_id: true
355 auto_pci_link: true
356 pci_order: 1
357 persistent_lun_bindings: false
358 fibre_channel_network_policy: "fc-network-policy"
359 fibre_channel_qos_policy: "fc-qos-policy"
360 fibre_channel_adapter_policy: "fc-adapter-policy"
361 fibre_channel_zone_policies:
362 - "fc-zone-policy-1"
363 state: present
364
365 - name: Create a SAN Connectivity Policy for FI-Attached with static WWPN
366 cisco.intersight.intersight_san_connectivity_policy:
367 api_private_key: "{{ api_private_key }}"
368 api_key_id: "{{ api_key_id }}"
369 organization: "default"
370 name: "fi-attached-static-san-policy"
371 description: "SAN connectivity policy with static addresses"
372 target_platform: "FIAttached"
373 placement_mode: "custom"
374 wwnn_address_type: "pool"
375 wwnn_pool: "default-wwnn-pool"
376 vhbas:
377 - name: "vhba-static"
378 vhba_type: "fc-target"
379 wwpn_address_type: "static"
380 static_wwpn_address: "50:00:00:00:00:00:00:00"
381 switch_id: "b"
382 auto_slot_id: false
383 slot_id: "2"
384 auto_pci_link: false
385 pci_link_assignment_mode: "load-balanced"
386 pci_order: 1
387 persistent_lun_bindings: true
388 fibre_channel_network_policy: "fc-network-policy"
389 fibre_channel_qos_policy: "fc-qos-policy"
390 fibre_channel_adapter_policy: "fc-adapter-policy"
391 fibre_channel_zone_policies:
392 - "fc-zone-policy-1"
393 state: present
394
395 - name: Create a SAN Connectivity Policy for FI-Attached with advanced placement
396 cisco.intersight.intersight_san_connectivity_policy:
397 api_private_key: "{{ api_private_key }}"
398 api_key_id: "{{ api_key_id }}"
399 organization: "default"
400 name: "fi-attached-advanced-placement"
401 description: "SAN connectivity with custom placement"
402 target_platform: "FIAttached"
403 placement_mode: "custom"
404 wwnn_address_type: "static"
405 static_wwnn_address: "20:00:00:25:B5:00:00:01"
406 vhbas:
407 - name: "vhba-custom"
408 vhba_type: "fc-initiator"
409 wwpn_address_type: "pool"
410 wwpn_pool: "wwpn-pool"
411 switch_id: "a"
412 auto_slot_id: false
413 slot_id: "MLOM"
414 auto_pci_link: false
415 pci_link_assignment_mode: "custom"
416 pci_link: 1
417 pci_order: 3
418 persistent_lun_bindings: false
419 pin_group_name: "pingroup-a"
420 fibre_channel_network_policy: "fc-network-policy"
421 fibre_channel_qos_policy: "fc-qos-policy"
422 fibre_channel_adapter_policy: "fc-adapter-policy"
423 state: present
424
425 - name: Update SAN connectivity policy - manage vHBA states
426 cisco.intersight.intersight_san_connectivity_policy:
427 api_private_key: "{{ api_private_key }}"
428 api_key_id: "{{ api_key_id }}"
429 organization: "default"
430 name: "mixed-vhba-states-policy"
431 description: "Policy demonstrating vHBA state management"
432 target_platform: "Standalone"
433 vhbas:
434 - name: "vhba0"
435 vhba_type: "fc-initiator"
436 slot_id: "1"
437 pci_link: 0
438 uplink_port: 0
439 pci_order: 0
440 persistent_lun_bindings: false
441 fibre_channel_network_policy: "fc-network-policy"
442 fibre_channel_qos_policy: "fc-qos-policy"
443 fibre_channel_adapter_policy: "fc-adapter-policy"
444 state: present
445 - name: "vhba-old"
446 state: absent
447 - name: "vhba-new"
448 vhba_type: "fc-nvme-initiator"
449 slot_id: "3"
450 pci_link: 0
451 uplink_port: 1
452 pci_order: 1
453 persistent_lun_bindings: true
454 fibre_channel_network_policy: "fc-network-policy"
455 fibre_channel_qos_policy: "fc-qos-policy"
456 fibre_channel_adapter_policy: "fc-adapter-policy"
457 state: present
458 state: present
459
460 - name: Delete a SAN Connectivity Policy
461 cisco.intersight.intersight_san_connectivity_policy:
462 api_private_key: "{{ api_private_key }}"
463 api_key_id: "{{ api_key_id }}"
464 name: "old-san-policy"
465 state: absent
466 '''
467
468 RETURN = r'''
469 api_response:
470 description: The API response output returned by the specified resource.
471 returned: always
472 type: dict
473 sample:
474 "api_response": {
475 "Name": "fi-attached-san-policy",
476 "ObjectType": "vnic.SanConnectivityPolicy",
477 "TargetPlatform": "FIAttached",
478 "WwnnAddressType": "POOL",
479 "Tags": [
480 {
481 "Key": "Environment",
482 "Value": "Production"
483 }
484 ],
485 "vHBAs": [
486 {
487 "Name": "vhba-a",
488 "ObjectType": "vnic.FcIf",
489 "Type": "fc-initiator",
490 "Order": 0,
491 "Placement": {
492 "SwitchId": "A",
493 "AutoSlotId": true,
494 "AutoPciLink": true
495 }
496 }
497 ]
498 }
499 '''
500
501
502 from ansible.module_utils.basic import AnsibleModule
503 from ansible_collections.cisco.intersight.plugins.module_utils.intersight import IntersightModule, intersight_argument_spec
504 from ansible_collections.cisco.intersight.plugins.module_utils.intersight_vhba_utils import (
505 validate_wwnn_address_config, validate_wwpn_address_config, validate_fi_attached_placement_config,
506 validate_standalone_vhba_config, resolve_policy_moids_from_mappings,
507 resolve_fc_zone_policies, build_wwpn_address_config, build_fi_attached_placement,
508 build_standalone_placement, get_san_connectivity_vhba_policy_mappings
509 )
510
511
512 def validate_fi_attached_params(module):
513 """
514 Validate FI-Attached specific parameters.
515 """
516 validate_wwnn_address_config(module, module.params)
517
518
519 def validate_fi_attached_vhba_config(module, vhba_config):
520 """
521 Validate FIAttached specific vHBA configuration.
522 """
523 vhba_name = vhba_config.get('name', 'unknown')
524 validate_wwpn_address_config(module, vhba_config, f"vHBA '{vhba_name}'")
525 validate_fi_attached_placement_config(module, vhba_config)
526
527
528 def validate_input(module):
529 """
530 Validate module input parameters.
531 """
532 target_platform = module.params.get('target_platform')
533 if target_platform == 'FIAttached':
534 validate_fi_attached_params(module)
535 vhbas = module.params.get('vhbas', [])
536 for vhba_config in vhbas:
537 vhba_name = vhba_config.get('name')
538 vhba_state = vhba_config.get('state', 'present')
539 if vhba_state == 'present':
540 required_fields = ['vhba_type', 'fibre_channel_network_policy', 'fibre_channel_qos_policy', 'fibre_channel_adapter_policy']
541 for field in required_fields:
542 if not vhba_config.get(field):
543 module.fail_json(msg=f"{field} is required when vHBA state is 'present' for vHBA '{vhba_name}'")
544 if target_platform == 'FIAttached':
545 validate_fi_attached_vhba_config(module, vhba_config)
546 elif target_platform == 'Standalone':
547 validate_standalone_vhba_config(module, vhba_config)
548
549
550 def build_standalone_vhba_api_body(intersight, policy_cache, module, vhba_config, san_connectivity_policy_moid):
551 """
552 Build Standalone vHBA API body for Intersight API call.
553 """
554 organization_name = module.params['organization']
555 target_platform = module.params.get('target_platform')
556 vhba_api_body = {
557 'Name': vhba_config['name'],
558 'Type': vhba_config['vhba_type'],
559 'Placement': build_standalone_placement(vhba_config),
560 'Order': vhba_config.get('pci_order', 0),
561 'PersistentBindings': vhba_config.get('persistent_lun_bindings', False),
562 'SanConnectivityPolicy': san_connectivity_policy_moid,
563 'StaticWwpnAddress': ''
564 }
565 # Resolve FC policy MOIDs
566 policy_mappings = get_san_connectivity_vhba_policy_mappings(target_platform)
567 policy_moids = resolve_policy_moids_from_mappings(intersight, policy_cache, module, vhba_config, policy_mappings, organization_name)
568 vhba_api_body.update(policy_moids)
569 vhba_api_body['FcZonePolicies'] = []
570 return vhba_api_body
571
572
573 def build_fi_attached_vhba_api_body(intersight, policy_cache, module, vhba_config, san_connectivity_policy_moid):
574 """
575 Build FIAttached vHBA API body for Intersight API call.
576 """
577 organization_name = module.params['organization']
578 target_platform = module.params.get('target_platform')
579 vhba_api_body = {
580 'Name': vhba_config['name'],
581 'Type': vhba_config['vhba_type'],
582 'Order': vhba_config.get('pci_order', 0),
583 'PersistentBindings': vhba_config.get('persistent_lun_bindings', False),
584 'SanConnectivityPolicy': san_connectivity_policy_moid
585 }
586 # Build WWPN address configuration
587 wwpn_config = build_wwpn_address_config(vhba_config, intersight, policy_cache, module, organization_name)
588 vhba_api_body.update(wwpn_config)
589
590 # Build placement configuration
591 vhba_api_body['Placement'] = build_fi_attached_placement(vhba_config)
592
593 # Resolve FC policy MOIDs
594 policy_mappings = get_san_connectivity_vhba_policy_mappings(target_platform)
595 policy_moids = resolve_policy_moids_from_mappings(intersight, policy_cache, module, vhba_config, policy_mappings, organization_name)
596 vhba_api_body.update(policy_moids)
597
598 # Resolve FC Zone Policies (optional)
599 fc_zone_policy_names = vhba_config.get('fibre_channel_zone_policies')
600 fc_zone_policy_moids = resolve_fc_zone_policies(intersight, policy_cache, module, fc_zone_policy_names, organization_name)
601 vhba_api_body['FcZonePolicies'] = fc_zone_policy_moids
602
603 # Add pin group name if specified
604 if vhba_config.get('pin_group_name'):
605 vhba_api_body['PinGroupName'] = vhba_config['pin_group_name']
606
607 return vhba_api_body
608
609
610 def build_vhba_api_body(intersight, policy_cache, module, vhba_config, san_connectivity_policy_moid):
611 """
612 Build vHBA API body based on target platform.
613 """
614 target_platform = module.params.get('target_platform')
615 if target_platform == 'FIAttached':
616 return build_fi_attached_vhba_api_body(intersight, policy_cache, module, vhba_config, san_connectivity_policy_moid)
617 else:
618 return build_standalone_vhba_api_body(intersight, policy_cache, module, vhba_config, san_connectivity_policy_moid)
619
620
621 def main():
622 vhba_options = dict(
623 name=dict(type='str', required=True),
624 state=dict(type='str', choices=['present', 'absent'], default='present'),
625 vhba_type=dict(type='str', choices=['fc-initiator', 'fc-nvme-initiator', 'fc-nvme-target', 'fc-target']),
626 slot_id=dict(type='str'),
627 pci_link=dict(type='int', choices=[0, 1], default=0),
628 uplink_port=dict(type='int', choices=[0, 1, 2, 3], default=0),
629 pci_order=dict(type='int', default=0),
630 persistent_lun_bindings=dict(type='bool', default=False),
631 fibre_channel_network_policy=dict(type='str'),
632 fibre_channel_qos_policy=dict(type='str'),
633 fibre_channel_adapter_policy=dict(type='str'),
634 pin_group_name=dict(type='str'),
635 wwpn_address_type=dict(type='str', choices=['pool', 'static'], default='pool'),
636 wwpn_pool=dict(type='str'),
637 static_wwpn_address=dict(type='str'),
638 switch_id=dict(type='str', choices=['a', 'b'], default='a'),
639 auto_slot_id=dict(type='bool', default=True),
640 auto_pci_link=dict(type='bool', default=True),
641 pci_link_assignment_mode=dict(type='str', choices=['custom', 'load-balanced']),
642 fibre_channel_zone_policies=dict(type='list', elements='str')
643 )
644 argument_spec = intersight_argument_spec.copy()
645 argument_spec.update(
646 state=dict(type='str', choices=['present', 'absent'], default='present'),
647 organization=dict(type='str', default='default'),
648 name=dict(type='str', required=True),
649 description=dict(type='str', aliases=['descr']),
650 tags=dict(type='list', elements='dict'),
651 target_platform=dict(type='str', choices=['Standalone', 'FIAttached'], default='Standalone'),
652 placement_mode=dict(type='str', choices=['custom', 'auto'], default='custom'),
653 wwnn_address_type=dict(type='str', choices=['pool', 'static'], default='pool'),
654 wwnn_pool=dict(type='str'),
655 static_wwnn_address=dict(type='str'),
656 vhbas=dict(type='list', elements='dict', options=vhba_options)
657 )
658 module = AnsibleModule(
659 argument_spec,
660 supports_check_mode=True,
661 )
662 if module.params['state'] == 'present':
663 validate_input(module)
664
665 intersight = IntersightModule(module)
666 intersight.result['api_response'] = {}
667 intersight.result['trace_id'] = ''
668
669 resource_path = '/vnic/SanConnectivityPolicies'
670 intersight.api_body = {
671 'Organization': {
672 'Name': intersight.module.params['organization'],
673 },
674 'Name': intersight.module.params['name']
675 }
676
677 if intersight.module.params['state'] == 'present':
678 intersight.set_tags_and_description()
679 target_platform_map = {
680 'Standalone': 'Standalone',
681 'FIAttached': 'FIAttached'
682 }
683 api_target_platform = target_platform_map[intersight.module.params['target_platform']]
684 intersight.api_body['TargetPlatform'] = api_target_platform
685
686 if intersight.module.params['target_platform'] == 'FIAttached':
687 # PlacementMode is only applicable for FIAttached
688 placement_mode_map = {'custom': 'custom', 'auto': 'auto'}
689 api_placement_mode = placement_mode_map[intersight.module.params['placement_mode']]
690 intersight.api_body['PlacementMode'] = api_placement_mode
691 wwnn_address_type_map = {'pool': 'POOL', 'static': 'STATIC'}
692 api_wwnn_address_type = wwnn_address_type_map[intersight.module.params['wwnn_address_type']]
693 intersight.api_body['WwnnAddressType'] = api_wwnn_address_type
694
695 if intersight.module.params['wwnn_address_type'] == 'pool':
696 wwnn_pool_moid = intersight.get_moid_by_name_and_org(
697 resource_path='/fcpool/Pools',
698 resource_name=intersight.module.params['wwnn_pool'],
699 organization_name=intersight.module.params['organization']
700 )
701 if not wwnn_pool_moid:
702 intersight.module.fail_json(
703 msg=f"WWNN Pool '{intersight.module.params['wwnn_pool']}' not found in organization '{intersight.module.params['organization']}'"
704 )
705 intersight.api_body['WwnnPool'] = wwnn_pool_moid
706 intersight.api_body['StaticWwnnAddress'] = ''
707 else:
708 intersight.api_body['StaticWwnnAddress'] = intersight.module.params['static_wwnn_address']
709
710 elif intersight.module.params['target_platform'] == 'Standalone':
711 intersight.api_body['PlacementMode'] = 'custom'
712 intersight.api_body['WwnnAddressType'] = 'POOL'
713 intersight.api_body['StaticWwnnAddress'] = ''
714
715 intersight.configure_policy_or_profile(resource_path=resource_path)
716 san_connectivity_policy_response = intersight.result['api_response']
717 san_connectivity_policy_moid = None
718 if intersight.module.params['state'] == 'present' and san_connectivity_policy_response:
719 san_connectivity_policy_moid = san_connectivity_policy_response.get('Moid')
720
721 # Process vHBAs
722 vhbas_response = []
723 if intersight.module.params['state'] == 'present' and intersight.module.params.get('vhbas'):
724 policy_cache = {}
725 for vhba_config in intersight.module.params['vhbas']:
726 vhba_state = vhba_config.get('state', 'present')
727 if vhba_state == 'present':
728 vhba_api_body = build_vhba_api_body(
729 intersight, policy_cache, module, vhba_config, san_connectivity_policy_moid
730 )
731 intersight.api_body = vhba_api_body
732
733 resource_path = '/vnic/FcIfs'
734 custom_filter = f"Name eq '{vhba_config['name']}' and SanConnectivityPolicy.Moid eq '{san_connectivity_policy_moid}'"
735 intersight.configure_secondary_resource(
736 resource_path=resource_path,
737 state=vhba_state,
738 custom_filter=custom_filter
739 )
740 if vhba_state == 'present':
741 vhbas_response.append(intersight.result['api_response'])
742
743 if san_connectivity_policy_response:
744 san_connectivity_policy_response['vHBAs'] = vhbas_response
745 intersight.result['api_response'] = san_connectivity_policy_response
746
747 module.exit_json(**intersight.result)
748
749
750 if __name__ == '__main__':
751 main()