| 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_port_policy |
| 16 |
short_description: Manage Port Policies for Cisco Intersight |
| 17 |
description: |
| 18 |
- Create, update, and delete Port Policies on Cisco Intersight. |
| 19 |
- Manage port configurations including breakout ports, server roles, uplink port channels, and LAN pin groups. |
| 20 |
- Supports various device models with model-specific port configurations. |
| 21 |
- Port policies define the configuration of unified ports on fabric interconnects. |
| 22 |
- For more information see L(Cisco Intersight,https://intersight.com/apidocs/fabric/PortPolicies/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 Port 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 Port 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 |
device_model: |
| 58 |
description: |
| 59 |
- The device model for which the Port Policy is intended. |
| 60 |
- Different models support different port configurations and capabilities. |
| 61 |
- Required when C(state=present). |
| 62 |
- "UCS-FI-6454: 54 ports (1-54), FC ports 1-16, breakout ports 49-54" |
| 63 |
- "UCS-FI-64108: 108 ports (1-108), FC ports 1-16, breakout ports 97-108, 1Gbps only on ports 89-96, 40/100Gbps only on ports 97-108" |
| 64 |
- "UCS-FI-6536: 36 ports (1-36), FC only via breakout ports 33-36, all ports support breakout, 1Gbps only on ports 9-10" |
| 65 |
- "UCS-FI-6664: 64 ports (1-64), FC ports 25-40, no breakout support, 40/100Gbps only on ports 1-24 and 41-64" |
| 66 |
- "UCSX-S9108-100G: 8 ports (1-8), FC only via breakout ports 1-2, 1Gbps only on ports 7-8" |
| 67 |
type: str |
| 68 |
choices: ['UCS-FI-6454', 'UCS-FI-64108', 'UCS-FI-6536', 'UCS-FI-6664', 'UCSX-S9108-100G'] |
| 69 |
fc_port_mode: |
| 70 |
description: |
| 71 |
- Configure Fibre Channel port mode for a range of ports. |
| 72 |
- This converts Ethernet ports to Fibre Channel ports. |
| 73 |
- Only one FC port mode configuration is allowed per policy. |
| 74 |
- Device-specific FC port ranges apply (see device_model documentation). |
| 75 |
- For UCS-FI-6536 and UCSX-S9108-100G, fc_port_mode is not supported. |
| 76 |
- FC functionality is available through breakout ports only. If specified, this parameter will be ignored with a warning. |
| 77 |
type: dict |
| 78 |
suboptions: |
| 79 |
port_id_start: |
| 80 |
description: |
| 81 |
- Starting port ID for FC mode configuration. |
| 82 |
- For UCS-FI-6454/64108, must be 1 (minimum FC port). |
| 83 |
- For UCS-FI-6664, must be 25 (minimum FC port). |
| 84 |
- Not applicable for UCS-FI-6536 and UCSX-S9108-100G (use breakout ports for FC). |
| 85 |
type: int |
| 86 |
default: 1 |
| 87 |
port_id_end: |
| 88 |
description: |
| 89 |
- Ending port ID for FC mode configuration. |
| 90 |
- Valid values depend on device model and supported FC range. |
| 91 |
- For UCS-FI-6454/64108, valid values are 4, 8, 12, or 16. |
| 92 |
- For UCS-FI-6664, must be within range 25-40. |
| 93 |
- Not applicable for UCS-FI-6536 and UCSX-S9108-100G (use breakout ports for FC). |
| 94 |
type: int |
| 95 |
required: true |
| 96 |
state: |
| 97 |
description: |
| 98 |
- Whether to enable or disable FC port mode. |
| 99 |
type: str |
| 100 |
choices: ['present', 'absent'] |
| 101 |
default: present |
| 102 |
breakout_ports: |
| 103 |
description: |
| 104 |
- List of breakout port configurations. |
| 105 |
- Breakout ports allow splitting a high-speed port into multiple lower-speed ports. |
| 106 |
- Device-specific breakout support applies (see device_model documentation). |
| 107 |
- UCS-FI-6664 does not support breakout ports at all. |
| 108 |
type: list |
| 109 |
elements: dict |
| 110 |
suboptions: |
| 111 |
port_id: |
| 112 |
description: |
| 113 |
- Port ID to configure for breakout. |
| 114 |
- This port will be split into multiple sub-ports (e.g., '49/1', '49/2', '49/3', '49/4'). |
| 115 |
- Must be within the device's supported breakout port range. |
| 116 |
- "UCS-FI-6454: ports 49-54 (Ethernet breakout only)" |
| 117 |
- "UCS-FI-64108: ports 97-108 (Ethernet breakout only)" |
| 118 |
- "UCS-FI-6536: ports 1-32 (Ethernet breakout only), ports 33-36 (FC breakout only)" |
| 119 |
- "UCSX-S9108-100G: ports 1-2 (FC breakout only), ports 3-6 (Ethernet breakout)" |
| 120 |
- "UCS-FI-6536: ports 1-36 (including FC ports)" |
| 121 |
- "UCSX-S9108-100G: ports 1-8" |
| 122 |
type: int |
| 123 |
required: true |
| 124 |
custom_mode: |
| 125 |
description: |
| 126 |
- Breakout mode for the ports. |
| 127 |
- Ethernet breakout modes (BreakoutEthernet10G, BreakoutEthernet25G) are supported on all models that support breakout. |
| 128 |
- FC breakout modes (BreakoutFibreChannel8G, BreakoutFibreChannel16G, BreakoutFibreChannel32G) are only supported on UCS-FI-6536 and UCSX-S9108-100G. |
| 129 |
type: str |
| 130 |
choices: ['BreakoutEthernet10G', 'BreakoutEthernet25G', 'BreakoutFibreChannel8G', 'BreakoutFibreChannel16G', 'BreakoutFibreChannel32G'] |
| 131 |
required: true |
| 132 |
state: |
| 133 |
description: |
| 134 |
- Whether to create/update or delete the breakout port configuration. |
| 135 |
type: str |
| 136 |
choices: ['present', 'absent'] |
| 137 |
default: present |
| 138 |
server_ports: |
| 139 |
description: |
| 140 |
- List of server port configurations. |
| 141 |
- Server ports connect to server adapters. |
| 142 |
type: list |
| 143 |
elements: dict |
| 144 |
suboptions: |
| 145 |
port_id: |
| 146 |
description: |
| 147 |
- Port ID to configure as server port. |
| 148 |
- Can be a regular port (e.g., 49) or aggregate port (e.g., '49/2'). |
| 149 |
- Aggregate ports use breakout port syntax where '49/2' means sub-port 2 of port 49. |
| 150 |
type: str |
| 151 |
required: true |
| 152 |
fec: |
| 153 |
description: |
| 154 |
- Forward Error Correction (FEC) mode. |
| 155 |
type: str |
| 156 |
choices: ['Auto', 'Cl74'] |
| 157 |
default: 'Auto' |
| 158 |
manual_numbering: |
| 159 |
description: |
| 160 |
- Enable manual numbering on the port. |
| 161 |
- When true, preferred_device_type defaults to 'Chassis' and preferred_device_id becomes required. |
| 162 |
- Cannot be true for aggregate ports (e.g., '49/1') as manual numbering is not supported on breakout ports. |
| 163 |
- Chassis and Rack Servers are numbered automatically as discovered. |
| 164 |
- Chassis are numbered separately from rack servers. Enable this to allow manual setting of discovered device IDs. |
| 165 |
type: bool |
| 166 |
default: false |
| 167 |
user_label: |
| 168 |
description: |
| 169 |
- User-defined label for the port. |
| 170 |
- User label must be between 0 and 128 alphanumeric characters. |
| 171 |
type: str |
| 172 |
preferred_device_type: |
| 173 |
description: |
| 174 |
- Preferred device type when manual chassis/server numbering is enabled. |
| 175 |
- Defaults to 'Chassis' when manual_numbering is true. |
| 176 |
type: str |
| 177 |
choices: ['Chassis', 'RackServer'] |
| 178 |
preferred_device_id: |
| 179 |
description: |
| 180 |
- Preferred device ID when manual chassis/server numbering is enabled. |
| 181 |
- Required when manual_numbering is true or when preferred_device_type is specified. |
| 182 |
type: int |
| 183 |
state: |
| 184 |
description: |
| 185 |
- Whether to create/update or delete the server port configuration. |
| 186 |
type: str |
| 187 |
choices: ['present', 'absent'] |
| 188 |
default: present |
| 189 |
ethernet_uplink_port_channels: |
| 190 |
description: |
| 191 |
- List of Ethernet uplink port channel configurations. |
| 192 |
- Port channels aggregate multiple Ethernet ports into a single logical link. |
| 193 |
type: list |
| 194 |
elements: dict |
| 195 |
suboptions: |
| 196 |
pc_id: |
| 197 |
description: |
| 198 |
- Port Channel Identifier. |
| 199 |
- Valid range is 1-256. |
| 200 |
type: int |
| 201 |
required: true |
| 202 |
admin_speed: |
| 203 |
description: |
| 204 |
- Administrative speed of the port channel. |
| 205 |
type: str |
| 206 |
choices: ['Auto', '1Gbps', '10Gbps', '25Gbps', '40Gbps', '100Gbps'] |
| 207 |
default: 'Auto' |
| 208 |
fec: |
| 209 |
description: |
| 210 |
- Forward Error Correction (FEC) mode. |
| 211 |
type: str |
| 212 |
choices: ['Auto', 'Off'] |
| 213 |
default: 'Auto' |
| 214 |
user_label: |
| 215 |
description: |
| 216 |
- User-defined label for the port channel. |
| 217 |
- User label must be between 0 and 128 alphanumeric characters. |
| 218 |
type: str |
| 219 |
ports: |
| 220 |
description: |
| 221 |
- List of Ethernet ports to include in the port channel. |
| 222 |
type: list |
| 223 |
elements: dict |
| 224 |
required: true |
| 225 |
suboptions: |
| 226 |
port_id: |
| 227 |
description: |
| 228 |
- Port ID to include in the port channel. |
| 229 |
- Can be a regular port (e.g., 36) or aggregate port (e.g., '49/2'). |
| 230 |
- Aggregate ports use breakout port syntax where '49/2' means sub-port 2 of port 49. |
| 231 |
type: str |
| 232 |
required: true |
| 233 |
eth_network_group_policy_names: |
| 234 |
description: |
| 235 |
- List of Ethernet Network Group Policy names to associate. |
| 236 |
- The Ethernet Network Group Policy specifies a set of VLANs to allow on the uplink port. |
| 237 |
- The specified VLAN set must be either identical or disjoint from those specified on other uplink interfaces. |
| 238 |
- Ensure that the VLANs are defined in the VLAN Policy and 'Auto Allow on Uplinks' option is disabled. |
| 239 |
- Note, default VLAN-1 is auto allowed and can be specified as the native VLAN. |
| 240 |
type: list |
| 241 |
elements: str |
| 242 |
flow_control_policy_name: |
| 243 |
description: |
| 244 |
- Flow Control Policy name to associate. |
| 245 |
type: str |
| 246 |
link_aggregation_policy_name: |
| 247 |
description: |
| 248 |
- Link Aggregation Policy name to associate. |
| 249 |
type: str |
| 250 |
link_control_policy_name: |
| 251 |
description: |
| 252 |
- Link Control Policy name to associate. |
| 253 |
type: str |
| 254 |
state: |
| 255 |
description: |
| 256 |
- Whether to create/update or delete the port channel. |
| 257 |
type: str |
| 258 |
choices: ['present', 'absent'] |
| 259 |
default: present |
| 260 |
fc_uplink_port_channels: |
| 261 |
description: |
| 262 |
- List of FC uplink port channel configurations. |
| 263 |
- Port channels aggregate multiple FC ports into a single logical link. |
| 264 |
- Only applicable when fc_port_mode is configured. |
| 265 |
type: list |
| 266 |
elements: dict |
| 267 |
suboptions: |
| 268 |
pc_id: |
| 269 |
description: |
| 270 |
- Port Channel Identifier. |
| 271 |
- Valid range is 1-256. |
| 272 |
type: int |
| 273 |
required: true |
| 274 |
admin_speed: |
| 275 |
description: |
| 276 |
- Administrative speed of the FC port channel. |
| 277 |
type: str |
| 278 |
choices: ['8Gbps', '16Gbps', '32Gbps'] |
| 279 |
default: '16Gbps' |
| 280 |
vsan_id: |
| 281 |
description: |
| 282 |
- VSAN ID associated to the FC port channel. |
| 283 |
type: int |
| 284 |
default: 1 |
| 285 |
user_label: |
| 286 |
description: |
| 287 |
- User-defined label for the port channel. |
| 288 |
- User label must be between 0 and 128 alphanumeric characters. |
| 289 |
type: str |
| 290 |
ports: |
| 291 |
description: |
| 292 |
- List of FC ports to include in the port channel. |
| 293 |
- Ports must be within the FC port mode range. |
| 294 |
type: list |
| 295 |
elements: dict |
| 296 |
required: true |
| 297 |
suboptions: |
| 298 |
port_id: |
| 299 |
description: |
| 300 |
- FC port ID to include in the port channel. |
| 301 |
type: str |
| 302 |
required: true |
| 303 |
state: |
| 304 |
description: |
| 305 |
- Whether to create/update or delete the port channel. |
| 306 |
type: str |
| 307 |
choices: ['present', 'absent'] |
| 308 |
default: present |
| 309 |
fcoe_uplink_port_channels: |
| 310 |
description: |
| 311 |
- List of FCoE uplink port channel configurations. |
| 312 |
- Port channels provide Fibre Channel over Ethernet connectivity. |
| 313 |
type: list |
| 314 |
elements: dict |
| 315 |
suboptions: |
| 316 |
pc_id: |
| 317 |
description: |
| 318 |
- Port Channel Identifier. |
| 319 |
- Valid range is 1-256. |
| 320 |
type: int |
| 321 |
required: true |
| 322 |
admin_speed: |
| 323 |
description: |
| 324 |
- Administrative speed of the port channel. |
| 325 |
type: str |
| 326 |
choices: ['Auto', '1Gbps', '10Gbps', '25Gbps', '40Gbps', '100Gbps'] |
| 327 |
default: 'Auto' |
| 328 |
fec: |
| 329 |
description: |
| 330 |
- Forward Error Correction (FEC) mode. |
| 331 |
type: str |
| 332 |
choices: ['Auto', 'Off'] |
| 333 |
default: 'Auto' |
| 334 |
user_label: |
| 335 |
description: |
| 336 |
- User-defined label for the port channel. |
| 337 |
- User label must be between 0 and 128 alphanumeric characters. |
| 338 |
type: str |
| 339 |
ports: |
| 340 |
description: |
| 341 |
- List of Ethernet ports to include in the port channel. |
| 342 |
type: list |
| 343 |
elements: dict |
| 344 |
required: true |
| 345 |
suboptions: |
| 346 |
port_id: |
| 347 |
description: |
| 348 |
- Port ID to include in the port channel. |
| 349 |
- Can be a regular port (e.g., 36) or aggregate port (e.g., '49/2'). |
| 350 |
- Aggregate ports use breakout port syntax where '49/2' means sub-port 2 of port 49. |
| 351 |
type: str |
| 352 |
required: true |
| 353 |
link_aggregation_policy_name: |
| 354 |
description: |
| 355 |
- Link Aggregation Policy name to associate. |
| 356 |
- The relationship to the Link Aggregation Policy. |
| 357 |
type: str |
| 358 |
link_control_policy_name: |
| 359 |
description: |
| 360 |
- Link Control Policy name to associate. |
| 361 |
type: str |
| 362 |
state: |
| 363 |
description: |
| 364 |
- Whether to create/update or delete the port channel. |
| 365 |
type: str |
| 366 |
choices: ['present', 'absent'] |
| 367 |
default: present |
| 368 |
appliance_port_channels: |
| 369 |
description: |
| 370 |
- List of appliance port channel configurations. |
| 371 |
- Port channels for direct-attached storage connectivity. |
| 372 |
type: list |
| 373 |
elements: dict |
| 374 |
suboptions: |
| 375 |
pc_id: |
| 376 |
description: |
| 377 |
- Port Channel Identifier. |
| 378 |
- Valid range is 1-256. |
| 379 |
type: int |
| 380 |
required: true |
| 381 |
admin_speed: |
| 382 |
description: |
| 383 |
- Administrative speed of the port channel. |
| 384 |
type: str |
| 385 |
choices: ['Auto', '1Gbps', '10Gbps', '25Gbps', '40Gbps', '100Gbps'] |
| 386 |
default: 'Auto' |
| 387 |
fec: |
| 388 |
description: |
| 389 |
- Forward Error Correction (FEC) mode. |
| 390 |
type: str |
| 391 |
choices: ['Auto', 'Off'] |
| 392 |
default: 'Auto' |
| 393 |
priority: |
| 394 |
description: |
| 395 |
- QoS priority for the appliance port channel. |
| 396 |
type: str |
| 397 |
choices: ['Best Effort', 'FC', 'Platinum', 'Gold', 'Silver', 'Bronze'] |
| 398 |
default: 'Best Effort' |
| 399 |
mode: |
| 400 |
description: |
| 401 |
- Port mode for the appliance port channel. |
| 402 |
type: str |
| 403 |
choices: ['trunk', 'access'] |
| 404 |
default: 'trunk' |
| 405 |
user_label: |
| 406 |
description: |
| 407 |
- User-defined label for the port channel. |
| 408 |
- User label must be between 0 and 128 alphanumeric characters. |
| 409 |
type: str |
| 410 |
ports: |
| 411 |
description: |
| 412 |
- List of Ethernet ports to include in the port channel. |
| 413 |
type: list |
| 414 |
elements: dict |
| 415 |
required: true |
| 416 |
suboptions: |
| 417 |
port_id: |
| 418 |
description: |
| 419 |
- Port ID to include in the port channel. |
| 420 |
- Can be a regular port (e.g., 36) or aggregate port (e.g., '49/2'). |
| 421 |
- Aggregate ports use breakout port syntax where '49/2' means sub-port 2 of port 49. |
| 422 |
type: str |
| 423 |
required: true |
| 424 |
eth_network_group_policy_name: |
| 425 |
description: |
| 426 |
- Ethernet Network Group Policy name (required). |
| 427 |
- The relationship to the Fabric Network Group Policy. |
| 428 |
type: str |
| 429 |
required: true |
| 430 |
eth_network_control_policy_name: |
| 431 |
description: |
| 432 |
- Ethernet Network Control Policy name (required). |
| 433 |
- The relationship to the Fabric Network Control Policy. |
| 434 |
type: str |
| 435 |
required: true |
| 436 |
link_aggregation_policy_name: |
| 437 |
description: |
| 438 |
- Link Aggregation Policy name to associate. |
| 439 |
- The relationship to the Link Aggregation Policy. |
| 440 |
type: str |
| 441 |
state: |
| 442 |
description: |
| 443 |
- Whether to create/update or delete the port channel. |
| 444 |
type: str |
| 445 |
choices: ['present', 'absent'] |
| 446 |
default: present |
| 447 |
pin_groups: |
| 448 |
description: |
| 449 |
- List of pin group configurations (both LAN and SAN). |
| 450 |
- Pin groups control traffic distribution across uplinks. |
| 451 |
- LAN pin groups are used for Ethernet uplink ports and port channels. |
| 452 |
- SAN pin groups are used for FCoE uplink ports and port channels. |
| 453 |
type: list |
| 454 |
elements: dict |
| 455 |
suboptions: |
| 456 |
name: |
| 457 |
description: |
| 458 |
- Name of the pin group. |
| 459 |
type: str |
| 460 |
required: true |
| 461 |
pin_group_type: |
| 462 |
description: |
| 463 |
- Type of pin group. |
| 464 |
- Use 'lan' for Ethernet uplink ports and port channels. |
| 465 |
- Use 'san' for FCoE uplink ports and port channels. |
| 466 |
type: str |
| 467 |
choices: ['lan', 'san'] |
| 468 |
required: true |
| 469 |
target_interface_type: |
| 470 |
description: |
| 471 |
- Type of target interface. |
| 472 |
type: str |
| 473 |
choices: ['pc', 'port'] |
| 474 |
required: true |
| 475 |
target_interface_name: |
| 476 |
description: |
| 477 |
- Name or identifier of the target interface. |
| 478 |
- For pc, this should be the pc_id of an uplink port channel. |
| 479 |
- For port, this should be the port identifier (e.g., '14' or '49/1'). |
| 480 |
type: str |
| 481 |
required: true |
| 482 |
state: |
| 483 |
description: |
| 484 |
- Whether to create/update or delete the pin group. |
| 485 |
type: str |
| 486 |
choices: ['present', 'absent'] |
| 487 |
default: present |
| 488 |
fc_uplink_ports: |
| 489 |
description: |
| 490 |
- List of FC Uplink port configurations. |
| 491 |
- FC Uplink ports are used for Fibre Channel connectivity to storage networks. |
| 492 |
- For UCS-FI-6454, UCS-FI-64108, UCS-FI-6664 requires fc_port_mode configuration. |
| 493 |
- For UCS-FI-6536, UCSX-S9108-100G uses FC breakout ports (no fc_port_mode needed). |
| 494 |
type: list |
| 495 |
elements: dict |
| 496 |
suboptions: |
| 497 |
port_id: |
| 498 |
description: |
| 499 |
- Port ID to configure as FC Uplink. |
| 500 |
- Must be within the FC port mode range. |
| 501 |
- Can be a regular port (e.g., 1) or aggregate port for FC breakout (e.g., '36/1'). |
| 502 |
- For aggregate ports, the base port must be configured as FC breakout. |
| 503 |
type: str |
| 504 |
required: true |
| 505 |
admin_speed: |
| 506 |
description: |
| 507 |
- Administrative speed of the FC port. |
| 508 |
type: str |
| 509 |
choices: ['Auto', '8Gbps', '16Gbps', '32Gbps'] |
| 510 |
default: 'Auto' |
| 511 |
vsan_id: |
| 512 |
description: |
| 513 |
- Virtual SAN Identifier associated to the FC port. |
| 514 |
type: int |
| 515 |
required: true |
| 516 |
user_label: |
| 517 |
description: |
| 518 |
- User-defined label for the port. |
| 519 |
- User label must be between 0 and 128 alphanumeric characters. |
| 520 |
type: str |
| 521 |
state: |
| 522 |
description: |
| 523 |
- Whether to create/update or delete the FC Uplink port. |
| 524 |
type: str |
| 525 |
choices: ['present', 'absent'] |
| 526 |
default: present |
| 527 |
fc_storage_ports: |
| 528 |
description: |
| 529 |
- List of FC Storage port configurations. |
| 530 |
- FC Storage ports are used for direct storage connectivity. |
| 531 |
- For UCS-FI-6454, UCS-FI-64108, UCS-FI-6664 requires fc_port_mode configuration. |
| 532 |
- For UCS-FI-6536, UCSX-S9108-100G uses FC breakout ports (no fc_port_mode needed). |
| 533 |
type: list |
| 534 |
elements: dict |
| 535 |
suboptions: |
| 536 |
port_id: |
| 537 |
description: |
| 538 |
- Port ID to configure as FC Storage. |
| 539 |
- Must be within the FC port mode range. |
| 540 |
- Can be a regular port (e.g., 2) or aggregate port for FC breakout (e.g., '36/2'). |
| 541 |
- For aggregate ports, the base port must be configured as FC breakout. |
| 542 |
type: str |
| 543 |
required: true |
| 544 |
admin_speed: |
| 545 |
description: |
| 546 |
- Administrative speed of the FC port. |
| 547 |
type: str |
| 548 |
choices: ['8Gbps', '16Gbps', '32Gbps'] |
| 549 |
default: '8Gbps' |
| 550 |
vsan_id: |
| 551 |
description: |
| 552 |
- VSAN ID associated to the FC Storage port. |
| 553 |
type: int |
| 554 |
required: true |
| 555 |
user_label: |
| 556 |
description: |
| 557 |
- User-defined label for the port. |
| 558 |
- User label must be between 0 and 128 alphanumeric characters. |
| 559 |
type: str |
| 560 |
state: |
| 561 |
description: |
| 562 |
- Whether to create/update or delete the FC Storage port. |
| 563 |
type: str |
| 564 |
choices: ['present', 'absent'] |
| 565 |
default: present |
| 566 |
appliance_ports: |
| 567 |
description: |
| 568 |
- List of Appliance port configurations. |
| 569 |
- Appliance ports are used for direct-attached storage connectivity. |
| 570 |
type: list |
| 571 |
elements: dict |
| 572 |
suboptions: |
| 573 |
port_id: |
| 574 |
description: |
| 575 |
- Port ID to configure as Appliance port. |
| 576 |
- Can be a regular port (e.g., 13) or aggregate port (e.g., '49/1'). |
| 577 |
type: str |
| 578 |
required: true |
| 579 |
admin_speed: |
| 580 |
description: |
| 581 |
- Administrative speed of the port. |
| 582 |
- 1Gbps only allowed for ports 45-48. |
| 583 |
- 40Gbps and 100Gbps only allowed for ports 49-54. |
| 584 |
type: str |
| 585 |
choices: ['Auto', '1Gbps', '10Gbps', '25Gbps', '40Gbps', '100Gbps'] |
| 586 |
default: 'Auto' |
| 587 |
fec: |
| 588 |
description: |
| 589 |
- Forward Error Correction (FEC) mode. |
| 590 |
type: str |
| 591 |
choices: ['Auto', 'Off'] |
| 592 |
default: 'Auto' |
| 593 |
priority: |
| 594 |
description: |
| 595 |
- QoS priority for the appliance port. |
| 596 |
type: str |
| 597 |
choices: ['Best Effort', 'FC', 'Platinum', 'Gold', 'Silver', 'Bronze'] |
| 598 |
default: 'Best Effort' |
| 599 |
mode: |
| 600 |
description: |
| 601 |
- Port mode for the appliance port. |
| 602 |
type: str |
| 603 |
choices: ['trunk', 'access'] |
| 604 |
default: 'trunk' |
| 605 |
eth_network_group_policy_name: |
| 606 |
description: |
| 607 |
- Ethernet Network Group Policy name (required). |
| 608 |
- The relationship to the Fabric Network Group Policy. |
| 609 |
type: str |
| 610 |
required: true |
| 611 |
eth_network_control_policy_name: |
| 612 |
description: |
| 613 |
- Ethernet Network Control Policy name (required). |
| 614 |
- The relationship to the Fabric Network Control Policy. |
| 615 |
type: str |
| 616 |
required: true |
| 617 |
user_label: |
| 618 |
description: |
| 619 |
- User-defined label for the port. |
| 620 |
- User label must be between 0 and 128 alphanumeric characters. |
| 621 |
type: str |
| 622 |
state: |
| 623 |
description: |
| 624 |
- Whether to create/update or delete the appliance port. |
| 625 |
type: str |
| 626 |
choices: ['present', 'absent'] |
| 627 |
default: present |
| 628 |
ethernet_uplink_ports: |
| 629 |
description: |
| 630 |
- List of Ethernet Uplink port configurations. |
| 631 |
- Ethernet Uplink ports connect to upstream network switches. |
| 632 |
type: list |
| 633 |
elements: dict |
| 634 |
suboptions: |
| 635 |
port_id: |
| 636 |
description: |
| 637 |
- Port ID to configure as Ethernet Uplink. |
| 638 |
- Can be a regular port (e.g., 14) or aggregate port (e.g., '49/1'). |
| 639 |
type: str |
| 640 |
required: true |
| 641 |
admin_speed: |
| 642 |
description: |
| 643 |
- Administrative speed of the port. |
| 644 |
- Speed restrictions apply based on port numbers. |
| 645 |
type: str |
| 646 |
choices: ['Auto', '1Gbps', '10Gbps', '25Gbps', '40Gbps', '100Gbps'] |
| 647 |
default: 'Auto' |
| 648 |
fec: |
| 649 |
description: |
| 650 |
- Forward Error Correction (FEC) mode. |
| 651 |
type: str |
| 652 |
choices: ['Auto', 'Off'] |
| 653 |
default: 'Auto' |
| 654 |
eth_network_group_policy_name: |
| 655 |
description: |
| 656 |
- List of Ethernet Network Group Policy names. |
| 657 |
- The Ethernet Network Group Policy specifies a set of VLANs to allow on the uplink port. |
| 658 |
- The specified VLAN set must be either identical or disjoint from those specified on other uplink interfaces. |
| 659 |
- Ensure that the VLANs are defined in the VLAN Policy and 'Auto Allow on Uplinks' option is disabled. |
| 660 |
- Note, default VLAN-1 is auto allowed and can be specified as the native VLAN. |
| 661 |
type: list |
| 662 |
elements: str |
| 663 |
flow_control_policy_name: |
| 664 |
description: |
| 665 |
- Flow Control Policy name. |
| 666 |
type: str |
| 667 |
link_control_policy_name: |
| 668 |
description: |
| 669 |
- Link Control Policy name. |
| 670 |
type: str |
| 671 |
mac_sec_policy_name: |
| 672 |
description: |
| 673 |
- MAC Security Policy name. |
| 674 |
- The relationship to the Media Access Control Security (MACsec) Policy. |
| 675 |
type: str |
| 676 |
user_label: |
| 677 |
description: |
| 678 |
- User-defined label for the port. |
| 679 |
- User label must be between 0 and 128 alphanumeric characters. |
| 680 |
type: str |
| 681 |
state: |
| 682 |
description: |
| 683 |
- Whether to create/update or delete the Ethernet Uplink port. |
| 684 |
type: str |
| 685 |
choices: ['present', 'absent'] |
| 686 |
default: present |
| 687 |
fcoe_uplink_ports: |
| 688 |
description: |
| 689 |
- List of FCoE Uplink port configurations. |
| 690 |
- FCoE Uplink ports provide Fibre Channel over Ethernet connectivity. |
| 691 |
type: list |
| 692 |
elements: dict |
| 693 |
suboptions: |
| 694 |
port_id: |
| 695 |
description: |
| 696 |
- Port ID to configure as FCoE Uplink. |
| 697 |
- Can be a regular port (e.g., 15) or aggregate port (e.g., '49/1'). |
| 698 |
type: str |
| 699 |
required: true |
| 700 |
admin_speed: |
| 701 |
description: |
| 702 |
- Administrative speed of the port. |
| 703 |
type: str |
| 704 |
choices: ['Auto', '1Gbps', '10Gbps', '25Gbps', '40Gbps', '100Gbps'] |
| 705 |
default: 'Auto' |
| 706 |
fec: |
| 707 |
description: |
| 708 |
- Forward Error Correction (FEC) mode. |
| 709 |
type: str |
| 710 |
choices: ['Auto', 'Off'] |
| 711 |
default: 'Auto' |
| 712 |
link_control_policy_name: |
| 713 |
description: |
| 714 |
- Link Control Policy name. |
| 715 |
type: str |
| 716 |
user_label: |
| 717 |
description: |
| 718 |
- User-defined label for the port. |
| 719 |
- User label must be between 0 and 128 alphanumeric characters. |
| 720 |
type: str |
| 721 |
state: |
| 722 |
description: |
| 723 |
- Whether to create/update or delete the FCoE Uplink port. |
| 724 |
type: str |
| 725 |
choices: ['present', 'absent'] |
| 726 |
default: present |
| 727 |
author: |
| 728 |
- Ron Gershburg (@rgershbu) |
| 729 |
''' |
| 730 |
|
| 731 |
EXAMPLES = r''' |
| 732 |
- name: Create a Port Policy with breakout ports and server ports |
| 733 |
cisco.intersight.intersight_port_policy: |
| 734 |
api_private_key: "{{ api_private_key }}" |
| 735 |
api_key_id: "{{ api_key_id }}" |
| 736 |
organization: "default" |
| 737 |
name: "port-policy-example" |
| 738 |
description: "Example port policy with various configurations" |
| 739 |
device_model: "UCS-FI-6454" |
| 740 |
tags: |
| 741 |
- Key: "Environment" |
| 742 |
Value: "Production" |
| 743 |
breakout_ports: |
| 744 |
- port_id: 49 |
| 745 |
custom_mode: "BreakoutEthernet25G" |
| 746 |
state: present |
| 747 |
server_ports: |
| 748 |
- port_id: 1 |
| 749 |
fec: "Auto" |
| 750 |
manual_numbering: false |
| 751 |
user_label: "Server Port 1" |
| 752 |
state: present |
| 753 |
- port_id: 2 |
| 754 |
fec: "Auto" |
| 755 |
manual_numbering: true |
| 756 |
preferred_device_type: "RackServer" |
| 757 |
preferred_device_id: 2 |
| 758 |
user_label: "Server Port with Manual Numbering" |
| 759 |
state: present |
| 760 |
state: present |
| 761 |
|
| 762 |
- name: Create a Port Policy with Ethernet uplink port channel |
| 763 |
cisco.intersight.intersight_port_policy: |
| 764 |
api_private_key: "{{ api_private_key }}" |
| 765 |
api_key_id: "{{ api_key_id }}" |
| 766 |
organization: "default" |
| 767 |
name: "port-policy-with-pc" |
| 768 |
description: "Port policy with port channel configurations" |
| 769 |
device_model: "UCS-FI-6454" |
| 770 |
ethernet_uplink_port_channels: |
| 771 |
- pc_id: 123 |
| 772 |
admin_speed: "25Gbps" |
| 773 |
fec: "Auto" |
| 774 |
user_label: "Uplink PC 123" |
| 775 |
ports: |
| 776 |
- port_id: 36 |
| 777 |
- port_id: 37 |
| 778 |
- port_id: "49/1" |
| 779 |
- port_id: "49/2" |
| 780 |
eth_network_group_policy_names: |
| 781 |
- "default-network-group" |
| 782 |
flow_control_policy_name: "default-flow-control" |
| 783 |
link_aggregation_policy_name: "default-link-aggregation" |
| 784 |
link_control_policy_name: "default-link-control" |
| 785 |
state: present |
| 786 |
state: present |
| 787 |
|
| 788 |
- name: Create a Port Policy with FC uplink port channel |
| 789 |
cisco.intersight.intersight_port_policy: |
| 790 |
api_private_key: "{{ api_private_key }}" |
| 791 |
api_key_id: "{{ api_key_id }}" |
| 792 |
organization: "default" |
| 793 |
name: "fc-port-channel-policy" |
| 794 |
device_model: "UCS-FI-6454" |
| 795 |
fc_port_mode: |
| 796 |
port_id_end: 8 |
| 797 |
state: present |
| 798 |
fc_uplink_port_channels: |
| 799 |
- pc_id: 13 |
| 800 |
admin_speed: "16Gbps" |
| 801 |
vsan_id: 1 |
| 802 |
ports: |
| 803 |
- port_id: 1 |
| 804 |
- port_id: 2 |
| 805 |
- port_id: 3 |
| 806 |
- port_id: 4 |
| 807 |
state: present |
| 808 |
state: present |
| 809 |
|
| 810 |
- name: Create a Port Policy with appliance port channel |
| 811 |
cisco.intersight.intersight_port_policy: |
| 812 |
api_private_key: "{{ api_private_key }}" |
| 813 |
api_key_id: "{{ api_key_id }}" |
| 814 |
organization: "default" |
| 815 |
name: "appliance-pc-policy" |
| 816 |
device_model: "UCS-FI-6454" |
| 817 |
appliance_port_channels: |
| 818 |
- pc_id: 21 |
| 819 |
admin_speed: "Auto" |
| 820 |
fec: "Auto" |
| 821 |
priority: "Best Effort" |
| 822 |
mode: "trunk" |
| 823 |
user_label: "Storage PC" |
| 824 |
ports: |
| 825 |
- port_id: 11 |
| 826 |
- port_id: 12 |
| 827 |
eth_network_group_policy_name: "storage-network-group" |
| 828 |
eth_network_control_policy_name: "storage-network-control" |
| 829 |
link_aggregation_policy_name: "default-link-aggregation" |
| 830 |
state: present |
| 831 |
state: present |
| 832 |
|
| 833 |
- name: Create a Port Policy with LAN pin groups |
| 834 |
cisco.intersight.intersight_port_policy: |
| 835 |
api_private_key: "{{ api_private_key }}" |
| 836 |
api_key_id: "{{ api_key_id }}" |
| 837 |
organization: "default" |
| 838 |
name: "port-policy-with-pin-groups" |
| 839 |
description: "Port policy with LAN pin group configuration" |
| 840 |
device_model: "UCS-FI-6454" |
| 841 |
breakout_ports: |
| 842 |
- port_id: 49 |
| 843 |
custom_mode: "BreakoutEthernet25G" |
| 844 |
state: present |
| 845 |
ethernet_uplink_port_channels: |
| 846 |
- pc_id: 1 |
| 847 |
admin_speed: "Auto" |
| 848 |
ports: |
| 849 |
- port_id: 53 |
| 850 |
- port_id: 54 |
| 851 |
eth_network_group_policy_names: |
| 852 |
- "default-network-group" |
| 853 |
state: present |
| 854 |
ethernet_uplink_ports: |
| 855 |
- port_id: 14 |
| 856 |
admin_speed: "Auto" |
| 857 |
fec: "Auto" |
| 858 |
eth_network_group_policy_name: |
| 859 |
- "default-network-group" |
| 860 |
state: present |
| 861 |
fcoe_uplink_ports: |
| 862 |
- port_id: "49/1" |
| 863 |
admin_speed: "Auto" |
| 864 |
fec: "Auto" |
| 865 |
state: present |
| 866 |
pin_groups: |
| 867 |
- name: "pin-group-1" |
| 868 |
pin_group_type: "lan" |
| 869 |
target_interface_type: "pc" |
| 870 |
target_interface_name: "1" |
| 871 |
state: present |
| 872 |
- name: "pin-group-2" |
| 873 |
pin_group_type: "lan" |
| 874 |
target_interface_type: "port" |
| 875 |
target_interface_name: "14" |
| 876 |
state: present |
| 877 |
- name: "pin-group-3" |
| 878 |
pin_group_type: "san" |
| 879 |
target_interface_type: "port" |
| 880 |
target_interface_name: "49/1" |
| 881 |
state: present |
| 882 |
state: present |
| 883 |
|
| 884 |
- name: Update Port Policy - manage resource states |
| 885 |
cisco.intersight.intersight_port_policy: |
| 886 |
api_private_key: "{{ api_private_key }}" |
| 887 |
api_key_id: "{{ api_key_id }}" |
| 888 |
organization: "default" |
| 889 |
name: "port-policy-update" |
| 890 |
device_model: "UCS-FI-6454" |
| 891 |
server_ports: |
| 892 |
- port_id: 3 |
| 893 |
user_label: "New Server Port" |
| 894 |
state: present |
| 895 |
- port_id: 4 |
| 896 |
state: absent |
| 897 |
state: present |
| 898 |
|
| 899 |
- name: Create a Port Policy with Fibre Channel ports 1-16 |
| 900 |
cisco.intersight.intersight_port_policy: |
| 901 |
api_private_key: "{{ api_private_key }}" |
| 902 |
api_key_id: "{{ api_key_id }}" |
| 903 |
name: "fc-port-policy" |
| 904 |
device_model: "UCS-FI-6454" |
| 905 |
fc_port_mode: |
| 906 |
port_id_end: 16 |
| 907 |
state: present |
| 908 |
fc_uplink_ports: |
| 909 |
- port_id: 1 |
| 910 |
admin_speed: "8Gbps" |
| 911 |
vsan_id: 2 |
| 912 |
user_label: "FC Uplink 1" |
| 913 |
state: present |
| 914 |
- port_id: "49/1" |
| 915 |
admin_speed: "16Gbps" |
| 916 |
vsan_id: 3 |
| 917 |
user_label: "FC Uplink Aggregate" |
| 918 |
state: present |
| 919 |
fc_storage_ports: |
| 920 |
- port_id: 2 |
| 921 |
admin_speed: "8Gbps" |
| 922 |
vsan_id: 5 |
| 923 |
user_label: "FC Storage 2" |
| 924 |
state: present |
| 925 |
state: present |
| 926 |
|
| 927 |
- name: Create a Port Policy with Appliance and Ethernet Uplink ports |
| 928 |
cisco.intersight.intersight_port_policy: |
| 929 |
api_private_key: "{{ api_private_key }}" |
| 930 |
api_key_id: "{{ api_key_id }}" |
| 931 |
name: "mixed-port-policy" |
| 932 |
device_model: "UCS-FI-6454" |
| 933 |
appliance_ports: |
| 934 |
- port_id: 13 |
| 935 |
admin_speed: "10Gbps" |
| 936 |
fec: "Auto" |
| 937 |
priority: "Best Effort" |
| 938 |
mode: "trunk" |
| 939 |
eth_network_group_policy_name: "default-network-group" |
| 940 |
eth_network_control_policy_name: "default-network-control" |
| 941 |
user_label: "Storage Appliance" |
| 942 |
state: present |
| 943 |
ethernet_uplink_ports: |
| 944 |
- port_id: 14 |
| 945 |
admin_speed: "Auto" |
| 946 |
fec: "Auto" |
| 947 |
eth_network_group_policy_name: |
| 948 |
- "default-network-group" |
| 949 |
flow_control_policy_name: "default-flow-control" |
| 950 |
link_control_policy_name: "default-link-control" |
| 951 |
state: present |
| 952 |
fcoe_uplink_ports: |
| 953 |
- port_id: 15 |
| 954 |
admin_speed: "Auto" |
| 955 |
fec: "Auto" |
| 956 |
link_control_policy_name: "default-link-control" |
| 957 |
user_label: "FCoE Uplink" |
| 958 |
state: present |
| 959 |
state: present |
| 960 |
|
| 961 |
- name: Delete a Port Policy |
| 962 |
cisco.intersight.intersight_port_policy: |
| 963 |
api_private_key: "{{ api_private_key }}" |
| 964 |
api_key_id: "{{ api_key_id }}" |
| 965 |
name: "port-policy-to-delete" |
| 966 |
state: absent |
| 967 |
|
| 968 |
# Device Model Specific Examples |
| 969 |
|
| 970 |
- name: UCS-FI-64108 Port Policy with device-specific features |
| 971 |
cisco.intersight.intersight_port_policy: |
| 972 |
api_private_key: "{{ api_private_key }}" |
| 973 |
api_key_id: "{{ api_key_id }}" |
| 974 |
name: "UCS-FI-64108-policy" |
| 975 |
device_model: "UCS-FI-64108" |
| 976 |
description: "Port policy for UCS-FI-64108 with 108 ports" |
| 977 |
breakout_ports: |
| 978 |
- port_id: 97 |
| 979 |
custom_mode: "BreakoutEthernet25G" |
| 980 |
state: present |
| 981 |
- port_id: 108 |
| 982 |
custom_mode: "BreakoutEthernet10G" |
| 983 |
state: present |
| 984 |
ethernet_uplink_ports: |
| 985 |
- port_id: 89 |
| 986 |
admin_speed: "1Gbps" |
| 987 |
state: present |
| 988 |
- port_id: 97 |
| 989 |
admin_speed: "100Gbps" |
| 990 |
state: present |
| 991 |
state: present |
| 992 |
|
| 993 |
- name: UCS-FI-6536 Port Policy with FC breakout support |
| 994 |
cisco.intersight.intersight_port_policy: |
| 995 |
api_private_key: "{{ api_private_key }}" |
| 996 |
api_key_id: "{{ api_key_id }}" |
| 997 |
name: "UCS-FI-6536-policy" |
| 998 |
device_model: "UCS-FI-6536" |
| 999 |
description: "Port policy for UCS-FI-6536 with FC breakout" |
| 1000 |
breakout_ports: |
| 1001 |
- port_id: 36 |
| 1002 |
custom_mode: "BreakoutFibreChannel16G" |
| 1003 |
state: present |
| 1004 |
- port_id: 35 |
| 1005 |
custom_mode: "BreakoutFibreChannel32G" |
| 1006 |
state: present |
| 1007 |
- port_id: 1 |
| 1008 |
custom_mode: "BreakoutEthernet25G" |
| 1009 |
state: present |
| 1010 |
ethernet_uplink_ports: |
| 1011 |
- port_id: 9 |
| 1012 |
admin_speed: "1Gbps" |
| 1013 |
state: present |
| 1014 |
fc_uplink_ports: |
| 1015 |
- port_id: "36/1" |
| 1016 |
admin_speed: "16Gbps" |
| 1017 |
vsan_id: 1 |
| 1018 |
state: present |
| 1019 |
fc_storage_ports: |
| 1020 |
- port_id: "35/2" |
| 1021 |
admin_speed: "32Gbps" |
| 1022 |
vsan_id: 2 |
| 1023 |
state: present |
| 1024 |
state: present |
| 1025 |
|
| 1026 |
- name: UCS-FI-6664 Port Policy without breakout support |
| 1027 |
cisco.intersight.intersight_port_policy: |
| 1028 |
api_private_key: "{{ api_private_key }}" |
| 1029 |
api_key_id: "{{ api_key_id }}" |
| 1030 |
name: "UCS-FI-6664-policy" |
| 1031 |
device_model: "UCS-FI-6664" |
| 1032 |
description: "Port policy for UCS-FI-6664 - no breakout support" |
| 1033 |
fc_port_mode: |
| 1034 |
port_id_start: 25 |
| 1035 |
port_id_end: 40 |
| 1036 |
state: present |
| 1037 |
ethernet_uplink_ports: |
| 1038 |
- port_id: 1 |
| 1039 |
admin_speed: "100Gbps" |
| 1040 |
state: present |
| 1041 |
- port_id: 50 |
| 1042 |
admin_speed: "40Gbps" |
| 1043 |
state: present |
| 1044 |
fc_uplink_ports: |
| 1045 |
- port_id: 25 |
| 1046 |
admin_speed: "32Gbps" |
| 1047 |
vsan_id: 1 |
| 1048 |
state: present |
| 1049 |
state: present |
| 1050 |
|
| 1051 |
- name: UCSX-S9108-100G Port Policy with FC breakout |
| 1052 |
cisco.intersight.intersight_port_policy: |
| 1053 |
api_private_key: "{{ api_private_key }}" |
| 1054 |
api_key_id: "{{ api_key_id }}" |
| 1055 |
name: "UCSX-S9108-100G-policy" |
| 1056 |
device_model: "UCSX-S9108-100G" |
| 1057 |
description: "Port policy for UCSX-S9108-100G with FC breakout" |
| 1058 |
breakout_ports: |
| 1059 |
- port_id: 1 |
| 1060 |
custom_mode: "BreakoutFibreChannel16G" |
| 1061 |
state: present |
| 1062 |
- port_id: 2 |
| 1063 |
custom_mode: "BreakoutFibreChannel8G" |
| 1064 |
state: present |
| 1065 |
ethernet_uplink_ports: |
| 1066 |
- port_id: 7 |
| 1067 |
admin_speed: "1Gbps" |
| 1068 |
state: present |
| 1069 |
- port_id: 8 |
| 1070 |
admin_speed: "1Gbps" |
| 1071 |
state: present |
| 1072 |
fc_uplink_ports: |
| 1073 |
- port_id: "1/1" |
| 1074 |
admin_speed: "16Gbps" |
| 1075 |
vsan_id: 1 |
| 1076 |
state: present |
| 1077 |
- port_id: "2/3" |
| 1078 |
admin_speed: "8Gbps" |
| 1079 |
vsan_id: 1 |
| 1080 |
state: present |
| 1081 |
state: present |
| 1082 |
''' |
| 1083 |
|
| 1084 |
RETURN = r''' |
| 1085 |
api_response: |
| 1086 |
description: The API response output returned by the specified resource. |
| 1087 |
returned: always |
| 1088 |
type: dict |
| 1089 |
sample: |
| 1090 |
"api_response": { |
| 1091 |
"Name": "port-policy-example", |
| 1092 |
"DeviceModel": "UCS-FI-6454", |
| 1093 |
"ObjectType": "fabric.PortPolicy", |
| 1094 |
"Tags": [ |
| 1095 |
{ |
| 1096 |
"Key": "Environment", |
| 1097 |
"Value": "Production" |
| 1098 |
} |
| 1099 |
], |
| 1100 |
"BreakoutPorts": [ |
| 1101 |
{ |
| 1102 |
"SlotId": 1, |
| 1103 |
"PortIdStart": 49, |
| 1104 |
"PortIdEnd": 49, |
| 1105 |
"CustomMode": "BreakoutEthernet25G" |
| 1106 |
} |
| 1107 |
], |
| 1108 |
"ServerPorts": [ |
| 1109 |
{ |
| 1110 |
"SlotId": 1, |
| 1111 |
"PortId": 1, |
| 1112 |
"Fec": "Auto", |
| 1113 |
"UserLabel": "Server Port 1" |
| 1114 |
} |
| 1115 |
] |
| 1116 |
} |
| 1117 |
''' |
| 1118 |
|
| 1119 |
|
| 1120 |
from ansible.module_utils.basic import AnsibleModule |
| 1121 |
from ansible_collections.cisco.intersight.plugins.module_utils.intersight import IntersightModule, intersight_argument_spec |
| 1122 |
|
| 1123 |
|
| 1124 |
def parse_port_id(port_input): |
| 1125 |
""" |
| 1126 |
Parse port ID input to determine if it's a regular or aggregate port. |
| 1127 |
|
| 1128 |
Args: |
| 1129 |
port_input: Port specification (int like 49 or string like "49/2") |
| 1130 |
|
| 1131 |
Returns: |
| 1132 |
Dictionary with: |
| 1133 |
- is_aggregate: Boolean indicating if it's an aggregate port |
| 1134 |
- port_id: The port ID (2 for aggregate "49/2", 49 for regular 49) |
| 1135 |
- aggregate_port_id: The aggregate port ID (49 for "49/2", None for regular) |
| 1136 |
- display_name: Human readable name ("port49/2" or "port49") |
| 1137 |
""" |
| 1138 |
if isinstance(port_input, str) and '/' in port_input: |
| 1139 |
# Aggregate port syntax: "49/2" |
| 1140 |
try: |
| 1141 |
aggregate_port_str, port_str = port_input.split('/') |
| 1142 |
aggregate_port_id = int(aggregate_port_str) |
| 1143 |
port_id = int(port_str) |
| 1144 |
|
| 1145 |
# Validate aggregate port sub-port range (1-4) |
| 1146 |
if not (1 <= port_id <= 4): |
| 1147 |
raise ValueError(f"Aggregate port sub-port must be between 1-4, got {port_id}") |
| 1148 |
|
| 1149 |
return { |
| 1150 |
'is_aggregate': True, |
| 1151 |
'port_id': port_id, |
| 1152 |
'aggregate_port_id': aggregate_port_id, |
| 1153 |
'display_name': f"port{aggregate_port_id}/{port_id}" |
| 1154 |
} |
| 1155 |
except (ValueError, TypeError) as e: |
| 1156 |
raise ValueError(f"Invalid aggregate port format '{port_input}'. Expected format: '49/2'") from e |
| 1157 |
else: |
| 1158 |
# Regular port: just a number |
| 1159 |
try: |
| 1160 |
port_id = int(port_input) |
| 1161 |
return { |
| 1162 |
'is_aggregate': False, |
| 1163 |
'port_id': port_id, |
| 1164 |
'aggregate_port_id': None, |
| 1165 |
'display_name': f"port{port_id}" |
| 1166 |
} |
| 1167 |
except (ValueError, TypeError) as e: |
| 1168 |
raise ValueError(f"Invalid port format '{port_input}'. Expected integer or 'X/Y' format") from e |
| 1169 |
|
| 1170 |
|
| 1171 |
def get_device_model_constraints(device_model): |
| 1172 |
""" |
| 1173 |
Get device model specific constraints and capabilities. |
| 1174 |
|
| 1175 |
Args: |
| 1176 |
device_model: Device model string |
| 1177 |
|
| 1178 |
Returns: |
| 1179 |
Dictionary with device-specific constraints |
| 1180 |
""" |
| 1181 |
constraints = { |
| 1182 |
'UCS-FI-6454': { |
| 1183 |
'total_ports': 54, |
| 1184 |
'port_range': (1, 54), |
| 1185 |
'fc_port_range': (1, 16), |
| 1186 |
'breakout_ports': (49, 54), |
| 1187 |
'fc_breakout_supported': False, |
| 1188 |
'admin_speed_restrictions': { |
| 1189 |
# No specific restrictions for UCS-FI-6454 in the original implementation |
| 1190 |
}, |
| 1191 |
'supported_breakout_modes': ['BreakoutEthernet10G', 'BreakoutEthernet25G'] |
| 1192 |
}, |
| 1193 |
'UCS-FI-64108': { |
| 1194 |
'total_ports': 108, |
| 1195 |
'port_range': (1, 108), |
| 1196 |
'fc_port_range': (1, 16), |
| 1197 |
'breakout_ports': (97, 108), |
| 1198 |
'fc_breakout_supported': False, |
| 1199 |
'admin_speed_restrictions': { |
| 1200 |
(89, 96): ['1Gbps'], # 1Gbps only for ports 89-96 |
| 1201 |
(97, 108): ['40Gbps', '100Gbps'] # 40Gbps and 100Gbps for ports 97-108 |
| 1202 |
}, |
| 1203 |
'supported_breakout_modes': ['BreakoutEthernet10G', 'BreakoutEthernet25G'] |
| 1204 |
}, |
| 1205 |
'UCS-FI-6536': { |
| 1206 |
'total_ports': 36, |
| 1207 |
'port_range': (1, 36), |
| 1208 |
'fc_port_range': (33, 36), |
| 1209 |
'breakout_ports': (1, 36), |
| 1210 |
'fc_breakout_supported': True, |
| 1211 |
'admin_speed_restrictions': { |
| 1212 |
(9, 10): ['1Gbps'] # 1Gbps only for ports 9-10 |
| 1213 |
}, |
| 1214 |
'supported_breakout_modes': [ |
| 1215 |
'BreakoutEthernet10G', |
| 1216 |
'BreakoutEthernet25G', |
| 1217 |
'BreakoutFibreChannel8G', |
| 1218 |
'BreakoutFibreChannel16G', |
| 1219 |
'BreakoutFibreChannel32G' |
| 1220 |
] |
| 1221 |
}, |
| 1222 |
'UCS-FI-6664': { |
| 1223 |
'total_ports': 64, |
| 1224 |
'port_range': (1, 64), |
| 1225 |
'fc_port_range': (25, 40), |
| 1226 |
'breakout_ports': None, # No breakout support |
| 1227 |
'fc_breakout_supported': False, |
| 1228 |
'admin_speed_restrictions': { |
| 1229 |
(1, 24): ['40Gbps', '100Gbps'], # 40Gbps and 100Gbps for ports 1-24 |
| 1230 |
(41, 64): ['40Gbps', '100Gbps'] # 40Gbps and 100Gbps for ports 41-64 |
| 1231 |
}, |
| 1232 |
'supported_breakout_modes': [] |
| 1233 |
}, |
| 1234 |
'UCSX-S9108-100G': { |
| 1235 |
'total_ports': 8, |
| 1236 |
'port_range': (1, 8), |
| 1237 |
'fc_port_range': (1, 2), |
| 1238 |
'breakout_ports': (1, 2), # Only FC ports support breakout |
| 1239 |
'fc_breakout_supported': True, |
| 1240 |
'admin_speed_restrictions': { |
| 1241 |
(7, 8): ['1Gbps'] # 1Gbps only for ports 7-8 |
| 1242 |
}, |
| 1243 |
'supported_breakout_modes': ['BreakoutFibreChannel8G', 'BreakoutFibreChannel16G', 'BreakoutFibreChannel32G'] |
| 1244 |
} |
| 1245 |
} |
| 1246 |
|
| 1247 |
return constraints.get(device_model, {}) |
| 1248 |
|
| 1249 |
|
| 1250 |
def validate_port_range_for_device(module, port_id, device_model, port_type="port"): |
| 1251 |
""" |
| 1252 |
Validate port ID is within the valid range for the device model. |
| 1253 |
|
| 1254 |
Args: |
| 1255 |
module: AnsibleModule instance |
| 1256 |
port_id: Port ID to validate |
| 1257 |
device_model: Device model string |
| 1258 |
port_type: Type of port for error messages |
| 1259 |
""" |
| 1260 |
constraints = get_device_model_constraints(device_model) |
| 1261 |
|
| 1262 |
if not constraints: |
| 1263 |
module.fail_json(msg=f"Unsupported device model: {device_model}") |
| 1264 |
|
| 1265 |
port_range = constraints.get('port_range', (1, 1)) |
| 1266 |
min_port, max_port = port_range |
| 1267 |
|
| 1268 |
if port_id < min_port or port_id > max_port: |
| 1269 |
module.fail_json( |
| 1270 |
msg=f"{port_type} {port_id} is outside valid range for {device_model}. " |
| 1271 |
f"Valid range: {min_port}-{max_port}" |
| 1272 |
) |
| 1273 |
|
| 1274 |
|
| 1275 |
def validate_admin_speed_for_device(module, port_id, admin_speed, device_model, port_type="port"): |
| 1276 |
""" |
| 1277 |
Validate admin speed is allowed for the specific port on the device model. |
| 1278 |
|
| 1279 |
Args: |
| 1280 |
module: AnsibleModule instance |
| 1281 |
port_id: Port ID |
| 1282 |
admin_speed: Admin speed to validate |
| 1283 |
device_model: Device model string |
| 1284 |
port_type: Type of port for error messages |
| 1285 |
""" |
| 1286 |
if admin_speed == 'Auto': |
| 1287 |
return # Auto is always allowed |
| 1288 |
|
| 1289 |
constraints = get_device_model_constraints(device_model) |
| 1290 |
speed_restrictions = constraints.get('admin_speed_restrictions', {}) |
| 1291 |
|
| 1292 |
for port_range, allowed_speeds in speed_restrictions.items(): |
| 1293 |
min_port, max_port = port_range |
| 1294 |
if min_port <= port_id <= max_port: |
| 1295 |
if admin_speed not in allowed_speeds: |
| 1296 |
allowed_str = ', '.join(allowed_speeds) |
| 1297 |
module.fail_json( |
| 1298 |
msg=f"{port_type} {port_id} on {device_model} only supports admin speeds: {allowed_str}. " |
| 1299 |
f"Got: {admin_speed}" |
| 1300 |
) |
| 1301 |
return |
| 1302 |
|
| 1303 |
|
| 1304 |
def validate_breakout_port_for_device(module, port_id, device_model): |
| 1305 |
""" |
| 1306 |
Validate that breakout is supported for the specific port on the device model. |
| 1307 |
|
| 1308 |
Args: |
| 1309 |
module: AnsibleModule instance |
| 1310 |
port_id: Port ID to validate |
| 1311 |
device_model: Device model string |
| 1312 |
""" |
| 1313 |
constraints = get_device_model_constraints(device_model) |
| 1314 |
breakout_ports = constraints.get('breakout_ports') |
| 1315 |
|
| 1316 |
if breakout_ports is None: |
| 1317 |
module.fail_json( |
| 1318 |
msg=f"Breakout ports are not supported on {device_model}" |
| 1319 |
) |
| 1320 |
|
| 1321 |
min_breakout, max_breakout = breakout_ports |
| 1322 |
if port_id < min_breakout or port_id > max_breakout: |
| 1323 |
module.fail_json( |
| 1324 |
msg=f"Port {port_id} cannot be configured as breakout on {device_model}. " |
| 1325 |
f"Breakout ports range: {min_breakout}-{max_breakout}" |
| 1326 |
) |
| 1327 |
|
| 1328 |
|
| 1329 |
def validate_fc_port_range_for_device(module, port_id, device_model): |
| 1330 |
""" |
| 1331 |
Validate FC port ID is within the valid FC range for the device model. |
| 1332 |
|
| 1333 |
Args: |
| 1334 |
module: AnsibleModule instance |
| 1335 |
port_id: Port ID to validate |
| 1336 |
device_model: Device model string |
| 1337 |
""" |
| 1338 |
constraints = get_device_model_constraints(device_model) |
| 1339 |
fc_port_range = constraints.get('fc_port_range') |
| 1340 |
|
| 1341 |
if not fc_port_range: |
| 1342 |
module.fail_json( |
| 1343 |
msg=f"FC ports are not supported on {device_model}" |
| 1344 |
) |
| 1345 |
|
| 1346 |
min_fc, max_fc = fc_port_range |
| 1347 |
if port_id < min_fc or port_id > max_fc: |
| 1348 |
module.fail_json( |
| 1349 |
msg=f"FC port {port_id} is outside valid FC range for {device_model}. " |
| 1350 |
f"Valid FC range: {min_fc}-{max_fc}" |
| 1351 |
) |
| 1352 |
|
| 1353 |
|
| 1354 |
def validate_breakout_mode_for_device(module, custom_mode, device_model): |
| 1355 |
""" |
| 1356 |
Validate breakout mode is supported for the device model. |
| 1357 |
|
| 1358 |
Args: |
| 1359 |
module: AnsibleModule instance |
| 1360 |
custom_mode: Breakout mode to validate |
| 1361 |
device_model: Device model string |
| 1362 |
""" |
| 1363 |
constraints = get_device_model_constraints(device_model) |
| 1364 |
supported_modes = constraints.get('supported_breakout_modes', []) |
| 1365 |
|
| 1366 |
if custom_mode not in supported_modes: |
| 1367 |
supported_str = ', '.join(supported_modes) |
| 1368 |
module.fail_json( |
| 1369 |
msg=f"Breakout mode '{custom_mode}' is not supported on {device_model}. " |
| 1370 |
f"Supported modes: {supported_str}" |
| 1371 |
) |
| 1372 |
|
| 1373 |
|
| 1374 |
def validate_breakout_port_config(module, breakout_config): |
| 1375 |
""" |
| 1376 |
Validate breakout port configuration with device model specific constraints. |
| 1377 |
|
| 1378 |
Args: |
| 1379 |
module: AnsibleModule instance |
| 1380 |
breakout_config: Dictionary containing breakout port configuration |
| 1381 |
""" |
| 1382 |
port_id = breakout_config.get('port_id') |
| 1383 |
custom_mode = breakout_config.get('custom_mode') |
| 1384 |
device_model = module.params.get('device_model') |
| 1385 |
|
| 1386 |
if port_id: |
| 1387 |
# Basic port ID validation |
| 1388 |
if port_id < 1: |
| 1389 |
module.fail_json(msg=f"port_id ({port_id}) must be greater than 0") |
| 1390 |
|
| 1391 |
# Device-specific validations |
| 1392 |
validate_port_range_for_device(module, port_id, device_model, "Breakout port") |
| 1393 |
validate_breakout_port_for_device(module, port_id, device_model) |
| 1394 |
|
| 1395 |
if custom_mode: |
| 1396 |
validate_breakout_mode_for_device(module, custom_mode, device_model) |
| 1397 |
|
| 1398 |
|
| 1399 |
def validate_uplink_port_channel_config(module, pc_config): |
| 1400 |
""" |
| 1401 |
Validate uplink port channel configuration. |
| 1402 |
|
| 1403 |
Args: |
| 1404 |
module: AnsibleModule instance |
| 1405 |
pc_config: Dictionary containing port channel configuration |
| 1406 |
""" |
| 1407 |
ports = pc_config.get('ports', []) |
| 1408 |
|
| 1409 |
if not ports: |
| 1410 |
module.fail_json(msg=f"At least one port must be specified for port channel {pc_config.get('pc_id')}") |
| 1411 |
|
| 1412 |
port_ids = [p['port_id'] for p in ports] |
| 1413 |
if len(port_ids) != len(set(port_ids)): |
| 1414 |
module.fail_json(msg=f"Duplicate ports found in port channel {pc_config.get('pc_id')}") |
| 1415 |
|
| 1416 |
|
| 1417 |
def validate_port_id_uniqueness(module): |
| 1418 |
""" |
| 1419 |
Validate that port IDs don't overlap across different port types. |
| 1420 |
Handles both regular ports and aggregate ports properly. |
| 1421 |
|
| 1422 |
Args: |
| 1423 |
module: AnsibleModule instance |
| 1424 |
""" |
| 1425 |
# Separate lists for regular ports and aggregate ports |
| 1426 |
regular_ports = [] # Regular port IDs (e.g., 49) |
| 1427 |
aggregate_ports = [] # Aggregate port strings (e.g., "port49/2") |
| 1428 |
aggregate_base_ports = set() # Base ports used for aggregation (e.g., 49) |
| 1429 |
|
| 1430 |
def add_port_to_lists(port_input): |
| 1431 |
"""Helper to add port to appropriate list based on type.""" |
| 1432 |
try: |
| 1433 |
port_info = parse_port_id(port_input) |
| 1434 |
if port_info['is_aggregate']: |
| 1435 |
aggregate_ports.append(port_info['display_name']) |
| 1436 |
# Track the base port used for aggregation |
| 1437 |
aggregate_base_ports.add(port_info['aggregate_port_id']) |
| 1438 |
else: |
| 1439 |
regular_ports.append(port_info['port_id']) |
| 1440 |
except ValueError as e: |
| 1441 |
module.fail_json(msg=f"Invalid port specification: {e}") |
| 1442 |
|
| 1443 |
# Add all port role configurations |
| 1444 |
port_role_configs = [ |
| 1445 |
('server_ports', module.params.get('server_ports')), |
| 1446 |
('fc_uplink_ports', module.params.get('fc_uplink_ports')), |
| 1447 |
('fc_storage_ports', module.params.get('fc_storage_ports')), |
| 1448 |
('appliance_ports', module.params.get('appliance_ports')), |
| 1449 |
('ethernet_uplink_ports', module.params.get('ethernet_uplink_ports')), |
| 1450 |
('fcoe_uplink_ports', module.params.get('fcoe_uplink_ports')) |
| 1451 |
] |
| 1452 |
|
| 1453 |
for port_type_name, port_configs in port_role_configs: |
| 1454 |
if port_configs: |
| 1455 |
for port_config in port_configs: |
| 1456 |
if port_config.get('state', 'present') == 'present': |
| 1457 |
add_port_to_lists(port_config['port_id']) |
| 1458 |
|
| 1459 |
# Add port channel member ports (can be regular or aggregate) |
| 1460 |
# TODO: Note to myself, please don't remove it or take it into account for now - I will need to handle port channel for aggregation in specific hardware. |
| 1461 |
def add_port_channel_ports(port_channels): |
| 1462 |
"""Helper function to add port channel ports to appropriate lists.""" |
| 1463 |
for pc_config in port_channels: |
| 1464 |
if pc_config.get('state', 'present') == 'present': |
| 1465 |
ports = pc_config.get('ports', []) |
| 1466 |
for port in ports: |
| 1467 |
port_id = port['port_id'] |
| 1468 |
aggregate_port_id = port.get('aggregate_port_id') |
| 1469 |
|
| 1470 |
if aggregate_port_id: |
| 1471 |
# Legacy syntax: aggregate_port_id specified separately |
| 1472 |
aggregate_ports.append(f"port{aggregate_port_id}/{port_id}") |
| 1473 |
# Track the base port used for aggregation |
| 1474 |
aggregate_base_ports.add(aggregate_port_id) |
| 1475 |
else: |
| 1476 |
# port_id can be "49/2" format or regular |
| 1477 |
add_port_to_lists(port_id) |
| 1478 |
|
| 1479 |
# Add all port channel types |
| 1480 |
if module.params.get('ethernet_uplink_port_channels'): |
| 1481 |
add_port_channel_ports(module.params.get('ethernet_uplink_port_channels')) |
| 1482 |
if module.params.get('fc_uplink_port_channels'): |
| 1483 |
add_port_channel_ports(module.params.get('fc_uplink_port_channels')) |
| 1484 |
if module.params.get('fcoe_uplink_port_channels'): |
| 1485 |
add_port_channel_ports(module.params.get('fcoe_uplink_port_channels')) |
| 1486 |
if module.params.get('appliance_port_channels'): |
| 1487 |
add_port_channel_ports(module.params.get('appliance_port_channels')) |
| 1488 |
|
| 1489 |
# Add breakout port ranges (these create the base ports for aggregation) |
| 1490 |
breakout_ports = module.params.get('breakout_ports') |
| 1491 |
if breakout_ports: |
| 1492 |
for breakout_config in breakout_ports: |
| 1493 |
if breakout_config.get('state', 'present') == 'present': |
| 1494 |
port_id = breakout_config['port_id'] |
| 1495 |
# Breakout ports become aggregate base ports, not regular ports |
| 1496 |
aggregate_base_ports.add(port_id) |
| 1497 |
|
| 1498 |
def find_duplicates(port_list): |
| 1499 |
"""Helper function to find duplicates in a list.""" |
| 1500 |
if len(port_list) == len(set(port_list)): |
| 1501 |
return [] |
| 1502 |
|
| 1503 |
duplicates = [] |
| 1504 |
unique_items = set(port_list) |
| 1505 |
for item in unique_items: |
| 1506 |
if port_list.count(item) > 1: |
| 1507 |
duplicates.append(item) |
| 1508 |
return duplicates |
| 1509 |
|
| 1510 |
# Check for duplicates in both port lists |
| 1511 |
regular_duplicates = find_duplicates(regular_ports) |
| 1512 |
aggregate_duplicates = find_duplicates(aggregate_ports) |
| 1513 |
|
| 1514 |
# Check for conflicts between regular ports and aggregate base ports |
| 1515 |
regular_ports_set = set(regular_ports) |
| 1516 |
base_regular_conflicts = regular_ports_set.intersection(aggregate_base_ports) |
| 1517 |
|
| 1518 |
# Report conflicts |
| 1519 |
conflicts = [] |
| 1520 |
if regular_duplicates: |
| 1521 |
regular_conflict_str = ', '.join(map(str, sorted(regular_duplicates))) |
| 1522 |
conflicts.append(f"Regular ports: {regular_conflict_str}") |
| 1523 |
|
| 1524 |
if aggregate_duplicates: |
| 1525 |
aggregate_conflict_str = ', '.join(sorted(aggregate_duplicates)) |
| 1526 |
conflicts.append(f"Aggregate ports: {aggregate_conflict_str}") |
| 1527 |
|
| 1528 |
if base_regular_conflicts: |
| 1529 |
base_conflict_str = ', '.join(map(str, sorted(base_regular_conflicts))) |
| 1530 |
conflicts.append(f"Ports used as both regular and aggregate base: {base_conflict_str}") |
| 1531 |
|
| 1532 |
if conflicts: |
| 1533 |
conflict_message = "Port ID conflicts detected. The following ports are assigned multiple roles:\n" + '\n'.join(conflicts) |
| 1534 |
module.fail_json(msg=conflict_message) |
| 1535 |
|
| 1536 |
|
| 1537 |
def validate_fc_port_constraints(module): |
| 1538 |
""" |
| 1539 |
Validate FC port constraints with device model specific validation. |
| 1540 |
|
| 1541 |
Args: |
| 1542 |
module: AnsibleModule instance |
| 1543 |
""" |
| 1544 |
fc_port_mode = module.params.get('fc_port_mode') |
| 1545 |
fc_uplink_ports = module.params.get('fc_uplink_ports') |
| 1546 |
fc_storage_ports = module.params.get('fc_storage_ports') |
| 1547 |
device_model = module.params.get('device_model') |
| 1548 |
|
| 1549 |
# For UCS-FI-6536 and UCSX-S9108-100G, FC is only available through breakout ports |
| 1550 |
# Warn user if they specify fc_port_mode for these models |
| 1551 |
if fc_port_mode and device_model in ['UCS-FI-6536', 'UCSX-S9108-100G']: |
| 1552 |
module.warn( |
| 1553 |
f"fc_port_mode is not supported on {device_model}. " |
| 1554 |
f"FC functionality is available through breakout ports only. " |
| 1555 |
f"Ignoring fc_port_mode configuration." |
| 1556 |
) |
| 1557 |
# Override the parameter to prevent it from being processed |
| 1558 |
module.params['fc_port_mode'] = None |
| 1559 |
fc_port_mode = None |
| 1560 |
|
| 1561 |
# If FC mode is configured, validate FC port IDs are within range |
| 1562 |
if fc_port_mode and fc_port_mode.get('state', 'present') == 'present': |
| 1563 |
port_start = fc_port_mode.get('port_id_start', 1) |
| 1564 |
port_end = fc_port_mode['port_id_end'] |
| 1565 |
|
| 1566 |
# Validate FC port mode range against device capabilities |
| 1567 |
constraints = get_device_model_constraints(device_model) |
| 1568 |
fc_port_range = constraints.get('fc_port_range') |
| 1569 |
|
| 1570 |
if not fc_port_range: |
| 1571 |
module.fail_json(msg=f"FC ports are not supported on {device_model}") |
| 1572 |
|
| 1573 |
device_fc_min, device_fc_max = fc_port_range |
| 1574 |
|
| 1575 |
# For most models (except UCS-FI-6536), the minimum FC port must always be included in the range |
| 1576 |
if device_model != 'UCS-FI-6536' and port_start != device_fc_min: |
| 1577 |
module.fail_json( |
| 1578 |
msg=f"For {device_model}, FC port mode must always include the minimum FC port. " |
| 1579 |
f"port_id_start must be {device_fc_min}, got {port_start}" |
| 1580 |
) |
| 1581 |
|
| 1582 |
# Device-specific validation for maximum FC port |
| 1583 |
if device_model == 'UCS-FI-6536': |
| 1584 |
# For UCS-FI-6536, port 36 must always be included in FC range |
| 1585 |
if port_end != 36: |
| 1586 |
module.fail_json( |
| 1587 |
msg=f"For {device_model}, FC port mode must always include port 36. " |
| 1588 |
f"port_id_end must be 36, got {port_end}" |
| 1589 |
) |
| 1590 |
elif device_model in ['UCS-FI-6454', 'UCS-FI-64108']: |
| 1591 |
# For these models, port_id_end must be one of the standard values |
| 1592 |
if port_end not in [4, 8, 12, 16]: |
| 1593 |
module.fail_json( |
| 1594 |
msg=f"For {device_model}, port_id_end must be one of [4, 8, 12, 16]. Got {port_end}" |
| 1595 |
) |
| 1596 |
|
| 1597 |
# Validate that FC port mode range is within device FC capabilities |
| 1598 |
if port_start < device_fc_min or port_end > device_fc_max: |
| 1599 |
module.fail_json( |
| 1600 |
msg=f"FC port mode range ({port_start}-{port_end}) is outside device FC range for {device_model}. " |
| 1601 |
f"Valid FC range: {device_fc_min}-{device_fc_max}" |
| 1602 |
) |
| 1603 |
|
| 1604 |
def validate_fc_port_range(fc_configs, port_type): |
| 1605 |
"""Helper function to validate FC ports are within FC port mode range and device capabilities.""" |
| 1606 |
if not fc_configs: |
| 1607 |
return |
| 1608 |
for fc_config in fc_configs: |
| 1609 |
if fc_config.get('state', 'present') == 'present': |
| 1610 |
try: |
| 1611 |
port_info = parse_port_id(fc_config['port_id']) |
| 1612 |
# For aggregate ports, check the base port; for regular ports, check the port itself |
| 1613 |
check_port = port_info['aggregate_port_id'] if port_info['is_aggregate'] else port_info['port_id'] |
| 1614 |
|
| 1615 |
# Special validation for FC breakout ports |
| 1616 |
if port_info['is_aggregate']: |
| 1617 |
# FC roles on aggregate ports (FC breakout) are only supported on specific devices |
| 1618 |
if device_model not in ['UCS-FI-6536', 'UCSX-S9108-100G']: |
| 1619 |
module.fail_json( |
| 1620 |
msg=f"FC roles on breakout ports (aggregate ports) are only supported on UCS-FI-6536 and UCSX-S9108-100G. " |
| 1621 |
f"Device {device_model} does not support {port_type} on breakout port {fc_config['port_id']}" |
| 1622 |
) |
| 1623 |
|
| 1624 |
# Validate against FC port mode range |
| 1625 |
if check_port < port_start or check_port > port_end: |
| 1626 |
module.fail_json( |
| 1627 |
msg=f"{port_type} port {fc_config['port_id']} is outside the FC port mode range ({port_start}-{port_end})" |
| 1628 |
) |
| 1629 |
|
| 1630 |
# Validate against device FC capabilities |
| 1631 |
validate_fc_port_range_for_device(module, check_port, device_model) |
| 1632 |
|
| 1633 |
# Validate admin speed for FC ports |
| 1634 |
admin_speed = fc_config.get('admin_speed') |
| 1635 |
if admin_speed and admin_speed != 'Auto': |
| 1636 |
validate_admin_speed_for_device(module, check_port, admin_speed, device_model, f"{port_type} port") |
| 1637 |
|
| 1638 |
except ValueError as e: |
| 1639 |
module.fail_json(msg=f"Invalid {port_type} port specification: {e}") |
| 1640 |
|
| 1641 |
# Validate both FC port types |
| 1642 |
validate_fc_port_range(fc_uplink_ports, "FC Uplink") |
| 1643 |
validate_fc_port_range(fc_storage_ports, "FC Storage") |
| 1644 |
|
| 1645 |
|
| 1646 |
def validate_server_port_constraints(module): |
| 1647 |
""" |
| 1648 |
Validate server port specific constraints with device model validation. |
| 1649 |
|
| 1650 |
Args: |
| 1651 |
module: AnsibleModule instance |
| 1652 |
""" |
| 1653 |
server_ports = module.params.get('server_ports') |
| 1654 |
device_model = module.params.get('device_model') |
| 1655 |
|
| 1656 |
if not server_ports: |
| 1657 |
return |
| 1658 |
|
| 1659 |
for server_config in server_ports: |
| 1660 |
if server_config.get('state', 'present') == 'present': |
| 1661 |
manual_numbering = server_config.get('manual_numbering', False) |
| 1662 |
preferred_device_type = server_config.get('preferred_device_type') |
| 1663 |
preferred_device_id = server_config.get('preferred_device_id') |
| 1664 |
port_id = server_config['port_id'] |
| 1665 |
|
| 1666 |
# Parse port ID to check if it's an aggregate port |
| 1667 |
port_info = parse_port_id(port_id) |
| 1668 |
check_port = port_info['aggregate_port_id'] if port_info['is_aggregate'] else port_info['port_id'] |
| 1669 |
|
| 1670 |
# Device model specific validation |
| 1671 |
validate_port_range_for_device(module, check_port, device_model, "Server port") |
| 1672 |
|
| 1673 |
# Manual numbering cannot be used with aggregate ports |
| 1674 |
if manual_numbering and port_info['is_aggregate']: |
| 1675 |
module.fail_json( |
| 1676 |
msg=f"manual_numbering cannot be true for aggregate port {port_id}. Manual numbering is not supported on breakout/aggregate ports." |
| 1677 |
) |
| 1678 |
|
| 1679 |
# If manual_numbering is true, device type and device ID are required |
| 1680 |
if manual_numbering: |
| 1681 |
if not preferred_device_type: |
| 1682 |
# Default to 'Chassis' if not specified when manual numbering is enabled |
| 1683 |
server_config['preferred_device_type'] = 'Chassis' |
| 1684 |
preferred_device_type = 'Chassis' |
| 1685 |
|
| 1686 |
if not preferred_device_id: |
| 1687 |
module.fail_json( |
| 1688 |
msg=f"preferred_device_id is required when manual_numbering is true for server port {port_id}" |
| 1689 |
) |
| 1690 |
|
| 1691 |
# If preferred_device_type is specified, preferred_device_id is required |
| 1692 |
if preferred_device_type and not preferred_device_id: |
| 1693 |
module.fail_json( |
| 1694 |
msg=f"preferred_device_id is required when preferred_device_type is specified for server port {server_config['port_id']}" |
| 1695 |
) |
| 1696 |
|
| 1697 |
# If preferred_device_id is specified, preferred_device_type is required |
| 1698 |
if preferred_device_id and not preferred_device_type: |
| 1699 |
module.fail_json( |
| 1700 |
msg=f"preferred_device_type is required when preferred_device_id is specified for server port {server_config['port_id']}" |
| 1701 |
) |
| 1702 |
|
| 1703 |
|
| 1704 |
def validate_appliance_port_constraints(module): |
| 1705 |
""" |
| 1706 |
Validate appliance port specific constraints with device model validation. |
| 1707 |
|
| 1708 |
Args: |
| 1709 |
module: AnsibleModule instance |
| 1710 |
""" |
| 1711 |
appliance_ports = module.params.get('appliance_ports') |
| 1712 |
device_model = module.params.get('device_model') |
| 1713 |
|
| 1714 |
if not appliance_ports: |
| 1715 |
return |
| 1716 |
|
| 1717 |
for appliance_config in appliance_ports: |
| 1718 |
if appliance_config.get('state', 'present') == 'present': |
| 1719 |
try: |
| 1720 |
port_info = parse_port_id(appliance_config['port_id']) |
| 1721 |
# For aggregate ports, check the base port; for regular ports, check the port itself |
| 1722 |
check_port = port_info['aggregate_port_id'] if port_info['is_aggregate'] else port_info['port_id'] |
| 1723 |
admin_speed = appliance_config.get('admin_speed', 'Auto') |
| 1724 |
|
| 1725 |
# Device model specific validation |
| 1726 |
validate_port_range_for_device(module, check_port, device_model, "Appliance port") |
| 1727 |
|
| 1728 |
# Validate admin speed for the device model and port |
| 1729 |
validate_admin_speed_for_device(module, check_port, admin_speed, device_model, "Appliance port") |
| 1730 |
|
| 1731 |
except ValueError as e: |
| 1732 |
module.fail_json(msg=f"Invalid Appliance port specification: {e}") |
| 1733 |
|
| 1734 |
|
| 1735 |
def validate_port_channel_constraints(module): |
| 1736 |
""" |
| 1737 |
Validate port channel specific constraints. |
| 1738 |
|
| 1739 |
Args: |
| 1740 |
module: AnsibleModule instance |
| 1741 |
""" |
| 1742 |
# List of all port channel parameter names |
| 1743 |
port_channel_params = [ |
| 1744 |
'ethernet_uplink_port_channels', |
| 1745 |
'fc_uplink_port_channels', |
| 1746 |
'fcoe_uplink_port_channels', |
| 1747 |
'appliance_port_channels' |
| 1748 |
] |
| 1749 |
|
| 1750 |
for param_name in port_channel_params: |
| 1751 |
port_channels = module.params.get(param_name) |
| 1752 |
if not port_channels: |
| 1753 |
continue |
| 1754 |
|
| 1755 |
for pc_config in port_channels: |
| 1756 |
if pc_config.get('state', 'present') == 'present': |
| 1757 |
pc_id = pc_config.get('pc_id') |
| 1758 |
if pc_id is not None: |
| 1759 |
# PcId must be less than 257 |
| 1760 |
if pc_id >= 257: |
| 1761 |
module.fail_json( |
| 1762 |
msg=f"pc_id {pc_id} in {param_name} must be less than 256. Valid range is 1-256." |
| 1763 |
) |
| 1764 |
# PcId must be positive |
| 1765 |
if pc_id < 1: |
| 1766 |
module.fail_json( |
| 1767 |
msg=f"pc_id {pc_id} in {param_name} must be greater than 0. Valid range is 1-256." |
| 1768 |
) |
| 1769 |
|
| 1770 |
|
| 1771 |
def validate_generic_ports(module, port_configs, port_type): |
| 1772 |
""" |
| 1773 |
Generic port validation for various port types. |
| 1774 |
|
| 1775 |
Args: |
| 1776 |
module: AnsibleModule instance |
| 1777 |
port_configs: List of port configurations |
| 1778 |
port_type: Type of port for error messages |
| 1779 |
""" |
| 1780 |
if not port_configs: |
| 1781 |
return |
| 1782 |
|
| 1783 |
device_model = module.params.get('device_model') |
| 1784 |
|
| 1785 |
for port_config in port_configs: |
| 1786 |
if port_config.get('state', 'present') == 'present': |
| 1787 |
try: |
| 1788 |
port_info = parse_port_id(port_config['port_id']) |
| 1789 |
check_port = port_info['aggregate_port_id'] if port_info['is_aggregate'] else port_info['port_id'] |
| 1790 |
|
| 1791 |
# Device model specific validation |
| 1792 |
validate_port_range_for_device(module, check_port, device_model, port_type) |
| 1793 |
|
| 1794 |
# Validate admin speed if present |
| 1795 |
admin_speed = port_config.get('admin_speed') |
| 1796 |
if admin_speed and admin_speed != 'Auto': |
| 1797 |
validate_admin_speed_for_device(module, check_port, admin_speed, device_model, port_type) |
| 1798 |
|
| 1799 |
except ValueError as e: |
| 1800 |
module.fail_json(msg=f"Invalid {port_type} specification: {e}") |
| 1801 |
|
| 1802 |
|
| 1803 |
def validate_input(module): |
| 1804 |
""" |
| 1805 |
Validate module input parameters with comprehensive device model support. |
| 1806 |
|
| 1807 |
Args: |
| 1808 |
module: AnsibleModule instance |
| 1809 |
""" |
| 1810 |
# Validate port ID uniqueness across all port types |
| 1811 |
validate_port_id_uniqueness(module) |
| 1812 |
|
| 1813 |
# Validate FC port constraints |
| 1814 |
validate_fc_port_constraints(module) |
| 1815 |
|
| 1816 |
# Validate server port constraints |
| 1817 |
validate_server_port_constraints(module) |
| 1818 |
|
| 1819 |
# Validate appliance port constraints |
| 1820 |
validate_appliance_port_constraints(module) |
| 1821 |
|
| 1822 |
# Validate ethernet uplink ports |
| 1823 |
validate_generic_ports(module, module.params.get('ethernet_uplink_ports'), "Ethernet Uplink port") |
| 1824 |
|
| 1825 |
# Validate fcoe uplink ports |
| 1826 |
validate_generic_ports(module, module.params.get('fcoe_uplink_ports'), "FCoE Uplink port") |
| 1827 |
|
| 1828 |
# Validate port channel constraints |
| 1829 |
validate_port_channel_constraints(module) |
| 1830 |
|
| 1831 |
# Validate breakout port configurations |
| 1832 |
breakout_ports = module.params.get('breakout_ports') |
| 1833 |
if breakout_ports: |
| 1834 |
for breakout_config in breakout_ports: |
| 1835 |
if breakout_config.get('state', 'present') == 'present': |
| 1836 |
validate_breakout_port_config(module, breakout_config) |
| 1837 |
|
| 1838 |
# Validate uplink port channel configurations |
| 1839 |
uplink_port_channels = module.params.get('uplink_port_channels') |
| 1840 |
if uplink_port_channels: |
| 1841 |
for pc_config in uplink_port_channels: |
| 1842 |
if pc_config.get('state', 'present') == 'present': |
| 1843 |
validate_uplink_port_channel_config(module, pc_config) |
| 1844 |
|
| 1845 |
|
| 1846 |
def resolve_policy_moid(intersight, policy_cache, resource_path, policy_name, policy_type): |
| 1847 |
""" |
| 1848 |
Resolve policy name to MOID with caching and organization scoping. |
| 1849 |
|
| 1850 |
Args: |
| 1851 |
intersight: IntersightModule instance |
| 1852 |
policy_cache: Dictionary for caching policy MOIDs |
| 1853 |
resource_path: API resource path for the policy |
| 1854 |
policy_name: Name of the policy to resolve |
| 1855 |
policy_type: Type of policy for error messages |
| 1856 |
|
| 1857 |
Returns: |
| 1858 |
MOID of the policy or None if not found |
| 1859 |
""" |
| 1860 |
cache_key = f"{resource_path}:{policy_name}" |
| 1861 |
|
| 1862 |
if cache_key in policy_cache: |
| 1863 |
return policy_cache[cache_key] |
| 1864 |
|
| 1865 |
organization_name = intersight.module.params['organization'] |
| 1866 |
moid = intersight.get_moid_by_name_and_org( |
| 1867 |
resource_path=resource_path, |
| 1868 |
resource_name=policy_name, |
| 1869 |
organization_name=organization_name |
| 1870 |
) |
| 1871 |
|
| 1872 |
if not moid: |
| 1873 |
intersight.module.fail_json(msg=f"{policy_type} '{policy_name}' not found in organization '{organization_name}'") |
| 1874 |
|
| 1875 |
policy_cache[cache_key] = moid |
| 1876 |
return moid |
| 1877 |
|
| 1878 |
|
| 1879 |
def build_port_policy_filter(api_body): |
| 1880 |
""" |
| 1881 |
Build specific filter string for port policy secondary resources. |
| 1882 |
|
| 1883 |
Creates a precise filter to identify exactly one resource by combining: |
| 1884 |
- PortPolicy.Moid (required for all port policy resources) |
| 1885 |
- SlotId (always 1, required for port-specific resources) |
| 1886 |
- Resource-specific identifiers (PortId, PcId, PortIdStart/End, AggregatePortId) |
| 1887 |
|
| 1888 |
Args: |
| 1889 |
api_body: Dictionary containing the API body |
| 1890 |
|
| 1891 |
Returns: |
| 1892 |
Filter string for querying the specific resource |
| 1893 |
""" |
| 1894 |
filter_conditions = [] |
| 1895 |
|
| 1896 |
# Always filter by PortPolicy - required for all port policy resources |
| 1897 |
if 'PortPolicy' in api_body: |
| 1898 |
if isinstance(api_body['PortPolicy'], dict) and 'Moid' in api_body['PortPolicy']: |
| 1899 |
filter_conditions.append(f"PortPolicy.Moid eq '{api_body['PortPolicy']['Moid']}'") |
| 1900 |
elif isinstance(api_body['PortPolicy'], str): |
| 1901 |
filter_conditions.append(f"PortPolicy.Moid eq '{api_body['PortPolicy']}'") |
| 1902 |
|
| 1903 |
# Add PcId filter for port channels (most specific identifier) |
| 1904 |
if 'PcId' in api_body: |
| 1905 |
filter_conditions.append(f"PcId eq {api_body['PcId']}") |
| 1906 |
# Add PortId filter for individual ports |
| 1907 |
elif 'PortId' in api_body: |
| 1908 |
filter_conditions.append(f"PortId eq {api_body['PortId']}") |
| 1909 |
# Add AggregatePortId filter for aggregate ports (makes port unique) |
| 1910 |
if 'AggregatePortId' in api_body: |
| 1911 |
filter_conditions.append(f"AggregatePortId eq {api_body['AggregatePortId']}") |
| 1912 |
# Add PortIdStart/PortIdEnd for breakout ports and FC port modes |
| 1913 |
elif 'PortIdStart' in api_body and 'PortIdEnd' in api_body: |
| 1914 |
filter_conditions.append(f"PortIdStart eq {api_body['PortIdStart']}") |
| 1915 |
filter_conditions.append(f"PortIdEnd eq {api_body['PortIdEnd']}") |
| 1916 |
|
| 1917 |
return ' and '.join(filter_conditions) |
| 1918 |
|
| 1919 |
|
| 1920 |
def configure_port_policy_resource(intersight, resource_path, state): |
| 1921 |
""" |
| 1922 |
Configure a port policy secondary resource using proper field-based filtering. |
| 1923 |
|
| 1924 |
Args: |
| 1925 |
intersight: IntersightModule instance with api_body already set |
| 1926 |
resource_path: API resource path |
| 1927 |
state: Resource state ('present' or 'absent') |
| 1928 |
|
| 1929 |
Returns: |
| 1930 |
MOID of the configured resource or None |
| 1931 |
""" |
| 1932 |
# Build the appropriate filter for this resource type |
| 1933 |
filter_str = build_port_policy_filter(intersight.api_body) |
| 1934 |
|
| 1935 |
# Use the enhanced configure_secondary_resource with custom filter |
| 1936 |
return intersight.configure_secondary_resource( |
| 1937 |
resource_path=resource_path, |
| 1938 |
state=state, |
| 1939 |
custom_filter=filter_str |
| 1940 |
) |
| 1941 |
|
| 1942 |
|
| 1943 |
def configure_generic_port_channels(intersight, policy_cache, port_policy_moid, port_channels, build_func, resource_path, requires_policy_cache=True): |
| 1944 |
""" |
| 1945 |
Generic function to configure port channels for the port policy. |
| 1946 |
|
| 1947 |
Args: |
| 1948 |
intersight: IntersightModule instance |
| 1949 |
policy_cache: Dictionary for caching policy MOIDs |
| 1950 |
port_policy_moid: MOID of the port policy |
| 1951 |
port_channels: List of port channel configurations |
| 1952 |
build_func: Function to build the API body |
| 1953 |
resource_path: API resource path |
| 1954 |
requires_policy_cache: Whether the build function requires policy cache |
| 1955 |
|
| 1956 |
Returns: |
| 1957 |
Dictionary mapping pc_id to MOID for created port channels |
| 1958 |
""" |
| 1959 |
pc_moids = {} |
| 1960 |
|
| 1961 |
for pc_config in port_channels: |
| 1962 |
pc_state = pc_config.get('state', 'present') |
| 1963 |
pc_id = pc_config['pc_id'] |
| 1964 |
|
| 1965 |
# Build API body using the provided build function (needed for both create and delete to build filter) |
| 1966 |
if requires_policy_cache: |
| 1967 |
intersight.api_body = build_func(intersight, policy_cache, pc_config, port_policy_moid) |
| 1968 |
else: |
| 1969 |
intersight.api_body = build_func(pc_config, port_policy_moid) |
| 1970 |
|
| 1971 |
# Configure the port channel using port policy specific handler |
| 1972 |
moid = configure_port_policy_resource( |
| 1973 |
intersight, resource_path, pc_state |
| 1974 |
) |
| 1975 |
|
| 1976 |
if pc_state == 'present' and moid: |
| 1977 |
pc_moids[pc_id] = moid |
| 1978 |
|
| 1979 |
return pc_moids |
| 1980 |
|
| 1981 |
|
| 1982 |
def configure_generic_ports(intersight, policy_cache, port_policy_moid, port_configs, build_func, resource_path, requires_policy_cache=True): |
| 1983 |
""" |
| 1984 |
Generic function to configure individual ports for the port policy. |
| 1985 |
|
| 1986 |
Args: |
| 1987 |
intersight: IntersightModule instance |
| 1988 |
policy_cache: Dictionary for caching policy MOIDs |
| 1989 |
port_policy_moid: MOID of the port policy |
| 1990 |
port_configs: List of port configurations |
| 1991 |
build_func: Function to build the API body |
| 1992 |
resource_path: API resource path |
| 1993 |
requires_policy_cache: Whether the build function requires policy cache |
| 1994 |
|
| 1995 |
Returns: |
| 1996 |
List of API responses for all configured ports |
| 1997 |
""" |
| 1998 |
port_responses = [] |
| 1999 |
|
| 2000 |
for port_config in port_configs: |
| 2001 |
port_state = port_config.get('state', 'present') |
| 2002 |
|
| 2003 |
# Build API body using the provided build function (needed for both create and delete to build filter) |
| 2004 |
if requires_policy_cache: |
| 2005 |
intersight.api_body = build_func(intersight, policy_cache, port_config, port_policy_moid) |
| 2006 |
else: |
| 2007 |
intersight.api_body = build_func(port_config, port_policy_moid) |
| 2008 |
|
| 2009 |
# Configure the port using port policy specific handler |
| 2010 |
configure_port_policy_resource( |
| 2011 |
intersight, resource_path, port_state |
| 2012 |
) |
| 2013 |
|
| 2014 |
# Collect the response for this port |
| 2015 |
if intersight.result.get('api_response'): |
| 2016 |
port_responses.append(intersight.result['api_response']) |
| 2017 |
|
| 2018 |
return port_responses |
| 2019 |
|
| 2020 |
|
| 2021 |
def resolve_optional_policies(intersight, policy_cache, config, api_body, policy_mappings): |
| 2022 |
""" |
| 2023 |
Generic helper to resolve optional policy MOIDs and add them to API body. |
| 2024 |
|
| 2025 |
Args: |
| 2026 |
intersight: IntersightModule instance |
| 2027 |
policy_cache: Dictionary to cache policy MOIDs |
| 2028 |
config: Configuration dictionary containing policy names |
| 2029 |
api_body: API body dictionary to update |
| 2030 |
policy_mappings: Dictionary mapping config keys to (api_field, resource_path, display_name) |
| 2031 |
""" |
| 2032 |
for config_key, (api_field, resource_path, display_name) in policy_mappings.items(): |
| 2033 |
if config.get(config_key): |
| 2034 |
api_body[api_field] = resolve_policy_moid( |
| 2035 |
intersight, policy_cache, |
| 2036 |
resource_path, |
| 2037 |
config[config_key], |
| 2038 |
display_name |
| 2039 |
) |
| 2040 |
|
| 2041 |
|
| 2042 |
def build_breakout_port_api_body(breakout_config, port_policy_moid): |
| 2043 |
""" |
| 2044 |
Build API body for breakout port configuration. |
| 2045 |
|
| 2046 |
Args: |
| 2047 |
breakout_config: Dictionary containing breakout port configuration |
| 2048 |
port_policy_moid: MOID of the port policy |
| 2049 |
|
| 2050 |
Returns: |
| 2051 |
Dictionary containing the API body |
| 2052 |
""" |
| 2053 |
port_id = breakout_config['port_id'] |
| 2054 |
return { |
| 2055 |
'PortPolicy': port_policy_moid, |
| 2056 |
'SlotId': 1, |
| 2057 |
'PortIdStart': port_id, |
| 2058 |
'PortIdEnd': port_id, |
| 2059 |
'CustomMode': breakout_config['custom_mode'] |
| 2060 |
} |
| 2061 |
|
| 2062 |
|
| 2063 |
def build_server_port_api_body(server_config, port_policy_moid): |
| 2064 |
""" |
| 2065 |
Build API body for server port configuration. |
| 2066 |
|
| 2067 |
Args: |
| 2068 |
server_config: Dictionary containing server port configuration |
| 2069 |
port_policy_moid: MOID of the port policy |
| 2070 |
|
| 2071 |
Returns: |
| 2072 |
Dictionary containing the API body |
| 2073 |
""" |
| 2074 |
# Parse port ID to handle aggregate ports |
| 2075 |
port_info = parse_port_id(server_config['port_id']) |
| 2076 |
|
| 2077 |
api_body = { |
| 2078 |
'PortPolicy': port_policy_moid, |
| 2079 |
'SlotId': 1, |
| 2080 |
'PortId': port_info['port_id'], |
| 2081 |
'Fec': server_config.get('fec', 'Auto'), |
| 2082 |
'AutoNegotiationDisabled': server_config.get('manual_numbering', False) |
| 2083 |
} |
| 2084 |
|
| 2085 |
# Add aggregate port ID if this is an aggregate port |
| 2086 |
if port_info['is_aggregate']: |
| 2087 |
api_body['AggregatePortId'] = port_info['aggregate_port_id'] |
| 2088 |
|
| 2089 |
if server_config.get('user_label'): |
| 2090 |
api_body['UserLabel'] = server_config['user_label'] |
| 2091 |
|
| 2092 |
# Add preferred device configuration if specified |
| 2093 |
if server_config.get('preferred_device_type'): |
| 2094 |
api_body['PreferredDeviceType'] = server_config['preferred_device_type'] |
| 2095 |
if server_config.get('preferred_device_id'): |
| 2096 |
api_body['PreferredDeviceId'] = server_config['preferred_device_id'] |
| 2097 |
|
| 2098 |
return api_body |
| 2099 |
|
| 2100 |
|
| 2101 |
def build_port_channel_ports_list(ports): |
| 2102 |
""" |
| 2103 |
Build the Ports list for port channel API body. |
| 2104 |
|
| 2105 |
Args: |
| 2106 |
ports: List of port configurations with port_id |
| 2107 |
|
| 2108 |
Returns: |
| 2109 |
List of formatted port dictionaries |
| 2110 |
""" |
| 2111 |
port_list = [] |
| 2112 |
for port in ports: |
| 2113 |
port_input = port['port_id'] |
| 2114 |
|
| 2115 |
port_info = parse_port_id(port_input) |
| 2116 |
port_entry = { |
| 2117 |
'PortId': port_info['port_id'], |
| 2118 |
'SlotId': 1, |
| 2119 |
'id': port_info['display_name'] |
| 2120 |
} |
| 2121 |
|
| 2122 |
if port_info['is_aggregate']: |
| 2123 |
port_entry['AggregatePortId'] = port_info['aggregate_port_id'] |
| 2124 |
|
| 2125 |
port_list.append(port_entry) |
| 2126 |
|
| 2127 |
return port_list |
| 2128 |
|
| 2129 |
|
| 2130 |
def build_ethernet_uplink_pc_api_body(intersight, policy_cache, pc_config, port_policy_moid): |
| 2131 |
""" |
| 2132 |
Build API body for Ethernet uplink port channel configuration. |
| 2133 |
|
| 2134 |
Args: |
| 2135 |
intersight: IntersightModule instance |
| 2136 |
policy_cache: Dictionary for caching policy MOIDs |
| 2137 |
pc_config: Dictionary containing port channel configuration |
| 2138 |
port_policy_moid: MOID of the port policy |
| 2139 |
|
| 2140 |
Returns: |
| 2141 |
Dictionary containing the API body |
| 2142 |
""" |
| 2143 |
api_body = { |
| 2144 |
'PortPolicy': port_policy_moid, |
| 2145 |
'PcId': pc_config['pc_id'], |
| 2146 |
'AdminSpeed': pc_config.get('admin_speed', 'Auto'), |
| 2147 |
'Fec': pc_config.get('fec', 'Auto'), |
| 2148 |
'Ports': build_port_channel_ports_list(pc_config.get('ports', [])) |
| 2149 |
} |
| 2150 |
|
| 2151 |
if pc_config.get('user_label'): |
| 2152 |
api_body['UserLabel'] = pc_config['user_label'] |
| 2153 |
|
| 2154 |
# Resolve Ethernet Network Group Policy MOIDs |
| 2155 |
if pc_config.get('eth_network_group_policy_names'): |
| 2156 |
eth_network_group_moids = [] |
| 2157 |
for policy_name in pc_config['eth_network_group_policy_names']: |
| 2158 |
moid = resolve_policy_moid( |
| 2159 |
intersight, policy_cache, |
| 2160 |
'/fabric/EthNetworkGroupPolicies', |
| 2161 |
policy_name, |
| 2162 |
'Ethernet Network Group Policy' |
| 2163 |
) |
| 2164 |
eth_network_group_moids.append(moid) |
| 2165 |
api_body['EthNetworkGroupPolicy'] = eth_network_group_moids |
| 2166 |
|
| 2167 |
# Resolve optional policies using generic helper |
| 2168 |
policy_mappings = { |
| 2169 |
'flow_control_policy_name': ('FlowControlPolicy', '/fabric/FlowControlPolicies', 'Flow Control Policy'), |
| 2170 |
'link_aggregation_policy_name': ('LinkAggregationPolicy', '/fabric/LinkAggregationPolicies', 'Link Aggregation Policy'), |
| 2171 |
'link_control_policy_name': ('LinkControlPolicy', '/fabric/LinkControlPolicies', 'Link Control Policy') |
| 2172 |
} |
| 2173 |
|
| 2174 |
resolve_optional_policies(intersight, policy_cache, pc_config, api_body, policy_mappings) |
| 2175 |
|
| 2176 |
return api_body |
| 2177 |
|
| 2178 |
|
| 2179 |
def build_fc_uplink_pc_api_body(pc_config, port_policy_moid): |
| 2180 |
""" |
| 2181 |
Build API body for FC uplink port channel configuration. |
| 2182 |
|
| 2183 |
Args: |
| 2184 |
pc_config: Dictionary containing port channel configuration |
| 2185 |
port_policy_moid: MOID of the port policy |
| 2186 |
|
| 2187 |
Returns: |
| 2188 |
Dictionary containing the API body |
| 2189 |
""" |
| 2190 |
api_body = { |
| 2191 |
'PortPolicy': port_policy_moid, |
| 2192 |
'PcId': pc_config['pc_id'], |
| 2193 |
'AdminSpeed': pc_config.get('admin_speed', '16Gbps'), |
| 2194 |
'VsanId': pc_config.get('vsan_id', 1), |
| 2195 |
'Ports': build_port_channel_ports_list(pc_config.get('ports', [])) |
| 2196 |
} |
| 2197 |
|
| 2198 |
if pc_config.get('user_label'): |
| 2199 |
api_body['UserLabel'] = pc_config['user_label'] |
| 2200 |
|
| 2201 |
return api_body |
| 2202 |
|
| 2203 |
|
| 2204 |
def build_fcoe_uplink_pc_api_body(intersight, policy_cache, pc_config, port_policy_moid): |
| 2205 |
""" |
| 2206 |
Build API body for FCoE uplink port channel configuration. |
| 2207 |
|
| 2208 |
Args: |
| 2209 |
intersight: IntersightModule instance |
| 2210 |
policy_cache: Dictionary for caching policy MOIDs |
| 2211 |
pc_config: Dictionary containing port channel configuration |
| 2212 |
port_policy_moid: MOID of the port policy |
| 2213 |
|
| 2214 |
Returns: |
| 2215 |
Dictionary containing the API body |
| 2216 |
""" |
| 2217 |
api_body = { |
| 2218 |
'PortPolicy': port_policy_moid, |
| 2219 |
'PcId': pc_config['pc_id'], |
| 2220 |
'AdminSpeed': pc_config.get('admin_speed', 'Auto'), |
| 2221 |
'Fec': pc_config.get('fec', 'Auto'), |
| 2222 |
'Ports': build_port_channel_ports_list(pc_config.get('ports', [])) |
| 2223 |
} |
| 2224 |
|
| 2225 |
if pc_config.get('user_label'): |
| 2226 |
api_body['UserLabel'] = pc_config['user_label'] |
| 2227 |
|
| 2228 |
# Resolve optional policies using generic helper |
| 2229 |
policy_mappings = { |
| 2230 |
'link_aggregation_policy_name': ('LinkAggregationPolicy', '/fabric/LinkAggregationPolicies', 'Link Aggregation Policy'), |
| 2231 |
'link_control_policy_name': ('LinkControlPolicy', '/fabric/LinkControlPolicies', 'Link Control Policy') |
| 2232 |
} |
| 2233 |
|
| 2234 |
resolve_optional_policies(intersight, policy_cache, pc_config, api_body, policy_mappings) |
| 2235 |
|
| 2236 |
return api_body |
| 2237 |
|
| 2238 |
|
| 2239 |
def build_appliance_pc_api_body(intersight, policy_cache, pc_config, port_policy_moid): |
| 2240 |
""" |
| 2241 |
Build API body for appliance port channel configuration. |
| 2242 |
|
| 2243 |
Args: |
| 2244 |
intersight: IntersightModule instance |
| 2245 |
policy_cache: Dictionary for caching policy MOIDs |
| 2246 |
pc_config: Dictionary containing port channel configuration |
| 2247 |
port_policy_moid: MOID of the port policy |
| 2248 |
|
| 2249 |
Returns: |
| 2250 |
Dictionary containing the API body |
| 2251 |
""" |
| 2252 |
api_body = { |
| 2253 |
'PortPolicy': port_policy_moid, |
| 2254 |
'PcId': pc_config['pc_id'], |
| 2255 |
'AdminSpeed': pc_config.get('admin_speed', 'Auto'), |
| 2256 |
'Fec': pc_config.get('fec', 'Auto'), |
| 2257 |
'Priority': pc_config.get('priority', 'Best Effort'), |
| 2258 |
'Mode': pc_config.get('mode', 'trunk'), |
| 2259 |
'Ports': build_port_channel_ports_list(pc_config.get('ports', [])) |
| 2260 |
} |
| 2261 |
|
| 2262 |
if pc_config.get('user_label'): |
| 2263 |
api_body['UserLabel'] = pc_config['user_label'] |
| 2264 |
|
| 2265 |
# Resolve policies using generic helper |
| 2266 |
policy_mappings = { |
| 2267 |
'eth_network_group_policy_name': ('EthNetworkGroupPolicy', '/fabric/EthNetworkGroupPolicies', 'Ethernet Network Group Policy'), |
| 2268 |
'eth_network_control_policy_name': ('EthNetworkControlPolicy', '/fabric/EthNetworkControlPolicies', 'Ethernet Network Control Policy'), |
| 2269 |
'link_aggregation_policy_name': ('LinkAggregationPolicy', '/fabric/LinkAggregationPolicies', 'Link Aggregation Policy') |
| 2270 |
} |
| 2271 |
|
| 2272 |
resolve_optional_policies(intersight, policy_cache, pc_config, api_body, policy_mappings) |
| 2273 |
|
| 2274 |
return api_body |
| 2275 |
|
| 2276 |
|
| 2277 |
def get_port_channel_moid(intersight, port_policy_moid, pc_id, resource_path): |
| 2278 |
""" |
| 2279 |
Get the MOID of a port channel by pc_id and resource path. |
| 2280 |
|
| 2281 |
Args: |
| 2282 |
intersight: IntersightModule instance |
| 2283 |
port_policy_moid: MOID of the port policy |
| 2284 |
pc_id: Port channel ID |
| 2285 |
resource_path: API resource path (e.g., '/fabric/UplinkPcRoles', '/fabric/FcoeUplinkPcRoles') |
| 2286 |
|
| 2287 |
Returns: |
| 2288 |
MOID of the port channel or None if not found |
| 2289 |
""" |
| 2290 |
# Build filter for the port channel |
| 2291 |
filter_conditions = [f"PortPolicy.Moid eq '{port_policy_moid}'"] |
| 2292 |
filter_conditions.append(f"PcId eq {pc_id}") |
| 2293 |
filter_str = ' and '.join(filter_conditions) |
| 2294 |
|
| 2295 |
# Query the port channel |
| 2296 |
intersight.get_resource( |
| 2297 |
resource_path=resource_path, |
| 2298 |
query_params={'$filter': filter_str, '$select': 'Moid'} |
| 2299 |
) |
| 2300 |
|
| 2301 |
if intersight.result.get('api_response'): |
| 2302 |
return intersight.result['api_response'].get('Moid') |
| 2303 |
|
| 2304 |
return None |
| 2305 |
|
| 2306 |
|
| 2307 |
def get_port_role_moid(intersight, port_policy_moid, port_id, resource_path): |
| 2308 |
""" |
| 2309 |
Generic function to get the MOID of a port role by port ID and resource path. |
| 2310 |
|
| 2311 |
Args: |
| 2312 |
intersight: IntersightModule instance |
| 2313 |
port_policy_moid: MOID of the port policy |
| 2314 |
port_id: Port identifier (e.g., '14' or '49/1') |
| 2315 |
resource_path: API resource path (e.g., '/fabric/UplinkRoles', '/fabric/FcoeUplinkRoles') |
| 2316 |
|
| 2317 |
Returns: |
| 2318 |
MOID of the port role or None if not found |
| 2319 |
""" |
| 2320 |
# Parse port ID to handle aggregate ports |
| 2321 |
try: |
| 2322 |
port_info = parse_port_id(port_id) |
| 2323 |
except ValueError as e: |
| 2324 |
intersight.module.fail_json(msg=f"Invalid port ID format '{port_id}': {e}") |
| 2325 |
|
| 2326 |
# Build filter for the port role |
| 2327 |
filter_conditions = [f"PortPolicy.Moid eq '{port_policy_moid}'"] |
| 2328 |
filter_conditions.append(f"PortId eq {port_info['port_id']}") |
| 2329 |
|
| 2330 |
if port_info['is_aggregate']: |
| 2331 |
filter_conditions.append(f"AggregatePortId eq {port_info['aggregate_port_id']}") |
| 2332 |
|
| 2333 |
filter_str = ' and '.join(filter_conditions) |
| 2334 |
|
| 2335 |
# Query the port role |
| 2336 |
intersight.get_resource( |
| 2337 |
resource_path=resource_path, |
| 2338 |
query_params={'$filter': filter_str, '$select': 'Moid'} |
| 2339 |
) |
| 2340 |
|
| 2341 |
if intersight.result.get('api_response'): |
| 2342 |
return intersight.result['api_response'].get('Moid') |
| 2343 |
|
| 2344 |
return None |
| 2345 |
|
| 2346 |
|
| 2347 |
def get_uplink_port_moid(intersight, port_policy_moid, port_id): |
| 2348 |
""" |
| 2349 |
Get the MOID of an uplink port role by port ID. |
| 2350 |
|
| 2351 |
Args: |
| 2352 |
intersight: IntersightModule instance |
| 2353 |
port_policy_moid: MOID of the port policy |
| 2354 |
port_id: Port identifier (e.g., '14' or '49/1') |
| 2355 |
|
| 2356 |
Returns: |
| 2357 |
MOID of the uplink port role or None if not found |
| 2358 |
""" |
| 2359 |
return get_port_role_moid(intersight, port_policy_moid, port_id, '/fabric/UplinkRoles') |
| 2360 |
|
| 2361 |
|
| 2362 |
def get_fcoe_uplink_port_moid(intersight, port_policy_moid, port_id): |
| 2363 |
""" |
| 2364 |
Get the MOID of an FCoE uplink port role by port ID. |
| 2365 |
|
| 2366 |
Args: |
| 2367 |
intersight: IntersightModule instance |
| 2368 |
port_policy_moid: MOID of the port policy |
| 2369 |
port_id: Port identifier (e.g., '14' or '49/1') |
| 2370 |
|
| 2371 |
Returns: |
| 2372 |
MOID of the FCoE uplink port role or None if not found |
| 2373 |
""" |
| 2374 |
return get_port_role_moid(intersight, port_policy_moid, port_id, '/fabric/FcoeUplinkRoles') |
| 2375 |
|
| 2376 |
|
| 2377 |
def build_pin_group_api_body(intersight, pin_group_config, port_policy_moid, uplink_pc_moids): |
| 2378 |
""" |
| 2379 |
Build API body for pin group configuration (both LAN and SAN). |
| 2380 |
|
| 2381 |
Args: |
| 2382 |
intersight: IntersightModule instance |
| 2383 |
pin_group_config: Dictionary containing pin group configuration |
| 2384 |
port_policy_moid: MOID of the port policy |
| 2385 |
uplink_pc_moids: Dictionary mapping pc_id to MOID |
| 2386 |
|
| 2387 |
Returns: |
| 2388 |
Dictionary containing the API body |
| 2389 |
""" |
| 2390 |
api_body = { |
| 2391 |
'PortPolicy': port_policy_moid, |
| 2392 |
'Name': pin_group_config['name'] |
| 2393 |
} |
| 2394 |
|
| 2395 |
# Determine the pin group type and target interface type |
| 2396 |
pin_group_type = pin_group_config['pin_group_type'] |
| 2397 |
target_type = pin_group_config['target_interface_type'] |
| 2398 |
target_name = pin_group_config['target_interface_name'] |
| 2399 |
|
| 2400 |
if target_type == 'pc': |
| 2401 |
# Look up the MOID for the uplink port channel |
| 2402 |
pc_id = int(target_name) |
| 2403 |
pc_moid = None |
| 2404 |
|
| 2405 |
# First, try to get from current run's port channels |
| 2406 |
if pc_id in uplink_pc_moids: |
| 2407 |
pc_moid = uplink_pc_moids[pc_id] |
| 2408 |
else: |
| 2409 |
# If not found in current run, try to fetch from API based on pin group type |
| 2410 |
if pin_group_type == 'lan': |
| 2411 |
# For LAN pin groups, try Ethernet uplink, FCoE uplink, and appliance port channels |
| 2412 |
pc_moid = get_port_channel_moid(intersight, port_policy_moid, pc_id, '/fabric/UplinkPcRoles') |
| 2413 |
else: # san |
| 2414 |
# For SAN pin groups, try FCoE uplink port channels first, then others |
| 2415 |
pc_moid = get_port_channel_moid(intersight, port_policy_moid, pc_id, '/fabric/FcoeUplinkPcRoles') |
| 2416 |
|
| 2417 |
if not pc_moid: |
| 2418 |
intersight.module.fail_json( |
| 2419 |
msg=f"Uplink port channel with pc_id {pc_id} not found for pin group '{pin_group_config['name']}'. " |
| 2420 |
f"Make sure the port channel is configured in the same policy." |
| 2421 |
) |
| 2422 |
|
| 2423 |
# Set ObjectType based on pin group type |
| 2424 |
if pin_group_type == 'lan': |
| 2425 |
object_type = 'fabric.UplinkPcRole' |
| 2426 |
else: # san |
| 2427 |
object_type = 'fabric.FcoeUplinkPcRole' |
| 2428 |
|
| 2429 |
api_body['PinTargetInterfaceRole'] = { |
| 2430 |
'ObjectType': object_type, |
| 2431 |
'Moid': pc_moid |
| 2432 |
} |
| 2433 |
else: # target_type == 'port' |
| 2434 |
# Look up the MOID for the uplink port |
| 2435 |
if pin_group_type == 'lan': |
| 2436 |
port_moid = get_uplink_port_moid(intersight, port_policy_moid, target_name) |
| 2437 |
object_type = 'fabric.UplinkRole' |
| 2438 |
else: # san |
| 2439 |
port_moid = get_fcoe_uplink_port_moid(intersight, port_policy_moid, target_name) |
| 2440 |
object_type = 'fabric.FcoeUplinkRole' |
| 2441 |
|
| 2442 |
if not port_moid: |
| 2443 |
port_type = "Ethernet uplink" if pin_group_type == 'lan' else "FCoE uplink" |
| 2444 |
intersight.module.fail_json( |
| 2445 |
msg=f"{port_type} port '{target_name}' not found for pin group '{pin_group_config['name']}'. " |
| 2446 |
f"Make sure the port is configured as a {port_type.lower()} port in the same policy." |
| 2447 |
) |
| 2448 |
|
| 2449 |
api_body['PinTargetInterfaceRole'] = { |
| 2450 |
'ObjectType': object_type, |
| 2451 |
'Moid': port_moid |
| 2452 |
} |
| 2453 |
|
| 2454 |
return api_body |
| 2455 |
|
| 2456 |
|
| 2457 |
def build_fc_port_mode_api_body(fc_config, port_policy_moid): |
| 2458 |
""" |
| 2459 |
Build API body for FC port mode configuration. |
| 2460 |
|
| 2461 |
Args: |
| 2462 |
fc_config: Dictionary containing FC port mode configuration |
| 2463 |
port_policy_moid: MOID of the port policy |
| 2464 |
|
| 2465 |
Returns: |
| 2466 |
Dictionary containing the API body |
| 2467 |
""" |
| 2468 |
return { |
| 2469 |
'PortPolicy': port_policy_moid, |
| 2470 |
'PortIdStart': fc_config.get('port_id_start', 1), |
| 2471 |
'PortIdEnd': fc_config['port_id_end'], |
| 2472 |
'SlotId': 1 |
| 2473 |
} |
| 2474 |
|
| 2475 |
|
| 2476 |
def build_fc_uplink_port_api_body(fc_config, port_policy_moid): |
| 2477 |
""" |
| 2478 |
Build API body for FC Uplink port configuration. |
| 2479 |
|
| 2480 |
Args: |
| 2481 |
fc_config: Dictionary containing FC Uplink port configuration |
| 2482 |
port_policy_moid: MOID of the port policy |
| 2483 |
|
| 2484 |
Returns: |
| 2485 |
Dictionary containing the API body |
| 2486 |
""" |
| 2487 |
# Parse port ID to handle aggregate ports |
| 2488 |
port_info = parse_port_id(fc_config['port_id']) |
| 2489 |
|
| 2490 |
api_body = { |
| 2491 |
'PortPolicy': port_policy_moid, |
| 2492 |
'SlotId': 1, |
| 2493 |
'PortId': port_info['port_id'], |
| 2494 |
'AdminSpeed': fc_config.get('admin_speed', 'Auto'), |
| 2495 |
'VsanId': fc_config['vsan_id'] |
| 2496 |
} |
| 2497 |
|
| 2498 |
# Add aggregate port ID if this is an aggregate port |
| 2499 |
if port_info['is_aggregate']: |
| 2500 |
api_body['AggregatePortId'] = port_info['aggregate_port_id'] |
| 2501 |
|
| 2502 |
if fc_config.get('user_label'): |
| 2503 |
api_body['UserLabel'] = fc_config['user_label'] |
| 2504 |
|
| 2505 |
return api_body |
| 2506 |
|
| 2507 |
|
| 2508 |
def build_fc_storage_port_api_body(fc_config, port_policy_moid): |
| 2509 |
""" |
| 2510 |
Build API body for FC Storage port configuration. |
| 2511 |
|
| 2512 |
Args: |
| 2513 |
fc_config: Dictionary containing FC Storage port configuration |
| 2514 |
port_policy_moid: MOID of the port policy |
| 2515 |
|
| 2516 |
Returns: |
| 2517 |
Dictionary containing the API body |
| 2518 |
""" |
| 2519 |
# Parse port ID to handle aggregate ports |
| 2520 |
port_info = parse_port_id(fc_config['port_id']) |
| 2521 |
|
| 2522 |
api_body = { |
| 2523 |
'PortPolicy': port_policy_moid, |
| 2524 |
'SlotId': 1, |
| 2525 |
'PortId': port_info['port_id'], |
| 2526 |
'AdminSpeed': fc_config.get('admin_speed'), |
| 2527 |
'VsanId': fc_config['vsan_id'] |
| 2528 |
} |
| 2529 |
|
| 2530 |
# Add aggregate port ID if this is an aggregate port |
| 2531 |
if port_info['is_aggregate']: |
| 2532 |
api_body['AggregatePortId'] = port_info['aggregate_port_id'] |
| 2533 |
|
| 2534 |
if fc_config.get('user_label'): |
| 2535 |
api_body['UserLabel'] = fc_config['user_label'] |
| 2536 |
|
| 2537 |
return api_body |
| 2538 |
|
| 2539 |
|
| 2540 |
def build_appliance_port_api_body(intersight, policy_cache, appliance_config, port_policy_moid): |
| 2541 |
""" |
| 2542 |
Build API body for Appliance port configuration. |
| 2543 |
|
| 2544 |
Args: |
| 2545 |
intersight: IntersightModule instance |
| 2546 |
policy_cache: Dictionary for caching policy MOIDs |
| 2547 |
appliance_config: Dictionary containing Appliance port configuration |
| 2548 |
port_policy_moid: MOID of the port policy |
| 2549 |
|
| 2550 |
Returns: |
| 2551 |
Dictionary containing the API body |
| 2552 |
""" |
| 2553 |
# Parse port ID to handle aggregate ports |
| 2554 |
port_info = parse_port_id(appliance_config['port_id']) |
| 2555 |
|
| 2556 |
api_body = { |
| 2557 |
'PortPolicy': port_policy_moid, |
| 2558 |
'SlotId': 1, |
| 2559 |
'PortId': port_info['port_id'], |
| 2560 |
'AdminSpeed': appliance_config.get('admin_speed', 'Auto'), |
| 2561 |
'Fec': appliance_config.get('fec', 'Auto'), |
| 2562 |
'Priority': appliance_config.get('priority', 'Best Effort'), |
| 2563 |
'Mode': appliance_config.get('mode', 'trunk') |
| 2564 |
} |
| 2565 |
|
| 2566 |
# Add aggregate port ID if this is an aggregate port |
| 2567 |
if port_info['is_aggregate']: |
| 2568 |
api_body['AggregatePortId'] = port_info['aggregate_port_id'] |
| 2569 |
|
| 2570 |
if appliance_config.get('user_label'): |
| 2571 |
api_body['UserLabel'] = appliance_config['user_label'] |
| 2572 |
|
| 2573 |
# Resolve policies using generic helper |
| 2574 |
policy_mappings = { |
| 2575 |
'eth_network_group_policy_name': ('EthNetworkGroupPolicy', '/fabric/EthNetworkGroupPolicies', 'Ethernet Network Group Policy'), |
| 2576 |
'eth_network_control_policy_name': ('EthNetworkControlPolicy', '/fabric/EthNetworkControlPolicies', 'Ethernet Network Control Policy') |
| 2577 |
} |
| 2578 |
|
| 2579 |
resolve_optional_policies(intersight, policy_cache, appliance_config, api_body, policy_mappings) |
| 2580 |
|
| 2581 |
return api_body |
| 2582 |
|
| 2583 |
|
| 2584 |
def build_ethernet_uplink_port_api_body(intersight, policy_cache, uplink_config, port_policy_moid): |
| 2585 |
""" |
| 2586 |
Build API body for Ethernet Uplink port configuration. |
| 2587 |
|
| 2588 |
Args: |
| 2589 |
intersight: IntersightModule instance |
| 2590 |
policy_cache: Dictionary for caching policy MOIDs |
| 2591 |
uplink_config: Dictionary containing Ethernet Uplink port configuration |
| 2592 |
port_policy_moid: MOID of the port policy |
| 2593 |
|
| 2594 |
Returns: |
| 2595 |
Dictionary containing the API body |
| 2596 |
""" |
| 2597 |
# Parse port ID to handle aggregate ports |
| 2598 |
port_info = parse_port_id(uplink_config['port_id']) |
| 2599 |
|
| 2600 |
api_body = { |
| 2601 |
'PortPolicy': port_policy_moid, |
| 2602 |
'SlotId': 1, |
| 2603 |
'PortId': port_info['port_id'], |
| 2604 |
'AdminSpeed': uplink_config.get('admin_speed', 'Auto'), |
| 2605 |
'Fec': uplink_config.get('fec', 'Auto') |
| 2606 |
} |
| 2607 |
|
| 2608 |
# Add aggregate port ID if this is an aggregate port |
| 2609 |
if port_info['is_aggregate']: |
| 2610 |
api_body['AggregatePortId'] = port_info['aggregate_port_id'] |
| 2611 |
|
| 2612 |
if uplink_config.get('user_label'): |
| 2613 |
api_body['UserLabel'] = uplink_config['user_label'] |
| 2614 |
|
| 2615 |
# Resolve Ethernet Network Group Policy MOIDs |
| 2616 |
if uplink_config.get('eth_network_group_policy_name'): |
| 2617 |
eth_network_group_moids = [] |
| 2618 |
for policy_name in uplink_config['eth_network_group_policy_name']: |
| 2619 |
moid = resolve_policy_moid( |
| 2620 |
intersight, policy_cache, |
| 2621 |
'/fabric/EthNetworkGroupPolicies', |
| 2622 |
policy_name, |
| 2623 |
'Ethernet Network Group Policy' |
| 2624 |
) |
| 2625 |
eth_network_group_moids.append(moid) |
| 2626 |
api_body['EthNetworkGroupPolicy'] = eth_network_group_moids |
| 2627 |
|
| 2628 |
# Resolve single policies using generic helper |
| 2629 |
policy_mappings = { |
| 2630 |
'flow_control_policy_name': ('FlowControlPolicy', '/fabric/FlowControlPolicies', 'Flow Control Policy'), |
| 2631 |
'link_control_policy_name': ('LinkControlPolicy', '/fabric/LinkControlPolicies', 'Link Control Policy'), |
| 2632 |
'mac_sec_policy_name': ('MacSecPolicy', '/fabric/MacSecPolicies', 'MAC Security Policy') |
| 2633 |
} |
| 2634 |
|
| 2635 |
resolve_optional_policies(intersight, policy_cache, uplink_config, api_body, policy_mappings) |
| 2636 |
|
| 2637 |
return api_body |
| 2638 |
|
| 2639 |
|
| 2640 |
def build_fcoe_uplink_port_api_body(intersight, policy_cache, fcoe_config, port_policy_moid): |
| 2641 |
""" |
| 2642 |
Build API body for FCoE Uplink port configuration. |
| 2643 |
|
| 2644 |
Args: |
| 2645 |
intersight: IntersightModule instance |
| 2646 |
policy_cache: Dictionary for caching policy MOIDs |
| 2647 |
fcoe_config: Dictionary containing FCoE Uplink port configuration |
| 2648 |
port_policy_moid: MOID of the port policy |
| 2649 |
|
| 2650 |
Returns: |
| 2651 |
Dictionary containing the API body |
| 2652 |
""" |
| 2653 |
# Parse port ID to handle aggregate ports |
| 2654 |
port_info = parse_port_id(fcoe_config['port_id']) |
| 2655 |
|
| 2656 |
api_body = { |
| 2657 |
'PortPolicy': port_policy_moid, |
| 2658 |
'SlotId': 1, |
| 2659 |
'PortId': port_info['port_id'], |
| 2660 |
'AdminSpeed': fcoe_config.get('admin_speed', 'Auto'), |
| 2661 |
'Fec': fcoe_config.get('fec', 'Auto') |
| 2662 |
} |
| 2663 |
|
| 2664 |
# Add aggregate port ID if this is an aggregate port |
| 2665 |
if port_info['is_aggregate']: |
| 2666 |
api_body['AggregatePortId'] = port_info['aggregate_port_id'] |
| 2667 |
|
| 2668 |
if fcoe_config.get('user_label'): |
| 2669 |
api_body['UserLabel'] = fcoe_config['user_label'] |
| 2670 |
|
| 2671 |
# Resolve policies using generic helper |
| 2672 |
policy_mappings = { |
| 2673 |
'link_control_policy_name': ('LinkControlPolicy', '/fabric/LinkControlPolicies', 'Link Control Policy') |
| 2674 |
} |
| 2675 |
|
| 2676 |
resolve_optional_policies(intersight, policy_cache, fcoe_config, api_body, policy_mappings) |
| 2677 |
|
| 2678 |
return api_body |
| 2679 |
|
| 2680 |
|
| 2681 |
def configure_breakout_ports(intersight, port_policy_moid, breakout_ports): |
| 2682 |
""" |
| 2683 |
Configure breakout ports for the port policy. |
| 2684 |
|
| 2685 |
Args: |
| 2686 |
intersight: IntersightModule instance |
| 2687 |
port_policy_moid: MOID of the port policy |
| 2688 |
breakout_ports: List of breakout port configurations |
| 2689 |
|
| 2690 |
Returns: |
| 2691 |
List of API responses for all configured breakout ports |
| 2692 |
""" |
| 2693 |
breakout_responses = [] |
| 2694 |
|
| 2695 |
for breakout_config in breakout_ports: |
| 2696 |
breakout_state = breakout_config.get('state', 'present') |
| 2697 |
|
| 2698 |
# Build API body for breakout port (needed for both create and delete to build filter) |
| 2699 |
intersight.api_body = build_breakout_port_api_body(breakout_config, port_policy_moid) |
| 2700 |
|
| 2701 |
# Configure the breakout port using field-based filtering |
| 2702 |
configure_port_policy_resource(intersight, '/fabric/PortModes', breakout_state) |
| 2703 |
|
| 2704 |
# Collect the response for this breakout port |
| 2705 |
if intersight.result.get('api_response'): |
| 2706 |
breakout_responses.append(intersight.result['api_response']) |
| 2707 |
|
| 2708 |
return breakout_responses |
| 2709 |
|
| 2710 |
|
| 2711 |
def configure_server_ports(intersight, port_policy_moid, server_ports): |
| 2712 |
""" |
| 2713 |
Configure server ports for the port policy. |
| 2714 |
|
| 2715 |
Args: |
| 2716 |
intersight: IntersightModule instance |
| 2717 |
port_policy_moid: MOID of the port policy |
| 2718 |
server_ports: List of server port configurations |
| 2719 |
|
| 2720 |
Returns: |
| 2721 |
List of API responses for all configured server ports |
| 2722 |
""" |
| 2723 |
server_responses = [] |
| 2724 |
|
| 2725 |
for server_config in server_ports: |
| 2726 |
server_state = server_config.get('state', 'present') |
| 2727 |
|
| 2728 |
# Build API body for server port (needed for both create and delete to build filter) |
| 2729 |
intersight.api_body = build_server_port_api_body(server_config, port_policy_moid) |
| 2730 |
|
| 2731 |
# Configure the server port using field-based filtering |
| 2732 |
configure_port_policy_resource(intersight, '/fabric/ServerRoles', server_state) |
| 2733 |
|
| 2734 |
# Collect the response for this server port |
| 2735 |
if intersight.result.get('api_response'): |
| 2736 |
server_responses.append(intersight.result['api_response']) |
| 2737 |
|
| 2738 |
return server_responses |
| 2739 |
|
| 2740 |
|
| 2741 |
def configure_ethernet_uplink_port_channels(intersight, policy_cache, port_policy_moid, port_channels): |
| 2742 |
"""Configure Ethernet uplink port channels.""" |
| 2743 |
return configure_generic_port_channels( |
| 2744 |
intersight, policy_cache, port_policy_moid, port_channels, |
| 2745 |
build_ethernet_uplink_pc_api_body, '/fabric/UplinkPcRoles' |
| 2746 |
) |
| 2747 |
|
| 2748 |
|
| 2749 |
def configure_fc_uplink_port_channels(intersight, port_policy_moid, port_channels): |
| 2750 |
"""Configure FC uplink port channels.""" |
| 2751 |
return configure_generic_port_channels( |
| 2752 |
intersight, None, port_policy_moid, port_channels, |
| 2753 |
build_fc_uplink_pc_api_body, '/fabric/FcUplinkPcRoles', |
| 2754 |
requires_policy_cache=False |
| 2755 |
) |
| 2756 |
|
| 2757 |
|
| 2758 |
def configure_fcoe_uplink_port_channels(intersight, policy_cache, port_policy_moid, port_channels): |
| 2759 |
"""Configure FCoE uplink port channels.""" |
| 2760 |
return configure_generic_port_channels( |
| 2761 |
intersight, policy_cache, port_policy_moid, port_channels, |
| 2762 |
build_fcoe_uplink_pc_api_body, '/fabric/FcoeUplinkPcRoles' |
| 2763 |
) |
| 2764 |
|
| 2765 |
|
| 2766 |
def configure_appliance_port_channels(intersight, policy_cache, port_policy_moid, port_channels): |
| 2767 |
"""Configure appliance port channels.""" |
| 2768 |
return configure_generic_port_channels( |
| 2769 |
intersight, policy_cache, port_policy_moid, port_channels, |
| 2770 |
build_appliance_pc_api_body, '/fabric/AppliancePcRoles' |
| 2771 |
) |
| 2772 |
|
| 2773 |
|
| 2774 |
def configure_pin_groups(intersight, port_policy_moid, pin_groups, uplink_pc_moids): |
| 2775 |
""" |
| 2776 |
Configure pin groups (both LAN and SAN) for the port policy. |
| 2777 |
|
| 2778 |
Args: |
| 2779 |
intersight: IntersightModule instance |
| 2780 |
port_policy_moid: MOID of the port policy |
| 2781 |
pin_groups: List of pin group configurations |
| 2782 |
uplink_pc_moids: Dictionary mapping pc_id to MOID |
| 2783 |
""" |
| 2784 |
for pin_group_config in pin_groups: |
| 2785 |
pin_group_state = pin_group_config.get('state', 'present') |
| 2786 |
pin_group_type = pin_group_config['pin_group_type'] |
| 2787 |
|
| 2788 |
# Build API body for pin group (needed for both create and delete for consistency) |
| 2789 |
if pin_group_state == 'present': |
| 2790 |
intersight.api_body = build_pin_group_api_body( |
| 2791 |
intersight, pin_group_config, port_policy_moid, uplink_pc_moids |
| 2792 |
) |
| 2793 |
|
| 2794 |
resource_name = pin_group_config['name'] |
| 2795 |
|
| 2796 |
# Determine resource path based on pin group type |
| 2797 |
if pin_group_type == 'lan': |
| 2798 |
resource_path = '/fabric/LanPinGroups' |
| 2799 |
else: # san |
| 2800 |
resource_path = '/fabric/SanPinGroups' |
| 2801 |
|
| 2802 |
# Configure the pin group |
| 2803 |
# Filter by both pin group name AND PortPolicy to avoid affecting pin groups in other policies |
| 2804 |
custom_filter = f"Name eq '{resource_name}' and PortPolicy.Moid eq '{port_policy_moid}'" |
| 2805 |
intersight.configure_secondary_resource( |
| 2806 |
resource_path=resource_path, |
| 2807 |
state=pin_group_state, |
| 2808 |
custom_filter=custom_filter |
| 2809 |
) |
| 2810 |
|
| 2811 |
|
| 2812 |
def configure_fc_port_mode(intersight, port_policy_moid, fc_port_mode): |
| 2813 |
""" |
| 2814 |
Configure FC port mode for the port policy. |
| 2815 |
|
| 2816 |
Args: |
| 2817 |
intersight: IntersightModule instance |
| 2818 |
port_policy_moid: MOID of the port policy |
| 2819 |
fc_port_mode: Dictionary containing FC port mode configuration |
| 2820 |
""" |
| 2821 |
if not fc_port_mode: |
| 2822 |
return |
| 2823 |
|
| 2824 |
fc_state = fc_port_mode.get('state', 'present') |
| 2825 |
|
| 2826 |
# Build API body for FC port mode (needed for both create and delete to build filter) |
| 2827 |
intersight.api_body = build_fc_port_mode_api_body(fc_port_mode, port_policy_moid) |
| 2828 |
|
| 2829 |
# Configure the FC port mode using field-based filtering |
| 2830 |
configure_port_policy_resource(intersight, '/fabric/PortModes', fc_state) |
| 2831 |
|
| 2832 |
|
| 2833 |
def configure_fc_uplink_ports(intersight, port_policy_moid, fc_uplink_ports): |
| 2834 |
""" |
| 2835 |
Configure FC Uplink ports for the port policy. |
| 2836 |
|
| 2837 |
Args: |
| 2838 |
intersight: IntersightModule instance |
| 2839 |
port_policy_moid: MOID of the port policy |
| 2840 |
fc_uplink_ports: List of FC Uplink port configurations |
| 2841 |
|
| 2842 |
Returns: |
| 2843 |
List of API responses for all configured FC Uplink ports |
| 2844 |
""" |
| 2845 |
return configure_generic_ports( |
| 2846 |
intersight, None, port_policy_moid, fc_uplink_ports, |
| 2847 |
build_fc_uplink_port_api_body, '/fabric/FcUplinkRoles', |
| 2848 |
requires_policy_cache=False |
| 2849 |
) |
| 2850 |
|
| 2851 |
|
| 2852 |
def configure_fc_storage_ports(intersight, port_policy_moid, fc_storage_ports): |
| 2853 |
""" |
| 2854 |
Configure FC Storage ports for the port policy. |
| 2855 |
|
| 2856 |
Args: |
| 2857 |
intersight: IntersightModule instance |
| 2858 |
port_policy_moid: MOID of the port policy |
| 2859 |
fc_storage_ports: List of FC Storage port configurations |
| 2860 |
|
| 2861 |
Returns: |
| 2862 |
List of API responses for all configured FC Storage ports |
| 2863 |
""" |
| 2864 |
return configure_generic_ports( |
| 2865 |
intersight, None, port_policy_moid, fc_storage_ports, |
| 2866 |
build_fc_storage_port_api_body, '/fabric/FcStorageRoles', |
| 2867 |
requires_policy_cache=False |
| 2868 |
) |
| 2869 |
|
| 2870 |
|
| 2871 |
def configure_appliance_ports(intersight, policy_cache, port_policy_moid, appliance_ports): |
| 2872 |
""" |
| 2873 |
Configure Appliance ports for the port policy. |
| 2874 |
|
| 2875 |
Args: |
| 2876 |
intersight: IntersightModule instance |
| 2877 |
policy_cache: Dictionary for caching policy MOIDs |
| 2878 |
port_policy_moid: MOID of the port policy |
| 2879 |
appliance_ports: List of Appliance port configurations |
| 2880 |
|
| 2881 |
Returns: |
| 2882 |
List of API responses for all configured Appliance ports |
| 2883 |
""" |
| 2884 |
return configure_generic_ports( |
| 2885 |
intersight, policy_cache, port_policy_moid, appliance_ports, |
| 2886 |
build_appliance_port_api_body, '/fabric/ApplianceRoles', |
| 2887 |
requires_policy_cache=True |
| 2888 |
) |
| 2889 |
|
| 2890 |
|
| 2891 |
def configure_ethernet_uplink_ports(intersight, policy_cache, port_policy_moid, ethernet_uplink_ports): |
| 2892 |
""" |
| 2893 |
Configure Ethernet Uplink ports for the port policy. |
| 2894 |
|
| 2895 |
Args: |
| 2896 |
intersight: IntersightModule instance |
| 2897 |
policy_cache: Dictionary for caching policy MOIDs |
| 2898 |
port_policy_moid: MOID of the port policy |
| 2899 |
ethernet_uplink_ports: List of Ethernet Uplink port configurations |
| 2900 |
|
| 2901 |
Returns: |
| 2902 |
List of API responses for all configured Ethernet Uplink ports |
| 2903 |
""" |
| 2904 |
return configure_generic_ports( |
| 2905 |
intersight, policy_cache, port_policy_moid, ethernet_uplink_ports, |
| 2906 |
build_ethernet_uplink_port_api_body, '/fabric/UplinkRoles', |
| 2907 |
requires_policy_cache=True |
| 2908 |
) |
| 2909 |
|
| 2910 |
|
| 2911 |
def configure_fcoe_uplink_ports(intersight, policy_cache, port_policy_moid, fcoe_uplink_ports): |
| 2912 |
""" |
| 2913 |
Configure FCoE Uplink ports for the port policy. |
| 2914 |
|
| 2915 |
Args: |
| 2916 |
intersight: IntersightModule instance |
| 2917 |
policy_cache: Dictionary for caching policy MOIDs |
| 2918 |
port_policy_moid: MOID of the port policy |
| 2919 |
fcoe_uplink_ports: List of FCoE Uplink port configurations |
| 2920 |
|
| 2921 |
Returns: |
| 2922 |
List of API responses for all configured FCoE Uplink ports |
| 2923 |
""" |
| 2924 |
return configure_generic_ports( |
| 2925 |
intersight, policy_cache, port_policy_moid, fcoe_uplink_ports, |
| 2926 |
build_fcoe_uplink_port_api_body, '/fabric/FcoeUplinkRoles', |
| 2927 |
requires_policy_cache=True |
| 2928 |
) |
| 2929 |
|
| 2930 |
|
| 2931 |
def main(): |
| 2932 |
# Define FC port mode options |
| 2933 |
fc_port_mode_options = dict( |
| 2934 |
port_id_start=dict(type='int', default=1), |
| 2935 |
port_id_end=dict(type='int', required=True), |
| 2936 |
state=dict(type='str', choices=['present', 'absent'], default='present') |
| 2937 |
) |
| 2938 |
|
| 2939 |
# Define breakout port options |
| 2940 |
breakout_port_options = dict( |
| 2941 |
port_id=dict(type='int', required=True), |
| 2942 |
custom_mode=dict( |
| 2943 |
type='str', |
| 2944 |
choices=[ |
| 2945 |
'BreakoutEthernet10G', |
| 2946 |
'BreakoutEthernet25G', |
| 2947 |
'BreakoutFibreChannel8G', |
| 2948 |
'BreakoutFibreChannel16G', |
| 2949 |
'BreakoutFibreChannel32G' |
| 2950 |
], |
| 2951 |
required=True |
| 2952 |
), |
| 2953 |
state=dict(type='str', choices=['present', 'absent'], default='present') |
| 2954 |
) |
| 2955 |
|
| 2956 |
# Define server port options |
| 2957 |
server_port_options = dict( |
| 2958 |
port_id=dict(type='str', required=True), |
| 2959 |
fec=dict(type='str', choices=['Auto', 'Cl74'], default='Auto'), |
| 2960 |
manual_numbering=dict(type='bool', default=False), |
| 2961 |
user_label=dict(type='str'), |
| 2962 |
preferred_device_type=dict(type='str', choices=['Chassis', 'RackServer']), |
| 2963 |
preferred_device_id=dict(type='int'), |
| 2964 |
state=dict(type='str', choices=['present', 'absent'], default='present') |
| 2965 |
) |
| 2966 |
|
| 2967 |
# Define port options for port channels |
| 2968 |
ethernet_port_options = dict( |
| 2969 |
port_id=dict(type='str', required=True) |
| 2970 |
) |
| 2971 |
|
| 2972 |
fc_port_options = dict( |
| 2973 |
port_id=dict(type='str', required=True) |
| 2974 |
) |
| 2975 |
|
| 2976 |
# Define Ethernet uplink port channel options |
| 2977 |
ethernet_uplink_pc_options = dict( |
| 2978 |
pc_id=dict(type='int', required=True), |
| 2979 |
admin_speed=dict(type='str', choices=['Auto', '1Gbps', '10Gbps', '25Gbps', '40Gbps', '100Gbps'], default='Auto'), |
| 2980 |
fec=dict(type='str', choices=['Auto', 'Off'], default='Auto'), |
| 2981 |
user_label=dict(type='str'), |
| 2982 |
ports=dict(type='list', elements='dict', options=ethernet_port_options, required=True), |
| 2983 |
eth_network_group_policy_names=dict(type='list', elements='str'), |
| 2984 |
flow_control_policy_name=dict(type='str'), |
| 2985 |
link_aggregation_policy_name=dict(type='str'), |
| 2986 |
link_control_policy_name=dict(type='str'), |
| 2987 |
state=dict(type='str', choices=['present', 'absent'], default='present') |
| 2988 |
) |
| 2989 |
|
| 2990 |
# Define FC uplink port channel options |
| 2991 |
fc_uplink_pc_options = dict( |
| 2992 |
pc_id=dict(type='int', required=True), |
| 2993 |
admin_speed=dict(type='str', choices=['8Gbps', '16Gbps', '32Gbps'], default='16Gbps'), |
| 2994 |
vsan_id=dict(type='int', default=1), |
| 2995 |
user_label=dict(type='str'), |
| 2996 |
ports=dict(type='list', elements='dict', options=fc_port_options, required=True), |
| 2997 |
state=dict(type='str', choices=['present', 'absent'], default='present') |
| 2998 |
) |
| 2999 |
|
| 3000 |
# Define FCoE uplink port channel options |
| 3001 |
fcoe_uplink_pc_options = dict( |
| 3002 |
pc_id=dict(type='int', required=True), |
| 3003 |
admin_speed=dict(type='str', choices=['Auto', '1Gbps', '10Gbps', '25Gbps', '40Gbps', '100Gbps'], default='Auto'), |
| 3004 |
fec=dict(type='str', choices=['Auto', 'Off'], default='Auto'), |
| 3005 |
user_label=dict(type='str'), |
| 3006 |
ports=dict(type='list', elements='dict', options=ethernet_port_options, required=True), |
| 3007 |
link_aggregation_policy_name=dict(type='str'), |
| 3008 |
link_control_policy_name=dict(type='str'), |
| 3009 |
state=dict(type='str', choices=['present', 'absent'], default='present') |
| 3010 |
) |
| 3011 |
|
| 3012 |
# Define Appliance port channel options |
| 3013 |
appliance_pc_options = dict( |
| 3014 |
pc_id=dict(type='int', required=True), |
| 3015 |
admin_speed=dict(type='str', choices=['Auto', '1Gbps', '10Gbps', '25Gbps', '40Gbps', '100Gbps'], default='Auto'), |
| 3016 |
fec=dict(type='str', choices=['Auto', 'Off'], default='Auto'), |
| 3017 |
priority=dict(type='str', choices=['Best Effort', 'FC', 'Platinum', 'Gold', 'Silver', 'Bronze'], default='Best Effort'), |
| 3018 |
mode=dict(type='str', choices=['trunk', 'access'], default='trunk'), |
| 3019 |
user_label=dict(type='str'), |
| 3020 |
ports=dict(type='list', elements='dict', options=ethernet_port_options, required=True), |
| 3021 |
eth_network_group_policy_name=dict(type='str', required=True), |
| 3022 |
eth_network_control_policy_name=dict(type='str', required=True), |
| 3023 |
link_aggregation_policy_name=dict(type='str'), |
| 3024 |
state=dict(type='str', choices=['present', 'absent'], default='present') |
| 3025 |
) |
| 3026 |
|
| 3027 |
# Define pin group options (both LAN and SAN) |
| 3028 |
pin_group_options = dict( |
| 3029 |
name=dict(type='str', required=True), |
| 3030 |
pin_group_type=dict(type='str', choices=['lan', 'san'], required=True), |
| 3031 |
target_interface_type=dict(type='str', choices=['pc', 'port'], required=True), |
| 3032 |
target_interface_name=dict(type='str', required=True), |
| 3033 |
state=dict(type='str', choices=['present', 'absent'], default='present') |
| 3034 |
) |
| 3035 |
|
| 3036 |
# Define FC Uplink port options |
| 3037 |
fc_uplink_port_options = dict( |
| 3038 |
port_id=dict(type='str', required=True), |
| 3039 |
admin_speed=dict(type='str', choices=['Auto', '8Gbps', '16Gbps', '32Gbps'], default='Auto'), |
| 3040 |
vsan_id=dict(type='int', required=True), |
| 3041 |
user_label=dict(type='str'), |
| 3042 |
state=dict(type='str', choices=['present', 'absent'], default='present') |
| 3043 |
) |
| 3044 |
|
| 3045 |
# Define FC Storage port options |
| 3046 |
fc_storage_port_options = dict( |
| 3047 |
port_id=dict(type='str', required=True), |
| 3048 |
admin_speed=dict(type='str', choices=['8Gbps', '16Gbps', '32Gbps'], default='8Gbps'), |
| 3049 |
vsan_id=dict(type='int', required=True), |
| 3050 |
user_label=dict(type='str'), |
| 3051 |
state=dict(type='str', choices=['present', 'absent'], default='present') |
| 3052 |
) |
| 3053 |
|
| 3054 |
# Define Appliance port options |
| 3055 |
appliance_port_options = dict( |
| 3056 |
port_id=dict(type='str', required=True), |
| 3057 |
admin_speed=dict(type='str', choices=['Auto', '1Gbps', '10Gbps', '25Gbps', '40Gbps', '100Gbps'], default='Auto'), |
| 3058 |
fec=dict(type='str', choices=['Auto', 'Off'], default='Auto'), |
| 3059 |
priority=dict(type='str', choices=['Best Effort', 'FC', 'Platinum', 'Gold', 'Silver', 'Bronze'], default='Best Effort'), |
| 3060 |
mode=dict(type='str', choices=['trunk', 'access'], default='trunk'), |
| 3061 |
eth_network_group_policy_name=dict(type='str', required=True), |
| 3062 |
eth_network_control_policy_name=dict(type='str', required=True), |
| 3063 |
user_label=dict(type='str'), |
| 3064 |
state=dict(type='str', choices=['present', 'absent'], default='present') |
| 3065 |
) |
| 3066 |
|
| 3067 |
# Define Ethernet Uplink port options |
| 3068 |
ethernet_uplink_port_options = dict( |
| 3069 |
port_id=dict(type='str', required=True), |
| 3070 |
admin_speed=dict(type='str', choices=['Auto', '1Gbps', '10Gbps', '25Gbps', '40Gbps', '100Gbps'], default='Auto'), |
| 3071 |
fec=dict(type='str', choices=['Auto', 'Off'], default='Auto'), |
| 3072 |
eth_network_group_policy_name=dict(type='list', elements='str'), |
| 3073 |
flow_control_policy_name=dict(type='str'), |
| 3074 |
link_control_policy_name=dict(type='str'), |
| 3075 |
mac_sec_policy_name=dict(type='str'), |
| 3076 |
user_label=dict(type='str'), |
| 3077 |
state=dict(type='str', choices=['present', 'absent'], default='present') |
| 3078 |
) |
| 3079 |
|
| 3080 |
# Define FCoE Uplink port options |
| 3081 |
fcoe_uplink_port_options = dict( |
| 3082 |
port_id=dict(type='str', required=True), |
| 3083 |
admin_speed=dict(type='str', choices=['Auto', '1Gbps', '10Gbps', '25Gbps', '40Gbps', '100Gbps'], default='Auto'), |
| 3084 |
fec=dict(type='str', choices=['Auto', 'Off'], default='Auto'), |
| 3085 |
link_control_policy_name=dict(type='str'), |
| 3086 |
user_label=dict(type='str'), |
| 3087 |
state=dict(type='str', choices=['present', 'absent'], default='present') |
| 3088 |
) |
| 3089 |
|
| 3090 |
argument_spec = intersight_argument_spec.copy() |
| 3091 |
argument_spec.update( |
| 3092 |
state=dict(type='str', choices=['present', 'absent'], default='present'), |
| 3093 |
organization=dict(type='str', default='default'), |
| 3094 |
name=dict(type='str', required=True), |
| 3095 |
description=dict(type='str', aliases=['descr']), |
| 3096 |
tags=dict(type='list', elements='dict'), |
| 3097 |
device_model=dict( |
| 3098 |
type='str', |
| 3099 |
choices=['UCS-FI-6454', 'UCS-FI-64108', 'UCS-FI-6536', 'UCS-FI-6664', 'UCSX-S9108-100G'] |
| 3100 |
), |
| 3101 |
fc_port_mode=dict(type='dict', options=fc_port_mode_options), |
| 3102 |
breakout_ports=dict(type='list', elements='dict', options=breakout_port_options), |
| 3103 |
server_ports=dict(type='list', elements='dict', options=server_port_options), |
| 3104 |
ethernet_uplink_port_channels=dict(type='list', elements='dict', options=ethernet_uplink_pc_options), |
| 3105 |
fc_uplink_port_channels=dict(type='list', elements='dict', options=fc_uplink_pc_options), |
| 3106 |
fcoe_uplink_port_channels=dict(type='list', elements='dict', options=fcoe_uplink_pc_options), |
| 3107 |
appliance_port_channels=dict(type='list', elements='dict', options=appliance_pc_options), |
| 3108 |
pin_groups=dict(type='list', elements='dict', options=pin_group_options), |
| 3109 |
fc_uplink_ports=dict(type='list', elements='dict', options=fc_uplink_port_options), |
| 3110 |
fc_storage_ports=dict(type='list', elements='dict', options=fc_storage_port_options), |
| 3111 |
appliance_ports=dict(type='list', elements='dict', options=appliance_port_options), |
| 3112 |
ethernet_uplink_ports=dict(type='list', elements='dict', options=ethernet_uplink_port_options), |
| 3113 |
fcoe_uplink_ports=dict(type='list', elements='dict', options=fcoe_uplink_port_options) |
| 3114 |
) |
| 3115 |
|
| 3116 |
module = AnsibleModule( |
| 3117 |
argument_spec, |
| 3118 |
supports_check_mode=True, |
| 3119 |
required_if=[ |
| 3120 |
['state', 'present', ['device_model']], |
| 3121 |
], |
| 3122 |
) |
| 3123 |
|
| 3124 |
if module.params['state'] == 'present': |
| 3125 |
validate_input(module) |
| 3126 |
|
| 3127 |
intersight = IntersightModule(module) |
| 3128 |
intersight.result['api_response'] = {} |
| 3129 |
intersight.result['trace_id'] = '' |
| 3130 |
|
| 3131 |
# Resource path used to configure policy |
| 3132 |
resource_path = '/fabric/PortPolicies' |
| 3133 |
|
| 3134 |
# Define API body used in compares or create |
| 3135 |
intersight.api_body = { |
| 3136 |
'Organization': { |
| 3137 |
'Name': intersight.module.params['organization'], |
| 3138 |
}, |
| 3139 |
'Name': intersight.module.params['name'] |
| 3140 |
} |
| 3141 |
|
| 3142 |
if intersight.module.params['state'] == 'present': |
| 3143 |
intersight.set_tags_and_description() |
| 3144 |
intersight.api_body['DeviceModel'] = intersight.module.params['device_model'] |
| 3145 |
|
| 3146 |
# Configure the port policy |
| 3147 |
intersight.configure_policy_or_profile(resource_path=resource_path) |
| 3148 |
|
| 3149 |
# Save the port policy response |
| 3150 |
port_policy_response = intersight.result['api_response'] |
| 3151 |
|
| 3152 |
port_policy_moid = None |
| 3153 |
if intersight.module.params['state'] == 'present' and port_policy_response: |
| 3154 |
port_policy_moid = port_policy_response.get('Moid') |
| 3155 |
|
| 3156 |
# Process secondary resources if port policy is present |
| 3157 |
secondary_responses = {} |
| 3158 |
if intersight.module.params['state'] == 'present' and port_policy_moid: |
| 3159 |
# Cache for policy MOIDs to avoid redundant API calls |
| 3160 |
policy_cache = {} |
| 3161 |
|
| 3162 |
# Configure FC port mode |
| 3163 |
if intersight.module.params.get('fc_port_mode'): |
| 3164 |
configure_fc_port_mode( |
| 3165 |
intersight, |
| 3166 |
port_policy_moid, |
| 3167 |
intersight.module.params['fc_port_mode'] |
| 3168 |
) |
| 3169 |
secondary_responses['fc_port_mode'] = intersight.result.get('api_response') |
| 3170 |
|
| 3171 |
# Configure breakout ports |
| 3172 |
if intersight.module.params.get('breakout_ports'): |
| 3173 |
breakout_responses = configure_breakout_ports( |
| 3174 |
intersight, |
| 3175 |
port_policy_moid, |
| 3176 |
intersight.module.params['breakout_ports'] |
| 3177 |
) |
| 3178 |
if breakout_responses: |
| 3179 |
secondary_responses['breakout_ports'] = breakout_responses |
| 3180 |
|
| 3181 |
# Configure server ports |
| 3182 |
if intersight.module.params.get('server_ports'): |
| 3183 |
server_responses = configure_server_ports( |
| 3184 |
intersight, |
| 3185 |
port_policy_moid, |
| 3186 |
intersight.module.params['server_ports'] |
| 3187 |
) |
| 3188 |
if server_responses: |
| 3189 |
secondary_responses['server_ports'] = server_responses |
| 3190 |
|
| 3191 |
# Configure FC Uplink ports |
| 3192 |
if intersight.module.params.get('fc_uplink_ports'): |
| 3193 |
fc_uplink_responses = configure_fc_uplink_ports( |
| 3194 |
intersight, |
| 3195 |
port_policy_moid, |
| 3196 |
intersight.module.params['fc_uplink_ports'] |
| 3197 |
) |
| 3198 |
if fc_uplink_responses: |
| 3199 |
secondary_responses['fc_uplink_ports'] = fc_uplink_responses |
| 3200 |
|
| 3201 |
# Configure FC Storage ports |
| 3202 |
if intersight.module.params.get('fc_storage_ports'): |
| 3203 |
fc_storage_responses = configure_fc_storage_ports( |
| 3204 |
intersight, |
| 3205 |
port_policy_moid, |
| 3206 |
intersight.module.params['fc_storage_ports'] |
| 3207 |
) |
| 3208 |
if fc_storage_responses: |
| 3209 |
secondary_responses['fc_storage_ports'] = fc_storage_responses |
| 3210 |
|
| 3211 |
# Configure Appliance ports |
| 3212 |
if intersight.module.params.get('appliance_ports'): |
| 3213 |
appliance_responses = configure_appliance_ports( |
| 3214 |
intersight, |
| 3215 |
policy_cache, |
| 3216 |
port_policy_moid, |
| 3217 |
intersight.module.params['appliance_ports'] |
| 3218 |
) |
| 3219 |
if appliance_responses: |
| 3220 |
secondary_responses['appliance_ports'] = appliance_responses |
| 3221 |
|
| 3222 |
# Configure Ethernet Uplink ports |
| 3223 |
if intersight.module.params.get('ethernet_uplink_ports'): |
| 3224 |
ethernet_uplink_responses = configure_ethernet_uplink_ports( |
| 3225 |
intersight, |
| 3226 |
policy_cache, |
| 3227 |
port_policy_moid, |
| 3228 |
intersight.module.params['ethernet_uplink_ports'] |
| 3229 |
) |
| 3230 |
if ethernet_uplink_responses: |
| 3231 |
secondary_responses['ethernet_uplink_ports'] = ethernet_uplink_responses |
| 3232 |
|
| 3233 |
# Configure FCoE Uplink ports |
| 3234 |
if intersight.module.params.get('fcoe_uplink_ports'): |
| 3235 |
fcoe_uplink_responses = configure_fcoe_uplink_ports( |
| 3236 |
intersight, |
| 3237 |
policy_cache, |
| 3238 |
port_policy_moid, |
| 3239 |
intersight.module.params['fcoe_uplink_ports'] |
| 3240 |
) |
| 3241 |
if fcoe_uplink_responses: |
| 3242 |
secondary_responses['fcoe_uplink_ports'] = fcoe_uplink_responses |
| 3243 |
|
| 3244 |
# Configure Ethernet uplink port channels and get their MOIDs |
| 3245 |
uplink_pc_moids = {} |
| 3246 |
if intersight.module.params.get('ethernet_uplink_port_channels'): |
| 3247 |
ethernet_pc_moids = configure_ethernet_uplink_port_channels( |
| 3248 |
intersight, |
| 3249 |
policy_cache, |
| 3250 |
port_policy_moid, |
| 3251 |
intersight.module.params['ethernet_uplink_port_channels'] |
| 3252 |
) |
| 3253 |
uplink_pc_moids.update(ethernet_pc_moids) |
| 3254 |
secondary_responses['ethernet_uplink_port_channels'] = intersight.result.get('api_response') |
| 3255 |
|
| 3256 |
# Configure FC uplink port channels |
| 3257 |
if intersight.module.params.get('fc_uplink_port_channels'): |
| 3258 |
fc_pc_moids = configure_fc_uplink_port_channels( |
| 3259 |
intersight, |
| 3260 |
port_policy_moid, |
| 3261 |
intersight.module.params['fc_uplink_port_channels'] |
| 3262 |
) |
| 3263 |
uplink_pc_moids.update(fc_pc_moids) |
| 3264 |
secondary_responses['fc_uplink_port_channels'] = intersight.result.get('api_response') |
| 3265 |
|
| 3266 |
# Configure FCoE uplink port channels |
| 3267 |
if intersight.module.params.get('fcoe_uplink_port_channels'): |
| 3268 |
fcoe_pc_moids = configure_fcoe_uplink_port_channels( |
| 3269 |
intersight, |
| 3270 |
policy_cache, |
| 3271 |
port_policy_moid, |
| 3272 |
intersight.module.params['fcoe_uplink_port_channels'] |
| 3273 |
) |
| 3274 |
uplink_pc_moids.update(fcoe_pc_moids) |
| 3275 |
secondary_responses['fcoe_uplink_port_channels'] = intersight.result.get('api_response') |
| 3276 |
|
| 3277 |
# Configure Appliance port channels |
| 3278 |
if intersight.module.params.get('appliance_port_channels'): |
| 3279 |
appliance_pc_moids = configure_appliance_port_channels( |
| 3280 |
intersight, |
| 3281 |
policy_cache, |
| 3282 |
port_policy_moid, |
| 3283 |
intersight.module.params['appliance_port_channels'] |
| 3284 |
) |
| 3285 |
uplink_pc_moids.update(appliance_pc_moids) |
| 3286 |
secondary_responses['appliance_port_channels'] = intersight.result.get('api_response') |
| 3287 |
|
| 3288 |
# Configure pin groups (both LAN and SAN, must be after all port channels) |
| 3289 |
if intersight.module.params.get('pin_groups'): |
| 3290 |
configure_pin_groups( |
| 3291 |
intersight, |
| 3292 |
port_policy_moid, |
| 3293 |
intersight.module.params['pin_groups'], |
| 3294 |
uplink_pc_moids |
| 3295 |
) |
| 3296 |
secondary_responses['pin_groups'] = intersight.result.get('api_response') |
| 3297 |
|
| 3298 |
# Combine port policy and secondary resources in the main response |
| 3299 |
if port_policy_response: |
| 3300 |
port_policy_response.update(secondary_responses) |
| 3301 |
intersight.result['api_response'] = port_policy_response |
| 3302 |
|
| 3303 |
module.exit_json(**intersight.result) |
| 3304 |
|
| 3305 |
|
| 3306 |
if __name__ == '__main__': |
| 3307 |
main() |