| 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_lan_connectivity_policy |
| 16 |
short_description: Manage LAN Connectivity Policies and vNICs for Cisco Intersight |
| 17 |
description: |
| 18 |
- Create, update, and delete LAN Connectivity Policies on Cisco Intersight. |
| 19 |
- Manage individual vNICs within LAN Connectivity policies. |
| 20 |
- Supports both Standalone and FIAttached target platforms with different configuration options. |
| 21 |
- LAN Connectivity policies define network connectivity settings for server profiles. |
| 22 |
- For more information see L(Cisco Intersight,https://intersight.com/apidocs/vnic/LanConnectivityPolicy/get/). |
| 23 |
extends_documentation_fragment: intersight |
| 24 |
options: |
| 25 |
state: |
| 26 |
description: |
| 27 |
- If C(present), will verify the resource is present and will create if needed. |
| 28 |
- If C(absent), will verify the resource is absent and will delete if needed. |
| 29 |
type: str |
| 30 |
choices: [present, absent] |
| 31 |
default: present |
| 32 |
organization: |
| 33 |
description: |
| 34 |
- The name of the Organization this resource is assigned to. |
| 35 |
- Policies created within a Custom Organization are applicable only to devices in the same Organization. |
| 36 |
- Use 'default' for the default organization. |
| 37 |
type: str |
| 38 |
default: default |
| 39 |
name: |
| 40 |
description: |
| 41 |
- The name assigned to the LAN Connectivity Policy. |
| 42 |
- Must be unique within the organization. |
| 43 |
- The name must be between 1 and 62 alphanumeric characters, allowing special characters :-_. |
| 44 |
type: str |
| 45 |
required: true |
| 46 |
description: |
| 47 |
description: |
| 48 |
- The user-defined description for the LAN Connectivity Policy. |
| 49 |
- Description can contain letters(a-z, A-Z), numbers(0-9), hyphen(-), period(.), colon(:), or an underscore(_). |
| 50 |
type: str |
| 51 |
aliases: [descr] |
| 52 |
tags: |
| 53 |
description: |
| 54 |
- List of tags in Key:<user-defined key> Value:<user-defined value> format. |
| 55 |
type: list |
| 56 |
elements: dict |
| 57 |
target_platform: |
| 58 |
description: |
| 59 |
- The platform type for which the LAN Connectivity policy is intended. |
| 60 |
- Standalone for Standalone servers, FIAttached for fabric interconnect attached servers. |
| 61 |
type: str |
| 62 |
choices: ['Standalone', 'FIAttached'] |
| 63 |
default: 'Standalone' |
| 64 |
azure_qos_enabled: |
| 65 |
description: |
| 66 |
- Enable Azure QoS for the LAN Connectivity policy. |
| 67 |
- Only applicable when target_platform is 'FIAttached'. |
| 68 |
type: bool |
| 69 |
default: false |
| 70 |
iqn_allocation_type: |
| 71 |
description: |
| 72 |
- IQN allocation type for the LAN Connectivity policy. |
| 73 |
- Only applicable when target_platform is 'FIAttached'. |
| 74 |
type: str |
| 75 |
choices: ['None', 'Pool', 'Static'] |
| 76 |
default: 'None' |
| 77 |
placement_mode: |
| 78 |
description: |
| 79 |
- Placement mode for vNIC assignment. |
| 80 |
- Only applicable when target_platform is 'FIAttached'. |
| 81 |
type: str |
| 82 |
choices: ['custom', 'auto'] |
| 83 |
default: 'custom' |
| 84 |
iqn_pool_name: |
| 85 |
description: |
| 86 |
- Relationship to the iSCSI Qualified Name Pool. |
| 87 |
- Required when iqn_allocation_type is 'Pool'. |
| 88 |
- Only applicable for FIAttached target platform. |
| 89 |
type: str |
| 90 |
static_iqn_name: |
| 91 |
description: |
| 92 |
- User provided static iSCSI Qualified Name (IQN) for use as initiator identifiers by iSCSI vNICs in a Fabric Interconnect domain. |
| 93 |
- Required when iqn_allocation_type is 'Static'. |
| 94 |
- Only applicable for FIAttached target platform. |
| 95 |
type: str |
| 96 |
vnics: |
| 97 |
description: |
| 98 |
- List of vNICs to be created and attached to the LAN Connectivity policy. |
| 99 |
- Each vNIC will be configured with the specified network and adapter policies. |
| 100 |
- Required when C(state) is C(present). |
| 101 |
- At least one vNIC must be specified for both Standalone and FIAttached platforms. |
| 102 |
type: list |
| 103 |
elements: dict |
| 104 |
suboptions: |
| 105 |
name: |
| 106 |
description: |
| 107 |
- The name of the vNIC. |
| 108 |
- Must be unique within the LAN Connectivity policy. |
| 109 |
type: str |
| 110 |
required: true |
| 111 |
placement_slot_id: |
| 112 |
description: |
| 113 |
- PCIe Slot where the VIC adapter is installed. |
| 114 |
- Supported values are (1-15) and MLOM. |
| 115 |
- Required when vNIC state is 'present'. |
| 116 |
type: str |
| 117 |
uplink_port: |
| 118 |
description: |
| 119 |
- Adapter port on which the virtual interface will be created. |
| 120 |
type: int |
| 121 |
choices: [0, 1, 2, 3] |
| 122 |
default: 0 |
| 123 |
order: |
| 124 |
description: |
| 125 |
- The order in which the virtual interface is brought up. |
| 126 |
- 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. |
| 127 |
- The order should start from zero with no overlaps. |
| 128 |
- 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. |
| 129 |
- All VIC adapters have a single PCI link except VIC 1340, VIC 1380 and VIC 1385 which have two. |
| 130 |
type: int |
| 131 |
default: 0 |
| 132 |
cdn_source: |
| 133 |
description: |
| 134 |
- Source of the CDN. It can either be user specified or be the same as the vNIC name. |
| 135 |
type: str |
| 136 |
choices: ['vnic', 'user'] |
| 137 |
default: 'vnic' |
| 138 |
cdn_value: |
| 139 |
description: |
| 140 |
- CDN value when cdn_source is 'user'. |
| 141 |
type: str |
| 142 |
eth_network_policy_name: |
| 143 |
description: |
| 144 |
- Relationship to the Ethernet Network Policy. |
| 145 |
- Required when vNIC state is 'present'. |
| 146 |
type: str |
| 147 |
eth_qos_policy_name: |
| 148 |
description: |
| 149 |
- Relationship to the Ethernet QoS Policy. |
| 150 |
- Required when vNIC state is 'present'. |
| 151 |
type: str |
| 152 |
eth_adapter_policy_name: |
| 153 |
description: |
| 154 |
- Relationship to the Ethernet Adapter Policy. |
| 155 |
- Required when vNIC state is 'present'. |
| 156 |
type: str |
| 157 |
connection_type: |
| 158 |
description: |
| 159 |
- Type of connection for the vNIC. |
| 160 |
type: str |
| 161 |
choices: ['none', 'usnic', 'vmq', 'sriov'] |
| 162 |
default: 'none' |
| 163 |
mac_address_type: |
| 164 |
description: |
| 165 |
- Type of MAC address assignment. |
| 166 |
- Only applicable for FIAttached target platform. |
| 167 |
type: str |
| 168 |
choices: ['pool', 'static'] |
| 169 |
default: 'pool' |
| 170 |
mac_pool_name: |
| 171 |
description: |
| 172 |
- The MAC pool that is assigned. |
| 173 |
- Required when mac_address_type is 'pool' and target platform is FIAttached. |
| 174 |
- Only applicable for FIAttached target platform. |
| 175 |
type: str |
| 176 |
static_mac_address: |
| 177 |
description: |
| 178 |
- The MAC address must be in hexadecimal format xx:xx:xx:xx:xx:xx. |
| 179 |
- To ensure uniqueness of MACs in the LAN fabric, you are strongly encouraged to use the following MAC prefix 00:25:B5:xx:xx:xx. |
| 180 |
- Required when mac_address_type is 'static' and target platform is FIAttached. |
| 181 |
- Only applicable for FIAttached target platform. |
| 182 |
type: str |
| 183 |
pci_link: |
| 184 |
description: |
| 185 |
- The PCI Link used as transport for the virtual interface. |
| 186 |
- 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. |
| 187 |
- The value, if specified, for any other VIC model will be ignored. |
| 188 |
- For FIAttached required when pci_link_assignment_mode is 'Custom'. |
| 189 |
type: int |
| 190 |
choices: [0, 1] |
| 191 |
default: 0 |
| 192 |
auto_slot_id: |
| 193 |
description: |
| 194 |
- Enable or disable automatic assignment of the VIC slot ID. |
| 195 |
- If enabled and the server has only one VIC, the same VIC is chosen for all the vNICs. |
| 196 |
- If enabled and the server has multiple VICs, the vNIC/vHBA are deployed on the first VIC. |
| 197 |
- If disabled, placement_slot_id must be specified. |
| 198 |
- Only applicable for FIAttached target platform when auto_vnic_placement_enabled is false. |
| 199 |
type: bool |
| 200 |
default: true |
| 201 |
auto_pci_link: |
| 202 |
description: |
| 203 |
- Enable or disable automatic assignment of the PCI Link in a dual-link adapter. |
| 204 |
- This option applies only to 13xx series VICs that support dual-link. |
| 205 |
- If enabled, the system determines the placement of the vNIC/vHBA on either of the PCI Links. |
| 206 |
- If disabled, pci_link_assignment_mode must be specified. |
| 207 |
- Only applicable for FIAttached target platform when auto_vnic_placement_enabled is false. |
| 208 |
type: bool |
| 209 |
default: true |
| 210 |
pci_link_assignment_mode: |
| 211 |
description: |
| 212 |
- PCI Link assignment mode when auto_pci_link is disabled. |
| 213 |
- Custom allows manual selection of PCI link via pci_link parameter. |
| 214 |
- Load-Balanced automatically distributes vNICs across available PCI links. |
| 215 |
- Required when auto_pci_link is false and auto_vnic_placement_enabled is false. |
| 216 |
- Only applicable for FIAttached target platform. |
| 217 |
type: str |
| 218 |
choices: ['Custom', 'Load-Balanced'] |
| 219 |
auto_vnic_placement_enabled: |
| 220 |
description: |
| 221 |
- Enable automatic vNIC placement for FIAttached servers. |
| 222 |
- When enabled, the vNIC placement is simplified to only specify the switch ID. |
| 223 |
- When disabled, full placement control is available including order, auto_slot_id, and auto_pci_link. |
| 224 |
- Only applicable for FIAttached target platform. |
| 225 |
type: bool |
| 226 |
default: false |
| 227 |
switch_id: |
| 228 |
description: |
| 229 |
- The fabric port to which the vNICs will be associated. |
| 230 |
- Only applicable for FIAttached target platform. |
| 231 |
type: str |
| 232 |
choices: ['A', 'B'] |
| 233 |
default: 'A' |
| 234 |
failover_enabled: |
| 235 |
description: |
| 236 |
- Enables automatic vNIC failover to the secondary Fabric Interconnect |
| 237 |
if the primary path fails. |
| 238 |
- Failover applies only to Cisco VICs that are connected to a Fabric Interconnect cluster. |
| 239 |
- Only applicable for FIAttached target platform. |
| 240 |
type: bool |
| 241 |
default: false |
| 242 |
fabric_eth_network_group_policy_name: |
| 243 |
description: |
| 244 |
- Relationship to the Fabric Ethernet Group Policy. |
| 245 |
- Required when target platform is FIAttached and vNIC state is 'present'. |
| 246 |
- Only applicable for FIAttached target platform. |
| 247 |
type: str |
| 248 |
fabric_eth_network_control_policy_name: |
| 249 |
description: |
| 250 |
- Relationship to the Fabric Ethernet Network Policy. |
| 251 |
- Required when target platform is FIAttached and vNIC state is 'present'. |
| 252 |
- Only applicable for FIAttached target platform. |
| 253 |
type: str |
| 254 |
iscsi_boot_policy_name: |
| 255 |
description: |
| 256 |
- Relationship to the boot iSCSI Policy. |
| 257 |
- Only applicable for FIAttached target platform. |
| 258 |
type: str |
| 259 |
pin_group_name: |
| 260 |
description: |
| 261 |
- Pingroup name associated to vNIC for static pinning. |
| 262 |
- LCP deploy will resolve pingroup name and fetches the corresponding uplink port/port channel to pin the vNIC traffic. |
| 263 |
- Only applicable for FIAttached target platform. |
| 264 |
type: str |
| 265 |
usnic_settings: |
| 266 |
description: |
| 267 |
- USNIC settings when connection_type is 'usnic'. |
| 268 |
- Required when connection_type is 'usnic'. |
| 269 |
type: dict |
| 270 |
suboptions: |
| 271 |
count: |
| 272 |
description: |
| 273 |
- Number of usNIC interfaces to be created. |
| 274 |
- When usNIC is enabled, the valid values are from 1 to 225. |
| 275 |
- When usNIC is disabled, the default value is 0. |
| 276 |
type: int |
| 277 |
default: 0 |
| 278 |
cos: |
| 279 |
description: |
| 280 |
- Class of Service to be used for traffic on the usNIC. |
| 281 |
type: int |
| 282 |
choices: [0, 1, 2, 3, 4, 5, 6] |
| 283 |
default: 5 |
| 284 |
usnic_adapter_policy_name: |
| 285 |
description: |
| 286 |
- Ethernet Adapter policy to be associated with the usNICs. |
| 287 |
- Required when connection_type is 'usnic'. |
| 288 |
type: str |
| 289 |
vmq_settings: |
| 290 |
description: |
| 291 |
- VMQ settings when connection_type is 'vmq'. |
| 292 |
type: dict |
| 293 |
suboptions: |
| 294 |
enabled: |
| 295 |
description: |
| 296 |
- Enable VMQ. |
| 297 |
type: bool |
| 298 |
default: true |
| 299 |
multi_queue_support: |
| 300 |
description: |
| 301 |
- Enables Virtual Machine Multi-Queue feature on the virtual interface. |
| 302 |
- VMMQ allows configuration of multiple I/O queues for a single VM and thus distributes traffic across multiple CPU cores in a VM. |
| 303 |
type: bool |
| 304 |
default: false |
| 305 |
num_interrupts: |
| 306 |
description: |
| 307 |
- The number of interrupt resources to be allocated. |
| 308 |
- Recommended value is the number of CPU threads or logical processors available in the server. |
| 309 |
type: int |
| 310 |
default: 16 |
| 311 |
num_vmqs: |
| 312 |
description: |
| 313 |
- The number of hardware Virtual Machine Queues to be allocated. |
| 314 |
- The number of VMQs per adapter must be one more than the maximum number of VM NICs. |
| 315 |
type: int |
| 316 |
default: 4 |
| 317 |
num_sub_vnics: |
| 318 |
description: |
| 319 |
- Number of sub vNICs (0-64). |
| 320 |
- Only applicable when multi_queue_support is true. |
| 321 |
type: int |
| 322 |
default: 64 |
| 323 |
vmmq_adapter_policy_name: |
| 324 |
description: |
| 325 |
- Name of the VMMQ Adapter Policy. |
| 326 |
- Only applicable when multi_queue_support is true. |
| 327 |
type: str |
| 328 |
sriov_settings: |
| 329 |
description: |
| 330 |
- SR-IOV settings when connection_type is 'sriov'. |
| 331 |
type: dict |
| 332 |
suboptions: |
| 333 |
enabled: |
| 334 |
description: |
| 335 |
- Enable SR-IOV. |
| 336 |
type: bool |
| 337 |
default: true |
| 338 |
vf_count: |
| 339 |
description: |
| 340 |
- Number of Virtual Functions (1-64). |
| 341 |
type: int |
| 342 |
default: 64 |
| 343 |
rx_count_per_vf: |
| 344 |
description: |
| 345 |
- Receive Queue Count per VF (1-8). |
| 346 |
type: int |
| 347 |
default: 4 |
| 348 |
tx_count_per_vf: |
| 349 |
description: |
| 350 |
- Transmit Queue Count per VF (1-8). |
| 351 |
type: int |
| 352 |
default: 1 |
| 353 |
comp_count_per_vf: |
| 354 |
description: |
| 355 |
- Completion Queue Count per VF (1-16). |
| 356 |
type: int |
| 357 |
default: 5 |
| 358 |
int_count_per_vf: |
| 359 |
description: |
| 360 |
- Interrupt Count per VF (1-16). |
| 361 |
type: int |
| 362 |
default: 8 |
| 363 |
state: |
| 364 |
description: |
| 365 |
- Whether to create/update or delete the vNIC. |
| 366 |
type: str |
| 367 |
choices: ['present', 'absent'] |
| 368 |
default: present |
| 369 |
author: |
| 370 |
- Ron Gershburg (@rgershbu) |
| 371 |
''' |
| 372 |
|
| 373 |
EXAMPLES = r''' |
| 374 |
- name: Create a LAN Connectivity Policy for Standalone servers |
| 375 |
cisco.intersight.intersight_lan_connectivity_policy: |
| 376 |
api_private_key: "{{ api_private_key }}" |
| 377 |
api_key_id: "{{ api_key_id }}" |
| 378 |
organization: "default" |
| 379 |
name: "Standalone-lan-policy" |
| 380 |
description: "LAN connectivity policy for Standalone servers" |
| 381 |
target_platform: "Standalone" |
| 382 |
tags: |
| 383 |
- Key: "Environment" |
| 384 |
Value: "Production" |
| 385 |
- Key: "Site" |
| 386 |
Value: "DataCenter-A" |
| 387 |
vnics: |
| 388 |
- name: "eth0" |
| 389 |
placement_slot_id: "1" |
| 390 |
pci_link: 0 |
| 391 |
uplink_port: 0 |
| 392 |
order: 0 |
| 393 |
eth_network_policy_name: "default-network-policy" |
| 394 |
eth_qos_policy_name: "default-qos-policy" |
| 395 |
eth_adapter_policy_name: "default-adapter-policy" |
| 396 |
connection_type: "none" |
| 397 |
- name: "eth1" |
| 398 |
placement_slot_id: "2" |
| 399 |
pci_link: 0 |
| 400 |
uplink_port: 1 |
| 401 |
order: 1 |
| 402 |
eth_network_policy_name: "vlan-network-policy" |
| 403 |
eth_qos_policy_name: "high-qos-policy" |
| 404 |
eth_adapter_policy_name: "performance-adapter-policy" |
| 405 |
connection_type: "none" |
| 406 |
state: present |
| 407 |
|
| 408 |
- name: Create a LAN Connectivity Policy for FIAttached servers |
| 409 |
cisco.intersight.intersight_lan_connectivity_policy: |
| 410 |
api_private_key: "{{ api_private_key }}" |
| 411 |
api_key_id: "{{ api_key_id }}" |
| 412 |
organization: "default" |
| 413 |
name: "fi-attached-lan-policy" |
| 414 |
description: "LAN connectivity policy for FIAttached servers" |
| 415 |
target_platform: "FIAttached" |
| 416 |
azure_qos_enabled: true |
| 417 |
iqn_allocation_type: "Pool" |
| 418 |
iqn_pool_name: "default-iqn-pool" |
| 419 |
placement_mode: "custom" |
| 420 |
tags: |
| 421 |
- Key: "Environment" |
| 422 |
Value: "Production" |
| 423 |
vnics: |
| 424 |
- name: "vnic-fi-attached" |
| 425 |
order: 0 |
| 426 |
cdn_source: "vnic" |
| 427 |
mac_address_type: "pool" |
| 428 |
mac_pool_name: "default-mac-pool" |
| 429 |
auto_slot_id: true |
| 430 |
auto_pci_link: true |
| 431 |
auto_vnic_placement_enabled: false |
| 432 |
switch_id: "A" |
| 433 |
failover_enabled: false |
| 434 |
fabric_eth_network_group_policy_name: "default-network-group" |
| 435 |
fabric_eth_network_control_policy_name: "default-network-control" |
| 436 |
eth_qos_policy_name: "default-qos-policy" |
| 437 |
eth_adapter_policy_name: "default-adapter-policy" |
| 438 |
connection_type: "none" |
| 439 |
state: present |
| 440 |
state: present |
| 441 |
|
| 442 |
- name: Create a LAN Connectivity Policy with pin group for static pinning |
| 443 |
cisco.intersight.intersight_lan_connectivity_policy: |
| 444 |
api_private_key: "{{ api_private_key }}" |
| 445 |
api_key_id: "{{ api_key_id }}" |
| 446 |
organization: "default" |
| 447 |
name: "fi-attached-pinned-policy" |
| 448 |
description: "LAN connectivity policy with static uplink pinning" |
| 449 |
target_platform: "FIAttached" |
| 450 |
azure_qos_enabled: false |
| 451 |
iqn_allocation_type: "None" |
| 452 |
placement_mode: "custom" |
| 453 |
vnics: |
| 454 |
- name: "pinned-vnic" |
| 455 |
order: 0 |
| 456 |
cdn_source: "vnic" |
| 457 |
mac_address_type: "pool" |
| 458 |
mac_pool_name: "default-mac-pool" |
| 459 |
auto_slot_id: true |
| 460 |
auto_pci_link: true |
| 461 |
auto_vnic_placement_enabled: false |
| 462 |
switch_id: "A" |
| 463 |
failover_enabled: false |
| 464 |
fabric_eth_network_group_policy_name: "default-network-group" |
| 465 |
fabric_eth_network_control_policy_name: "default-network-control" |
| 466 |
eth_qos_policy_name: "default-qos-policy" |
| 467 |
eth_adapter_policy_name: "default-adapter-policy" |
| 468 |
pin_group_name: "pingroup-a" |
| 469 |
connection_type: "none" |
| 470 |
state: present |
| 471 |
state: present |
| 472 |
|
| 473 |
- name: Create a LAN Connectivity Policy with automatic vNIC placement |
| 474 |
cisco.intersight.intersight_lan_connectivity_policy: |
| 475 |
api_private_key: "{{ api_private_key }}" |
| 476 |
api_key_id: "{{ api_key_id }}" |
| 477 |
organization: "default" |
| 478 |
name: "fi-attached-auto-placement-policy" |
| 479 |
description: "LAN connectivity policy with automatic vNIC placement" |
| 480 |
target_platform: "FIAttached" |
| 481 |
azure_qos_enabled: false |
| 482 |
iqn_allocation_type: "None" |
| 483 |
placement_mode: "auto" |
| 484 |
vnics: |
| 485 |
- name: "auto-placed-vnic" |
| 486 |
cdn_source: "vnic" |
| 487 |
mac_address_type: "pool" |
| 488 |
mac_pool_name: "default-mac-pool" |
| 489 |
auto_vnic_placement_enabled: true |
| 490 |
switch_id: "A" |
| 491 |
failover_enabled: false |
| 492 |
fabric_eth_network_group_policy_name: "default-network-group" |
| 493 |
fabric_eth_network_control_policy_name: "default-network-control" |
| 494 |
eth_qos_policy_name: "default-qos-policy" |
| 495 |
eth_adapter_policy_name: "default-adapter-policy" |
| 496 |
connection_type: "none" |
| 497 |
state: present |
| 498 |
state: present |
| 499 |
|
| 500 |
- name: Create a LAN Connectivity Policy with advanced placement control |
| 501 |
cisco.intersight.intersight_lan_connectivity_policy: |
| 502 |
api_private_key: "{{ api_private_key }}" |
| 503 |
api_key_id: "{{ api_key_id }}" |
| 504 |
organization: "default" |
| 505 |
name: "fi-attached-advanced-placement-policy" |
| 506 |
description: "LAN connectivity policy with advanced placement control" |
| 507 |
target_platform: "FIAttached" |
| 508 |
azure_qos_enabled: false |
| 509 |
iqn_allocation_type: "None" |
| 510 |
placement_mode: "custom" |
| 511 |
vnics: |
| 512 |
- name: "advanced-placed-vnic" |
| 513 |
order: 9 |
| 514 |
cdn_source: "vnic" |
| 515 |
mac_address_type: "pool" |
| 516 |
mac_pool_name: "default-mac-pool" |
| 517 |
auto_slot_id: false |
| 518 |
placement_slot_id: "5" |
| 519 |
auto_pci_link: false |
| 520 |
pci_link_assignment_mode: "Custom" |
| 521 |
pci_link: 0 |
| 522 |
auto_vnic_placement_enabled: false |
| 523 |
switch_id: "A" |
| 524 |
failover_enabled: false |
| 525 |
fabric_eth_network_group_policy_name: "default-network-group" |
| 526 |
fabric_eth_network_control_policy_name: "default-network-control" |
| 527 |
eth_qos_policy_name: "default-qos-policy" |
| 528 |
eth_adapter_policy_name: "default-adapter-policy" |
| 529 |
connection_type: "none" |
| 530 |
state: present |
| 531 |
state: present |
| 532 |
|
| 533 |
- name: Create a LAN Connectivity Policy with load-balanced PCI assignment |
| 534 |
cisco.intersight.intersight_lan_connectivity_policy: |
| 535 |
api_private_key: "{{ api_private_key }}" |
| 536 |
api_key_id: "{{ api_key_id }}" |
| 537 |
organization: "default" |
| 538 |
name: "fi-attached-load-balanced-policy" |
| 539 |
description: "LAN connectivity policy with load-balanced PCI assignment" |
| 540 |
target_platform: "FIAttached" |
| 541 |
azure_qos_enabled: false |
| 542 |
iqn_allocation_type: "None" |
| 543 |
placement_mode: "custom" |
| 544 |
vnics: |
| 545 |
- name: "load-balanced-vnic" |
| 546 |
order: 5 |
| 547 |
cdn_source: "vnic" |
| 548 |
mac_address_type: "pool" |
| 549 |
mac_pool_name: "default-mac-pool" |
| 550 |
auto_slot_id: false |
| 551 |
placement_slot_id: "MLOM" |
| 552 |
auto_pci_link: false |
| 553 |
pci_link_assignment_mode: "Load-Balanced" |
| 554 |
auto_vnic_placement_enabled: false |
| 555 |
switch_id: "B" |
| 556 |
failover_enabled: true |
| 557 |
fabric_eth_network_group_policy_name: "default-network-group" |
| 558 |
fabric_eth_network_control_policy_name: "default-network-control" |
| 559 |
eth_qos_policy_name: "default-qos-policy" |
| 560 |
eth_adapter_policy_name: "default-adapter-policy" |
| 561 |
connection_type: "none" |
| 562 |
state: present |
| 563 |
state: present |
| 564 |
|
| 565 |
- name: Create a LAN Connectivity Policy with USNIC vNIC |
| 566 |
cisco.intersight.intersight_lan_connectivity_policy: |
| 567 |
api_private_key: "{{ api_private_key }}" |
| 568 |
api_key_id: "{{ api_key_id }}" |
| 569 |
name: "usnic-lan-policy" |
| 570 |
description: "Policy with USNIC configuration" |
| 571 |
target_platform: "Standalone" |
| 572 |
vnics: |
| 573 |
- name: "usnic-eth0" |
| 574 |
placement_slot_id: "4" |
| 575 |
pci_link: 0 |
| 576 |
uplink_port: 0 |
| 577 |
order: 0 |
| 578 |
eth_network_policy_name: "hpc-network-policy" |
| 579 |
eth_qos_policy_name: "hpc-qos-policy" |
| 580 |
eth_adapter_policy_name: "hpc-adapter-policy" |
| 581 |
connection_type: "usnic" |
| 582 |
usnic_settings: |
| 583 |
count: 0 |
| 584 |
cos: 5 |
| 585 |
usnic_adapter_policy_name: "hpc-adapter-policy" |
| 586 |
state: present |
| 587 |
|
| 588 |
- name: Create a LAN Connectivity Policy with VMQ vNIC |
| 589 |
cisco.intersight.intersight_lan_connectivity_policy: |
| 590 |
api_private_key: "{{ api_private_key }}" |
| 591 |
api_key_id: "{{ api_key_id }}" |
| 592 |
name: "vmq-lan-policy" |
| 593 |
description: "Policy with VMQ configuration" |
| 594 |
target_platform: "Standalone" |
| 595 |
vnics: |
| 596 |
- name: "vmq-eth0" |
| 597 |
placement_slot_id: "10" |
| 598 |
pci_link: 0 |
| 599 |
uplink_port: 2 |
| 600 |
order: 0 |
| 601 |
eth_network_policy_name: "vm-network-policy" |
| 602 |
eth_qos_policy_name: "vm-qos-policy" |
| 603 |
eth_adapter_policy_name: "vm-adapter-policy" |
| 604 |
connection_type: "vmq" |
| 605 |
vmq_settings: |
| 606 |
enabled: true |
| 607 |
multi_queue_support: false |
| 608 |
num_interrupts: 16 |
| 609 |
num_vmqs: 4 |
| 610 |
state: present |
| 611 |
|
| 612 |
- name: Create a LAN Connectivity Policy with VMQ multi-queue support |
| 613 |
cisco.intersight.intersight_lan_connectivity_policy: |
| 614 |
api_private_key: "{{ api_private_key }}" |
| 615 |
api_key_id: "{{ api_key_id }}" |
| 616 |
name: "vmq-multiqueue-lan-policy" |
| 617 |
description: "Policy with VMQ multi-queue configuration" |
| 618 |
target_platform: "Standalone" |
| 619 |
vnics: |
| 620 |
- name: "vmq-mq-eth0" |
| 621 |
placement_slot_id: "11" |
| 622 |
pci_link: 1 |
| 623 |
uplink_port: 3 |
| 624 |
order: 0 |
| 625 |
eth_network_policy_name: "vm-network-policy" |
| 626 |
eth_qos_policy_name: "vm-qos-policy" |
| 627 |
eth_adapter_policy_name: "vm-adapter-policy" |
| 628 |
connection_type: "vmq" |
| 629 |
vmq_settings: |
| 630 |
enabled: true |
| 631 |
multi_queue_support: true |
| 632 |
num_sub_vnics: 64 |
| 633 |
vmmq_adapter_policy_name: "vmmq-adapter-policy" |
| 634 |
state: present |
| 635 |
|
| 636 |
- name: Create a LAN Connectivity Policy with SR-IOV vNIC |
| 637 |
cisco.intersight.intersight_lan_connectivity_policy: |
| 638 |
api_private_key: "{{ api_private_key }}" |
| 639 |
api_key_id: "{{ api_key_id }}" |
| 640 |
name: "sriov-lan-policy" |
| 641 |
description: "Policy with SR-IOV configuration" |
| 642 |
target_platform: "Standalone" |
| 643 |
vnics: |
| 644 |
- name: "sriov-eth0" |
| 645 |
placement_slot_id: "14" |
| 646 |
pci_link: 0 |
| 647 |
uplink_port: 1 |
| 648 |
order: 0 |
| 649 |
eth_network_policy_name: "sriov-network-policy" |
| 650 |
eth_qos_policy_name: "sriov-qos-policy" |
| 651 |
eth_adapter_policy_name: "sriov-adapter-policy" |
| 652 |
connection_type: "sriov" |
| 653 |
sriov_settings: |
| 654 |
enabled: true |
| 655 |
vf_count: 64 |
| 656 |
rx_count_per_vf: 4 |
| 657 |
tx_count_per_vf: 1 |
| 658 |
comp_count_per_vf: 5 |
| 659 |
int_count_per_vf: 8 |
| 660 |
state: present |
| 661 |
|
| 662 |
- name: Create a LAN Connectivity Policy with custom CDN values |
| 663 |
cisco.intersight.intersight_lan_connectivity_policy: |
| 664 |
api_private_key: "{{ api_private_key }}" |
| 665 |
api_key_id: "{{ api_key_id }}" |
| 666 |
name: "custom-cdn-lan-policy" |
| 667 |
description: "Policy with custom CDN values" |
| 668 |
target_platform: "Standalone" |
| 669 |
vnics: |
| 670 |
- name: "mgmt-nic" |
| 671 |
placement_slot_id: "1" |
| 672 |
pci_link: 0 |
| 673 |
uplink_port: 0 |
| 674 |
order: 0 |
| 675 |
cdn_source: "user" |
| 676 |
cdn_value: "Management-NIC" |
| 677 |
eth_network_policy_name: "mgmt-network-policy" |
| 678 |
eth_qos_policy_name: "mgmt-qos-policy" |
| 679 |
eth_adapter_policy_name: "mgmt-adapter-policy" |
| 680 |
connection_type: "none" |
| 681 |
state: present |
| 682 |
|
| 683 |
- name: Update LAN connectivity policy - manage vNIC states |
| 684 |
cisco.intersight.intersight_lan_connectivity_policy: |
| 685 |
api_private_key: "{{ api_private_key }}" |
| 686 |
api_key_id: "{{ api_key_id }}" |
| 687 |
organization: "default" |
| 688 |
name: "mixed-vnic-states-policy" |
| 689 |
description: "Policy demonstrating vNIC state management" |
| 690 |
target_platform: "Standalone" |
| 691 |
vnics: |
| 692 |
- name: "eth0" |
| 693 |
placement_slot_id: "1" |
| 694 |
pci_link: 0 |
| 695 |
uplink_port: 0 |
| 696 |
order: 0 |
| 697 |
eth_network_policy_name: "production-network" |
| 698 |
eth_qos_policy_name: "standard-qos" |
| 699 |
eth_adapter_policy_name: "standard-adapter" |
| 700 |
connection_type: "none" |
| 701 |
state: present |
| 702 |
- name: "eth1-old" |
| 703 |
state: absent |
| 704 |
- name: "eth2-new" |
| 705 |
placement_slot_id: "3" |
| 706 |
pci_link: 0 |
| 707 |
uplink_port: 1 |
| 708 |
order: 1 |
| 709 |
eth_network_policy_name: "production-network" |
| 710 |
eth_qos_policy_name: "standard-qos" |
| 711 |
eth_adapter_policy_name: "standard-adapter" |
| 712 |
connection_type: "vmq" |
| 713 |
vmq_settings: |
| 714 |
enabled: true |
| 715 |
multi_queue_support: false |
| 716 |
num_interrupts: 16 |
| 717 |
num_vmqs: 4 |
| 718 |
state: present |
| 719 |
state: present |
| 720 |
|
| 721 |
- name: Delete a LAN Connectivity Policy |
| 722 |
cisco.intersight.intersight_lan_connectivity_policy: |
| 723 |
api_private_key: "{{ api_private_key }}" |
| 724 |
api_key_id: "{{ api_key_id }}" |
| 725 |
name: "old-lan-policy" |
| 726 |
state: absent |
| 727 |
''' |
| 728 |
|
| 729 |
RETURN = r''' |
| 730 |
api_response: |
| 731 |
description: The API response output returned by the specified resource. |
| 732 |
returned: always |
| 733 |
type: dict |
| 734 |
sample: |
| 735 |
"api_response": { |
| 736 |
"Name": "test-lan-policy", |
| 737 |
"ObjectType": "vnic.LanConnectivityPolicy", |
| 738 |
"TargetPlatform": "Standalone", |
| 739 |
"Tags": [ |
| 740 |
{ |
| 741 |
"Key": "Environment", |
| 742 |
"Value": "Production" |
| 743 |
} |
| 744 |
], |
| 745 |
"vNICs": [ |
| 746 |
{ |
| 747 |
"Name": "eth0", |
| 748 |
"ObjectType": "vnic.EthIf", |
| 749 |
"Order": 0, |
| 750 |
"Placement": { |
| 751 |
"Id": "1" |
| 752 |
} |
| 753 |
} |
| 754 |
] |
| 755 |
} |
| 756 |
''' |
| 757 |
|
| 758 |
|
| 759 |
from ansible.module_utils.basic import AnsibleModule |
| 760 |
from ansible_collections.cisco.intersight.plugins.module_utils.intersight import IntersightModule, intersight_argument_spec |
| 761 |
from ansible_collections.cisco.intersight.plugins.module_utils.intersight_vnic_utils import ( |
| 762 |
validate_cdn_config, validate_usnic_settings, validate_vmq_settings, validate_sriov_settings, |
| 763 |
build_cdn_config, build_connection_settings, resolve_policy_moids_from_mappings, |
| 764 |
get_common_policy_mappings, get_iscsi_boot_policy_mapping, get_fabric_network_policy_mappings, |
| 765 |
get_mac_pool_policy_mapping, get_common_settings_argument_spec |
| 766 |
) |
| 767 |
|
| 768 |
|
| 769 |
def validate_fi_attached_params(module): |
| 770 |
""" |
| 771 |
Validate FIAttached specific parameters |
| 772 |
""" |
| 773 |
iqn_allocation_type = module.params.get('iqn_allocation_type') |
| 774 |
static_iqn_name = module.params.get('static_iqn_name') |
| 775 |
iqn_pool_name = module.params.get('iqn_pool_name') |
| 776 |
|
| 777 |
# Validate IQN allocation type requirements |
| 778 |
if iqn_allocation_type == 'Static' and not static_iqn_name: |
| 779 |
module.fail_json(msg="static_iqn_name is required when iqn_allocation_type is 'Static'") |
| 780 |
|
| 781 |
if iqn_allocation_type == 'Pool' and not iqn_pool_name: |
| 782 |
module.fail_json(msg="iqn_pool_name is required when iqn_allocation_type is 'Pool'") |
| 783 |
|
| 784 |
if iqn_allocation_type != 'Static' and static_iqn_name: |
| 785 |
module.fail_json(msg="static_iqn_name should only be specified when iqn_allocation_type is 'Static'") |
| 786 |
|
| 787 |
if iqn_allocation_type != 'Pool' and iqn_pool_name: |
| 788 |
module.fail_json(msg="iqn_pool_name should only be specified when iqn_allocation_type is 'Pool'") |
| 789 |
|
| 790 |
|
| 791 |
def validate_fi_attached_vnic_config(module, vnic_config): |
| 792 |
""" |
| 793 |
Validate FIAttached specific vNIC configuration |
| 794 |
""" |
| 795 |
vnic_name = vnic_config.get('name', 'unknown') |
| 796 |
mac_address_type = vnic_config.get('mac_address_type', 'pool') |
| 797 |
mac_pool_name = vnic_config.get('mac_pool_name') |
| 798 |
static_mac_address = vnic_config.get('static_mac_address') |
| 799 |
|
| 800 |
# Validate MAC address configuration |
| 801 |
if mac_address_type == 'pool' and not mac_pool_name: |
| 802 |
module.fail_json(msg=f"mac_pool_name is required when mac_address_type is 'pool' for vNIC '{vnic_name}'") |
| 803 |
|
| 804 |
if mac_address_type == 'static' and not static_mac_address: |
| 805 |
module.fail_json(msg=f"static_mac_address is required when mac_address_type is 'static' for vNIC '{vnic_name}'") |
| 806 |
|
| 807 |
if mac_address_type != 'pool' and mac_pool_name: |
| 808 |
module.fail_json(msg=f"mac_pool_name should only be specified when mac_address_type is 'pool' for vNIC '{vnic_name}'") |
| 809 |
|
| 810 |
if mac_address_type != 'static' and static_mac_address: |
| 811 |
module.fail_json(msg=f"static_mac_address should only be specified when mac_address_type is 'static' for vNIC '{vnic_name}'") |
| 812 |
|
| 813 |
# Validate required FIAttached fields |
| 814 |
fabric_eth_network_group_policy_name = vnic_config.get('fabric_eth_network_group_policy_name') |
| 815 |
fabric_eth_network_control_policy_name = vnic_config.get('fabric_eth_network_control_policy_name') |
| 816 |
|
| 817 |
if not fabric_eth_network_group_policy_name: |
| 818 |
module.fail_json(msg=f"fabric_eth_network_group_policy_name is required for attached vNIC '{vnic_name}'") |
| 819 |
|
| 820 |
if not fabric_eth_network_control_policy_name: |
| 821 |
module.fail_json(msg=f"fabric_eth_network_control_policy_name is required for attached vNIC '{vnic_name}'") |
| 822 |
|
| 823 |
# Validate advanced placement configuration |
| 824 |
validate_fi_attached_placement_config(module, vnic_config) |
| 825 |
|
| 826 |
|
| 827 |
def validate_fi_attached_placement_config(module, vnic_config): |
| 828 |
""" |
| 829 |
Validate FIAttached placement configuration |
| 830 |
""" |
| 831 |
vnic_name = vnic_config.get('name', 'unknown') |
| 832 |
auto_vnic_placement_enabled = vnic_config.get('auto_vnic_placement_enabled', False) |
| 833 |
|
| 834 |
# Skip advanced placement validation if auto placement is enabled |
| 835 |
if auto_vnic_placement_enabled: |
| 836 |
return |
| 837 |
|
| 838 |
auto_slot_id = vnic_config.get('auto_slot_id', True) |
| 839 |
placement_slot_id = vnic_config.get('placement_slot_id') |
| 840 |
auto_pci_link = vnic_config.get('auto_pci_link', True) |
| 841 |
pci_link_assignment_mode = vnic_config.get('pci_link_assignment_mode') |
| 842 |
pci_link = vnic_config.get('pci_link') |
| 843 |
|
| 844 |
# Validate slot ID configuration |
| 845 |
if not auto_slot_id and not placement_slot_id: |
| 846 |
module.fail_json(msg=f"placement_slot_id is required when auto_slot_id is false for vNIC '{vnic_name}'") |
| 847 |
|
| 848 |
if auto_slot_id and placement_slot_id: |
| 849 |
module.fail_json(msg=f"placement_slot_id should not be specified when auto_slot_id is true for vNIC '{vnic_name}'") |
| 850 |
|
| 851 |
# Validate PCI link configuration |
| 852 |
if not auto_pci_link and not pci_link_assignment_mode: |
| 853 |
module.fail_json(msg=f"pci_link_assignment_mode is required when auto_pci_link is false for vNIC '{vnic_name}'") |
| 854 |
|
| 855 |
if auto_pci_link and pci_link_assignment_mode: |
| 856 |
module.fail_json(msg=f"pci_link_assignment_mode should not be specified when auto_pci_link is true for vNIC '{vnic_name}'") |
| 857 |
|
| 858 |
# Validate PCI link when using Custom mode |
| 859 |
if pci_link_assignment_mode == 'Custom' and pci_link is None: |
| 860 |
module.fail_json(msg=f"pci_link is required when pci_link_assignment_mode is 'Custom' for vNIC '{vnic_name}'") |
| 861 |
|
| 862 |
if pci_link_assignment_mode != 'Custom' and pci_link is not None and pci_link != 0: |
| 863 |
module.fail_json(msg=f"pci_link should only be specified when pci_link_assignment_mode is 'Custom' for vNIC '{vnic_name}'") |
| 864 |
|
| 865 |
|
| 866 |
def validate_standalone_vnic_config(module, vnic_config): |
| 867 |
""" |
| 868 |
Validate Standalone specific vNIC configuration |
| 869 |
""" |
| 870 |
vnic_name = vnic_config.get('name', 'unknown') |
| 871 |
|
| 872 |
# Validate required Standalone fields |
| 873 |
placement_slot_id = vnic_config.get('placement_slot_id') |
| 874 |
eth_network_policy_name = vnic_config.get('eth_network_policy_name') |
| 875 |
|
| 876 |
if not placement_slot_id: |
| 877 |
module.fail_json(msg=f"placement_slot_id is required for Standalone vNIC '{vnic_name}'") |
| 878 |
|
| 879 |
if not eth_network_policy_name: |
| 880 |
module.fail_json(msg=f"eth_network_policy_name is required for Standalone vNIC '{vnic_name}'") |
| 881 |
|
| 882 |
|
| 883 |
def get_vnic_policy_mappings(target_platform, vnic_config): |
| 884 |
""" |
| 885 |
Get policy mappings for vNIC configuration based on target platform. |
| 886 |
""" |
| 887 |
# Start with common policies |
| 888 |
policy_mappings = get_common_policy_mappings() |
| 889 |
|
| 890 |
# Platform-specific policies |
| 891 |
if target_platform == 'FIAttached': |
| 892 |
# Add fabric network policies |
| 893 |
policy_mappings.update(get_fabric_network_policy_mappings()) |
| 894 |
|
| 895 |
# MAC pool for FIAttached when using pool type |
| 896 |
if vnic_config.get('mac_address_type', 'pool') == 'pool': |
| 897 |
policy_mappings.update(get_mac_pool_policy_mapping()) |
| 898 |
|
| 899 |
# iSCSI boot policy |
| 900 |
if vnic_config.get('iscsi_boot_policy_name'): |
| 901 |
policy_mappings.update(get_iscsi_boot_policy_mapping()) |
| 902 |
|
| 903 |
else: # Standalone server |
| 904 |
policy_mappings['eth_network_policy_name'] = ('/vnic/EthNetworkPolicies', 'EthNetworkPolicy', 'Ethernet Network Policy') |
| 905 |
|
| 906 |
return policy_mappings |
| 907 |
|
| 908 |
|
| 909 |
def resolve_vnic_policy_moids(intersight, policy_cache, module, vnic_config, target_platform): |
| 910 |
""" |
| 911 |
Resolve all policy MOIDs for a vNIC configuration based on target platform. |
| 912 |
""" |
| 913 |
policy_mappings = get_vnic_policy_mappings(target_platform, vnic_config) |
| 914 |
organization_name = module.params['organization'] |
| 915 |
return resolve_policy_moids_from_mappings(intersight, policy_cache, module, vnic_config, policy_mappings, organization_name) |
| 916 |
|
| 917 |
|
| 918 |
def build_vnic_api_body(intersight, policy_cache, module, vnic_config, lan_connectivity_policy_moid): |
| 919 |
""" |
| 920 |
Build vNIC API body for API call |
| 921 |
""" |
| 922 |
target_platform = module.params.get('target_platform') |
| 923 |
|
| 924 |
if target_platform == 'FIAttached': |
| 925 |
return build_fi_attached_vnic_api_body(intersight, policy_cache, module, vnic_config, lan_connectivity_policy_moid) |
| 926 |
else: |
| 927 |
return build_standalone_vnic_api_body(intersight, policy_cache, module, vnic_config, lan_connectivity_policy_moid) |
| 928 |
|
| 929 |
|
| 930 |
def build_standalone_vnic_api_body(intersight, policy_cache, module, vnic_config, lan_connectivity_policy_moid): |
| 931 |
""" |
| 932 |
Build Standalone vNIC API body for Intersight API call |
| 933 |
""" |
| 934 |
# Base vNIC configuration for Standalone |
| 935 |
vnic_api_body = { |
| 936 |
'Name': vnic_config['name'], |
| 937 |
'Placement': { |
| 938 |
'Id': vnic_config['placement_slot_id'], |
| 939 |
'Uplink': vnic_config.get('uplink_port', 0), |
| 940 |
'PciLink': vnic_config.get('pci_link', 0) |
| 941 |
}, |
| 942 |
'Order': vnic_config.get('order', 0), |
| 943 |
'LanConnectivityPolicy': lan_connectivity_policy_moid |
| 944 |
} |
| 945 |
|
| 946 |
# Add common CDN configuration |
| 947 |
vnic_api_body['Cdn'] = build_cdn_config(vnic_config) |
| 948 |
|
| 949 |
# Resolve and add policy MOIDs |
| 950 |
policy_moids = resolve_vnic_policy_moids(intersight, policy_cache, module, vnic_config, 'Standalone') |
| 951 |
vnic_api_body.update(policy_moids) |
| 952 |
|
| 953 |
# Add common connection type settings |
| 954 |
organization_name = module.params['organization'] |
| 955 |
connection_settings = build_connection_settings(intersight, policy_cache, module, vnic_config, organization_name) |
| 956 |
vnic_api_body.update(connection_settings) |
| 957 |
|
| 958 |
return vnic_api_body |
| 959 |
|
| 960 |
|
| 961 |
def build_fi_attached_vnic_api_body(intersight, policy_cache, module, vnic_config, lan_connectivity_policy_moid): |
| 962 |
""" |
| 963 |
Build FIAttached vNIC API body for Intersight API call |
| 964 |
""" |
| 965 |
# Base vNIC configuration for FIAttached |
| 966 |
# Map lowercase user input to API format |
| 967 |
mac_address_type = vnic_config.get('mac_address_type', 'pool') |
| 968 |
api_mac_address_type = 'STATIC' if mac_address_type == 'static' else 'POOL' |
| 969 |
auto_vnic_placement_enabled = vnic_config.get('auto_vnic_placement_enabled', False) |
| 970 |
|
| 971 |
vnic_api_body = { |
| 972 |
'Name': vnic_config['name'], |
| 973 |
'MacAddressType': api_mac_address_type, |
| 974 |
'FailoverEnabled': vnic_config.get('failover_enabled', False), |
| 975 |
'LanConnectivityPolicy': lan_connectivity_policy_moid |
| 976 |
} |
| 977 |
|
| 978 |
# Handle placement based on auto_vnic_placement_enabled |
| 979 |
if auto_vnic_placement_enabled: |
| 980 |
vnic_api_body['Placement'] = { |
| 981 |
'SwitchId': vnic_config.get('switch_id', 'A'), |
| 982 |
'AutoSlotId': True, |
| 983 |
'AutoPciLink': True |
| 984 |
} |
| 985 |
else: |
| 986 |
# Full placement control |
| 987 |
placement = { |
| 988 |
'SwitchId': vnic_config.get('switch_id', 'A'), |
| 989 |
'AutoSlotId': vnic_config.get('auto_slot_id', True), |
| 990 |
'AutoPciLink': vnic_config.get('auto_pci_link', True) |
| 991 |
} |
| 992 |
|
| 993 |
# Add slot ID if auto_slot_id is disabled |
| 994 |
if not vnic_config.get('auto_slot_id', True): |
| 995 |
placement['Id'] = vnic_config['placement_slot_id'] |
| 996 |
|
| 997 |
# Add PCI link configuration if auto_pci_link is disabled |
| 998 |
if not vnic_config.get('auto_pci_link', True): |
| 999 |
placement['PciLinkAssignmentMode'] = vnic_config['pci_link_assignment_mode'] |
| 1000 |
if vnic_config['pci_link_assignment_mode'] == 'Custom': |
| 1001 |
placement['PciLink'] = vnic_config.get('pci_link', 0) |
| 1002 |
|
| 1003 |
vnic_api_body['Placement'] = placement |
| 1004 |
vnic_api_body['Order'] = vnic_config.get('order', 0) |
| 1005 |
|
| 1006 |
# Add common CDN configuration |
| 1007 |
vnic_api_body['Cdn'] = build_cdn_config(vnic_config) |
| 1008 |
|
| 1009 |
# Add static MAC address if using static type |
| 1010 |
if mac_address_type == 'static': |
| 1011 |
vnic_api_body['StaticMacAddress'] = vnic_config['static_mac_address'] |
| 1012 |
|
| 1013 |
# Resolve and add policy MOIDs |
| 1014 |
policy_moids = resolve_vnic_policy_moids(intersight, policy_cache, module, vnic_config, 'FIAttached') |
| 1015 |
vnic_api_body.update(policy_moids) |
| 1016 |
|
| 1017 |
# Add common connection type settings |
| 1018 |
organization_name = module.params['organization'] |
| 1019 |
connection_settings = build_connection_settings(intersight, policy_cache, module, vnic_config, organization_name) |
| 1020 |
vnic_api_body.update(connection_settings) |
| 1021 |
|
| 1022 |
# Add pin group name if specified |
| 1023 |
if vnic_config.get('pin_group_name'): |
| 1024 |
vnic_api_body['PinGroupName'] = vnic_config['pin_group_name'] |
| 1025 |
|
| 1026 |
return vnic_api_body |
| 1027 |
|
| 1028 |
|
| 1029 |
def validate_input(module): |
| 1030 |
""" |
| 1031 |
Validate module input parameters |
| 1032 |
""" |
| 1033 |
# Validate FIAttached specific requirements |
| 1034 |
target_platform = module.params.get('target_platform') |
| 1035 |
if target_platform == 'FIAttached': |
| 1036 |
validate_fi_attached_params(module) |
| 1037 |
|
| 1038 |
# Validate vNIC configurations |
| 1039 |
vnics = module.params.get('vnics', []) |
| 1040 |
for vnic_config in vnics: |
| 1041 |
vnic_name = vnic_config.get('name') |
| 1042 |
vnic_state = vnic_config.get('state', 'present') |
| 1043 |
|
| 1044 |
# Only validate present vNICs - absent vNICs only need name |
| 1045 |
if vnic_state == 'present': |
| 1046 |
# Validate common required fields |
| 1047 |
required_fields = ['eth_qos_policy_name', 'eth_adapter_policy_name'] |
| 1048 |
for field in required_fields: |
| 1049 |
if not vnic_config.get(field): |
| 1050 |
module.fail_json(msg=f"{field} is required when vNIC state is 'present' for vNIC '{vnic_name}'") |
| 1051 |
|
| 1052 |
# Validate target platform specific fields |
| 1053 |
target_platform = module.params.get('target_platform') |
| 1054 |
if target_platform == 'FIAttached': |
| 1055 |
validate_fi_attached_vnic_config(module, vnic_config) |
| 1056 |
else: |
| 1057 |
validate_standalone_vnic_config(module, vnic_config) |
| 1058 |
|
| 1059 |
# Validate CDN configuration |
| 1060 |
validate_cdn_config(module, vnic_config) |
| 1061 |
|
| 1062 |
connection_type = vnic_config.get('connection_type', 'none') |
| 1063 |
|
| 1064 |
# Validate connection type specific settings |
| 1065 |
vnic_name = vnic_config.get('name', 'unknown') |
| 1066 |
if connection_type == 'usnic': |
| 1067 |
usnic_settings = vnic_config.get('usnic_settings') |
| 1068 |
validate_usnic_settings(module, usnic_settings, vnic_name) |
| 1069 |
elif connection_type == 'vmq': |
| 1070 |
vmq_settings = vnic_config.get('vmq_settings', {}) |
| 1071 |
validate_vmq_settings(module, vmq_settings, vnic_name) |
| 1072 |
elif connection_type == 'sriov': |
| 1073 |
sriov_settings = vnic_config.get('sriov_settings', {}) |
| 1074 |
validate_sriov_settings(module, sriov_settings, vnic_name) |
| 1075 |
|
| 1076 |
|
| 1077 |
def main(): |
| 1078 |
# Define vNIC options |
| 1079 |
vnic_options = dict( |
| 1080 |
name=dict(type='str', required=True), |
| 1081 |
state=dict(type='str', choices=['present', 'absent'], default='present'), |
| 1082 |
placement_slot_id=dict(type='str'), |
| 1083 |
pci_link=dict(type='int', choices=[0, 1], default=0), |
| 1084 |
uplink_port=dict(type='int', choices=[0, 1, 2, 3], default=0), |
| 1085 |
order=dict(type='int', default=0), |
| 1086 |
eth_network_policy_name=dict(type='str'), |
| 1087 |
eth_qos_policy_name=dict(type='str'), |
| 1088 |
eth_adapter_policy_name=dict(type='str'), |
| 1089 |
mac_address_type=dict(type='str', choices=['pool', 'static'], default='pool'), |
| 1090 |
static_mac_address=dict(type='str'), |
| 1091 |
auto_slot_id=dict(type='bool', default=True), |
| 1092 |
auto_pci_link=dict(type='bool', default=True), |
| 1093 |
pci_link_assignment_mode=dict(type='str', choices=['Custom', 'Load-Balanced']), |
| 1094 |
auto_vnic_placement_enabled=dict(type='bool', default=False), |
| 1095 |
pin_group_name=dict(type='str'), |
| 1096 |
) |
| 1097 |
# Add connection settings argument specs |
| 1098 |
vnic_options.update(get_common_settings_argument_spec()) |
| 1099 |
|
| 1100 |
argument_spec = intersight_argument_spec.copy() |
| 1101 |
argument_spec.update( |
| 1102 |
state=dict(type='str', choices=['present', 'absent'], default='present'), |
| 1103 |
organization=dict(type='str', default='default'), |
| 1104 |
name=dict(type='str', required=True), |
| 1105 |
description=dict(type='str', aliases=['descr']), |
| 1106 |
tags=dict(type='list', elements='dict'), |
| 1107 |
target_platform=dict(type='str', choices=['Standalone', 'FIAttached'], default='Standalone'), |
| 1108 |
azure_qos_enabled=dict(type='bool', default=False), |
| 1109 |
iqn_allocation_type=dict(type='str', choices=['None', 'Pool', 'Static'], default='None'), |
| 1110 |
placement_mode=dict(type='str', choices=['custom', 'auto'], default='custom'), |
| 1111 |
iqn_pool_name=dict(type='str'), |
| 1112 |
static_iqn_name=dict(type='str'), |
| 1113 |
vnics=dict(type='list', elements='dict', options=vnic_options) |
| 1114 |
) |
| 1115 |
|
| 1116 |
required_if = [ |
| 1117 |
['state', 'present', ['vnics']], |
| 1118 |
] |
| 1119 |
|
| 1120 |
module = AnsibleModule( |
| 1121 |
argument_spec, |
| 1122 |
required_if=required_if, |
| 1123 |
supports_check_mode=True, |
| 1124 |
) |
| 1125 |
|
| 1126 |
if module.params['state'] == 'present': |
| 1127 |
validate_input(module) |
| 1128 |
|
| 1129 |
intersight = IntersightModule(module) |
| 1130 |
intersight.result['api_response'] = {} |
| 1131 |
intersight.result['trace_id'] = '' |
| 1132 |
|
| 1133 |
# Resource path used to configure policy |
| 1134 |
resource_path = '/vnic/LanConnectivityPolicies' |
| 1135 |
# Define API body used in compares or create |
| 1136 |
intersight.api_body = { |
| 1137 |
'Organization': { |
| 1138 |
'Name': intersight.module.params['organization'], |
| 1139 |
}, |
| 1140 |
'Name': intersight.module.params['name'] |
| 1141 |
} |
| 1142 |
|
| 1143 |
if intersight.module.params['state'] == 'present': |
| 1144 |
intersight.set_tags_and_description() |
| 1145 |
|
| 1146 |
target_platform = intersight.module.params['target_platform'] |
| 1147 |
api_target_platform = 'FIAttached' if target_platform == 'FIAttached' else 'Standalone' |
| 1148 |
intersight.api_body['TargetPlatform'] = api_target_platform |
| 1149 |
|
| 1150 |
# Add FIAttached-specific parameters |
| 1151 |
if intersight.module.params['target_platform'] == 'FIAttached': |
| 1152 |
intersight.api_body['AzureQosEnabled'] = intersight.module.params['azure_qos_enabled'] |
| 1153 |
intersight.api_body['IqnAllocationType'] = intersight.module.params['iqn_allocation_type'] |
| 1154 |
intersight.api_body['PlacementMode'] = intersight.module.params['placement_mode'] |
| 1155 |
|
| 1156 |
# Resolve IQN pool MOID if specified |
| 1157 |
if intersight.module.params['iqn_pool_name']: |
| 1158 |
iqn_pool_moid = intersight.get_moid_by_name_and_org( |
| 1159 |
resource_path='/iqnpool/Pools', |
| 1160 |
resource_name=intersight.module.params['iqn_pool_name'], |
| 1161 |
organization_name=intersight.module.params['organization'] |
| 1162 |
) |
| 1163 |
if not iqn_pool_moid: |
| 1164 |
intersight.module.fail_json(msg=f"IQN Pool '{intersight.module.params['iqn_pool_name']}' not found in organization ' \ |
| 1165 |
{intersight.module.params['organization']}'") |
| 1166 |
intersight.api_body['IqnPool'] = iqn_pool_moid |
| 1167 |
|
| 1168 |
if intersight.module.params['static_iqn_name']: |
| 1169 |
intersight.api_body['StaticIqnName'] = intersight.module.params['static_iqn_name'] |
| 1170 |
|
| 1171 |
intersight.configure_policy_or_profile(resource_path=resource_path) |
| 1172 |
|
| 1173 |
# Save the LAN connectivity policy response |
| 1174 |
lan_connectivity_policy_response = intersight.result['api_response'] |
| 1175 |
|
| 1176 |
lan_connectivity_policy_moid = None |
| 1177 |
if intersight.module.params['state'] == 'present' and lan_connectivity_policy_response: |
| 1178 |
lan_connectivity_policy_moid = lan_connectivity_policy_response.get('Moid') |
| 1179 |
|
| 1180 |
# Process vNICs |
| 1181 |
vnics_response = [] |
| 1182 |
if intersight.module.params['state'] == 'present' and intersight.module.params.get('vnics'): |
| 1183 |
# Cache for policy MOIDs to avoid redundant API calls |
| 1184 |
policy_cache = {} |
| 1185 |
|
| 1186 |
for vnic_config in intersight.module.params['vnics']: |
| 1187 |
vnic_state = vnic_config.get('state', 'present') |
| 1188 |
|
| 1189 |
# Only build API body for present vNICs |
| 1190 |
if vnic_state == 'present': |
| 1191 |
# Build vNIC API body using helper function |
| 1192 |
vnic_api_body = build_vnic_api_body( |
| 1193 |
intersight, policy_cache, module, vnic_config, lan_connectivity_policy_moid |
| 1194 |
) |
| 1195 |
intersight.api_body = vnic_api_body |
| 1196 |
|
| 1197 |
# Configure the vNIC (create/update/delete) |
| 1198 |
resource_path = '/vnic/EthIfs' |
| 1199 |
# Filter by both vNIC name AND LAN Connectivity Policy to avoid affecting vNICs in other policies |
| 1200 |
custom_filter = f"Name eq '{vnic_config['name']}' and LanConnectivityPolicy.Moid eq '{lan_connectivity_policy_moid}'" |
| 1201 |
intersight.configure_secondary_resource( |
| 1202 |
resource_path=resource_path, |
| 1203 |
state=vnic_state, |
| 1204 |
custom_filter=custom_filter |
| 1205 |
) |
| 1206 |
|
| 1207 |
# Save the vNIC response only if it's present |
| 1208 |
if vnic_state == 'present': |
| 1209 |
vnics_response.append(intersight.result['api_response']) |
| 1210 |
|
| 1211 |
# Combine LAN connectivity policy and vNICs in the main response |
| 1212 |
if lan_connectivity_policy_response: |
| 1213 |
lan_connectivity_policy_response['vNICs'] = vnics_response |
| 1214 |
intersight.result['api_response'] = lan_connectivity_policy_response |
| 1215 |
|
| 1216 |
module.exit_json(**intersight.result) |
| 1217 |
|
| 1218 |
|
| 1219 |
if __name__ == '__main__': |
| 1220 |
main() |