| 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_server_pool_qualification_policy |
| 16 |
short_description: Server Pool Qualification Policy configuration for Cisco Intersight |
| 17 |
description: |
| 18 |
- Manages Server Pool Qualification Policy configuration on Cisco Intersight. |
| 19 |
- A Server Pool Qualification Policy defines conditions to qualify servers for resource pools based on various hardware and configuration attributes. |
| 20 |
- Supports multiple qualifier types including Domain, Rack Server, Blade, Tag, Memory, GPU, Processor, and Network Adaptor qualifiers. |
| 21 |
- For more information see L(Cisco Intersight,https://intersight.com/apidocs/resourcepool/QualificationPolicies/get/). |
| 22 |
extends_documentation_fragment: intersight |
| 23 |
options: |
| 24 |
state: |
| 25 |
description: |
| 26 |
- If C(present), will verify the resource is present and will create if needed. |
| 27 |
- If C(absent), will verify the resource is absent and will delete if needed. |
| 28 |
type: str |
| 29 |
choices: [present, absent] |
| 30 |
default: present |
| 31 |
organization: |
| 32 |
description: |
| 33 |
- The name of the Organization this resource is assigned to. |
| 34 |
- Profiles and Policies that are created within a Custom Organization are applicable only to devices in the same Organization. |
| 35 |
type: str |
| 36 |
default: default |
| 37 |
name: |
| 38 |
description: |
| 39 |
- The name assigned to the Server Pool Qualification Policy. |
| 40 |
- The name must be between 1 and 62 alphanumeric characters, allowing special characters :-_. |
| 41 |
type: str |
| 42 |
required: true |
| 43 |
description: |
| 44 |
description: |
| 45 |
- The user-defined description for the Server Pool Qualification Policy. |
| 46 |
- Description can contain letters(a-z, A-Z), numbers(0-9), hyphen(-), period(.), colon(:), or an underscore(_). |
| 47 |
type: str |
| 48 |
aliases: [descr] |
| 49 |
tags: |
| 50 |
description: |
| 51 |
- List of tags in Key:<user-defined key> Value:<user-defined value> format. |
| 52 |
type: list |
| 53 |
elements: dict |
| 54 |
domain_qualifier: |
| 55 |
description: |
| 56 |
- Domain qualifier for Fabric Interconnect and domain-based qualification. |
| 57 |
type: dict |
| 58 |
suboptions: |
| 59 |
fabric_interconnect_pids: |
| 60 |
description: |
| 61 |
- List of Fabric Interconnect PIDs to qualify resources. |
| 62 |
- Qualifies resources based on the PID property of Fabric Interconnects. |
| 63 |
type: list |
| 64 |
elements: str |
| 65 |
domain_names: |
| 66 |
description: |
| 67 |
- List of domain names to qualify resources. |
| 68 |
- Qualifies resources based on the DomainName property. |
| 69 |
type: list |
| 70 |
elements: str |
| 71 |
rack_server_qualifier: |
| 72 |
description: |
| 73 |
- Rack server qualifier for qualifying rack-based servers. |
| 74 |
type: dict |
| 75 |
suboptions: |
| 76 |
rack_id_ranges: |
| 77 |
description: |
| 78 |
- List of rack ID ranges to qualify servers. |
| 79 |
- Each range specifies min_value and max_value for rack IDs. |
| 80 |
type: list |
| 81 |
elements: dict |
| 82 |
suboptions: |
| 83 |
min_value: |
| 84 |
description: |
| 85 |
- Minimum rack ID value (1-256). |
| 86 |
type: int |
| 87 |
required: true |
| 88 |
max_value: |
| 89 |
description: |
| 90 |
- Maximum rack ID value (min_value-256). |
| 91 |
type: int |
| 92 |
required: true |
| 93 |
pids: |
| 94 |
description: |
| 95 |
- List of rack server PIDs to qualify (maximum 20). |
| 96 |
- Qualifies rack servers based on their PID. |
| 97 |
type: list |
| 98 |
elements: str |
| 99 |
asset_tags: |
| 100 |
description: |
| 101 |
- List of asset tags to qualify servers. |
| 102 |
- Qualifies servers based on the AssetTag property. |
| 103 |
type: list |
| 104 |
elements: str |
| 105 |
user_labels: |
| 106 |
description: |
| 107 |
- List of user labels to qualify servers. |
| 108 |
- Qualifies servers based on the UserLabel property. |
| 109 |
type: list |
| 110 |
elements: str |
| 111 |
blade_qualifier: |
| 112 |
description: |
| 113 |
- Blade qualifier for qualifying blade-based servers. |
| 114 |
type: dict |
| 115 |
suboptions: |
| 116 |
pids: |
| 117 |
description: |
| 118 |
- List of blade server PIDs to qualify (maximum 20). |
| 119 |
- Qualifies blade servers based on their PID. |
| 120 |
type: list |
| 121 |
elements: str |
| 122 |
chassis_pids: |
| 123 |
description: |
| 124 |
- List of chassis PIDs to qualify (maximum 20). |
| 125 |
- Qualifies blade servers based on chassis PID. |
| 126 |
type: list |
| 127 |
elements: str |
| 128 |
asset_tags: |
| 129 |
description: |
| 130 |
- List of asset tags to qualify blade servers. |
| 131 |
- Qualifies servers based on the AssetTag property. |
| 132 |
type: list |
| 133 |
elements: str |
| 134 |
user_labels: |
| 135 |
description: |
| 136 |
- List of user labels to qualify blade servers. |
| 137 |
- Qualifies servers based on the UserLabel property. |
| 138 |
type: list |
| 139 |
elements: str |
| 140 |
chassis_slot_ranges: |
| 141 |
description: |
| 142 |
- List of chassis and slot ID ranges to qualify blade servers. |
| 143 |
type: list |
| 144 |
elements: dict |
| 145 |
suboptions: |
| 146 |
chassis_id_range: |
| 147 |
description: |
| 148 |
- Chassis ID range specification. |
| 149 |
type: dict |
| 150 |
required: true |
| 151 |
suboptions: |
| 152 |
min_value: |
| 153 |
description: |
| 154 |
- Minimum chassis ID value (1-40). |
| 155 |
type: int |
| 156 |
required: true |
| 157 |
max_value: |
| 158 |
description: |
| 159 |
- Maximum chassis ID value (min_value-40). |
| 160 |
type: int |
| 161 |
required: true |
| 162 |
slot_id_ranges: |
| 163 |
description: |
| 164 |
- List of slot ID ranges within the chassis. |
| 165 |
- Can only be specified if chassis_id_range is provided. |
| 166 |
type: list |
| 167 |
elements: dict |
| 168 |
suboptions: |
| 169 |
min_value: |
| 170 |
description: |
| 171 |
- Minimum slot ID value (1-8). |
| 172 |
type: int |
| 173 |
required: true |
| 174 |
max_value: |
| 175 |
description: |
| 176 |
- Maximum slot ID value (min_value-8). |
| 177 |
type: int |
| 178 |
required: true |
| 179 |
tag_qualifier: |
| 180 |
description: |
| 181 |
- Tag qualifier for qualifying resources based on tags. |
| 182 |
type: dict |
| 183 |
suboptions: |
| 184 |
server_tags: |
| 185 |
description: |
| 186 |
- List of server tags in key-value format. |
| 187 |
type: list |
| 188 |
elements: dict |
| 189 |
suboptions: |
| 190 |
key: |
| 191 |
description: |
| 192 |
- Tag key. |
| 193 |
type: str |
| 194 |
required: true |
| 195 |
value: |
| 196 |
description: |
| 197 |
- Tag value. |
| 198 |
type: str |
| 199 |
required: true |
| 200 |
domain_profile_tags: |
| 201 |
description: |
| 202 |
- List of domain profile tags in key-value format. |
| 203 |
type: list |
| 204 |
elements: dict |
| 205 |
suboptions: |
| 206 |
key: |
| 207 |
description: |
| 208 |
- Tag key. |
| 209 |
type: str |
| 210 |
required: true |
| 211 |
value: |
| 212 |
description: |
| 213 |
- Tag value. |
| 214 |
type: str |
| 215 |
required: true |
| 216 |
chassis_tags: |
| 217 |
description: |
| 218 |
- List of chassis tags in key-value format. |
| 219 |
type: list |
| 220 |
elements: dict |
| 221 |
suboptions: |
| 222 |
key: |
| 223 |
description: |
| 224 |
- Tag key. |
| 225 |
type: str |
| 226 |
required: true |
| 227 |
value: |
| 228 |
description: |
| 229 |
- Tag value. |
| 230 |
type: str |
| 231 |
required: true |
| 232 |
memory_qualifier: |
| 233 |
description: |
| 234 |
- Memory qualifier for qualifying servers based on memory specifications. |
| 235 |
type: dict |
| 236 |
suboptions: |
| 237 |
capacity_range: |
| 238 |
description: |
| 239 |
- Memory capacity range in GiB. |
| 240 |
type: dict |
| 241 |
suboptions: |
| 242 |
min_value: |
| 243 |
description: |
| 244 |
- Minimum memory capacity in GiB (1-999999). |
| 245 |
type: int |
| 246 |
required: true |
| 247 |
max_value: |
| 248 |
description: |
| 249 |
- Maximum memory capacity in GiB (min_value-999999). |
| 250 |
type: int |
| 251 |
required: true |
| 252 |
units_range: |
| 253 |
description: |
| 254 |
- Number of memory units range. |
| 255 |
type: dict |
| 256 |
suboptions: |
| 257 |
min_value: |
| 258 |
description: |
| 259 |
- Minimum number of memory units (1-99999). |
| 260 |
type: int |
| 261 |
required: true |
| 262 |
max_value: |
| 263 |
description: |
| 264 |
- Maximum number of memory units (min_value-99999). |
| 265 |
type: int |
| 266 |
required: true |
| 267 |
gpu_qualifier: |
| 268 |
description: |
| 269 |
- GPU qualifier for qualifying servers based on GPU specifications. |
| 270 |
- If not specified, a default GPU qualifier with C(servers_without_gpu) evaluation type is automatically added. |
| 271 |
type: dict |
| 272 |
suboptions: |
| 273 |
evaluation_type: |
| 274 |
description: |
| 275 |
- GPU evaluation type for server qualification. |
| 276 |
- C(servers_without_gpu) - Qualifies servers without GPUs (default). |
| 277 |
- C(all_servers) - Qualifies all servers regardless of GPU presence. |
| 278 |
- C(servers_with_gpu) - Qualifies only servers with GPUs. |
| 279 |
type: str |
| 280 |
choices: [servers_without_gpu, all_servers, servers_with_gpu] |
| 281 |
default: servers_without_gpu |
| 282 |
gpu_count_range: |
| 283 |
description: |
| 284 |
- GPU count range (only applicable when evaluation_type is servers_with_gpu). |
| 285 |
type: dict |
| 286 |
suboptions: |
| 287 |
min_value: |
| 288 |
description: |
| 289 |
- Minimum number of GPUs (1-16). |
| 290 |
type: int |
| 291 |
required: true |
| 292 |
max_value: |
| 293 |
description: |
| 294 |
- Maximum number of GPUs (min_value-16). |
| 295 |
type: int |
| 296 |
required: true |
| 297 |
pids: |
| 298 |
description: |
| 299 |
- List of GPU PIDs to qualify (maximum 20, only for servers_with_gpu). |
| 300 |
type: list |
| 301 |
elements: str |
| 302 |
vendor: |
| 303 |
description: |
| 304 |
- GPU vendor (only applicable when evaluation_type is servers_with_gpu). |
| 305 |
type: str |
| 306 |
choices: [nvidia, intel, amd] |
| 307 |
processor_qualifier: |
| 308 |
description: |
| 309 |
- Processor qualifier for qualifying servers based on CPU specifications. |
| 310 |
type: dict |
| 311 |
suboptions: |
| 312 |
cores_range: |
| 313 |
description: |
| 314 |
- CPU cores range. |
| 315 |
type: dict |
| 316 |
suboptions: |
| 317 |
min_value: |
| 318 |
description: |
| 319 |
- Minimum number of CPU cores (1-9999). |
| 320 |
type: int |
| 321 |
required: true |
| 322 |
max_value: |
| 323 |
description: |
| 324 |
- Maximum number of CPU cores (min_value-9999). |
| 325 |
type: int |
| 326 |
required: true |
| 327 |
speed_range: |
| 328 |
description: |
| 329 |
- CPU speed range in GHz. |
| 330 |
type: dict |
| 331 |
suboptions: |
| 332 |
min_value: |
| 333 |
description: |
| 334 |
- Minimum CPU speed in GHz (1-99). |
| 335 |
type: int |
| 336 |
required: true |
| 337 |
max_value: |
| 338 |
description: |
| 339 |
- Maximum CPU speed in GHz (min_value-99). |
| 340 |
type: int |
| 341 |
required: true |
| 342 |
pids: |
| 343 |
description: |
| 344 |
- List of processor PIDs to qualify (maximum 100). |
| 345 |
type: list |
| 346 |
elements: str |
| 347 |
vendor: |
| 348 |
description: |
| 349 |
- Processor vendor. |
| 350 |
type: str |
| 351 |
choices: [intel, amd] |
| 352 |
network_adaptor_qualifier: |
| 353 |
description: |
| 354 |
- Network adaptor qualifier for qualifying servers based on network adaptor count. |
| 355 |
type: dict |
| 356 |
suboptions: |
| 357 |
adaptors_range: |
| 358 |
description: |
| 359 |
- Number of network adaptors range. |
| 360 |
type: dict |
| 361 |
suboptions: |
| 362 |
min_value: |
| 363 |
description: |
| 364 |
- Minimum number of network adaptors (1-16). |
| 365 |
type: int |
| 366 |
required: true |
| 367 |
max_value: |
| 368 |
description: |
| 369 |
- Maximum number of network adaptors (min_value-16). |
| 370 |
type: int |
| 371 |
required: true |
| 372 |
author: |
| 373 |
- Ron Gershburg (@rgershbu) |
| 374 |
''' |
| 375 |
|
| 376 |
EXAMPLES = r''' |
| 377 |
- name: Create minimal Server Pool Qualification Policy |
| 378 |
cisco.intersight.intersight_server_pool_qualification_policy: |
| 379 |
api_private_key: "{{ api_private_key }}" |
| 380 |
api_key_id: "{{ api_key_id }}" |
| 381 |
organization: "default" |
| 382 |
name: "ServerPool-Minimal-Policy" |
| 383 |
description: "Minimal policy - GPU qualifier automatically added with servers_without_gpu" |
| 384 |
state: present |
| 385 |
|
| 386 |
- name: Create Server Pool Qualification Policy with domain and rack qualifiers |
| 387 |
cisco.intersight.intersight_server_pool_qualification_policy: |
| 388 |
api_private_key: "{{ api_private_key }}" |
| 389 |
api_key_id: "{{ api_key_id }}" |
| 390 |
organization: "default" |
| 391 |
name: "ServerPool-Qual-Policy-01" |
| 392 |
description: "Server pool qualification with domain and rack filters" |
| 393 |
domain_qualifier: |
| 394 |
fabric_interconnect_pids: |
| 395 |
- ucs-fi-6454 |
| 396 |
- ucs-fi-64108 |
| 397 |
domain_names: |
| 398 |
- "AC08-6454" |
| 399 |
rack_server_qualifier: |
| 400 |
rack_id_ranges: |
| 401 |
- min_value: 2 |
| 402 |
max_value: 4 |
| 403 |
- min_value: 5 |
| 404 |
max_value: 8 |
| 405 |
pids: |
| 406 |
- "UCSC-C245-M8SX" |
| 407 |
- "UCSC-C220-M8S" |
| 408 |
asset_tags: |
| 409 |
- "production" |
| 410 |
user_labels: |
| 411 |
- "datacenter-a" |
| 412 |
state: present |
| 413 |
|
| 414 |
- name: Create Server Pool Qualification Policy with blade and memory qualifiers |
| 415 |
cisco.intersight.intersight_server_pool_qualification_policy: |
| 416 |
api_private_key: "{{ api_private_key }}" |
| 417 |
api_key_id: "{{ api_key_id }}" |
| 418 |
name: "ServerPool-Blade-Policy" |
| 419 |
blade_qualifier: |
| 420 |
pids: |
| 421 |
- "UCSB-B480-M5" |
| 422 |
- "UCSB-B200-M5" |
| 423 |
chassis_pids: |
| 424 |
- "N20-C6508" |
| 425 |
chassis_slot_ranges: |
| 426 |
- chassis_id_range: |
| 427 |
min_value: 2 |
| 428 |
max_value: 10 |
| 429 |
slot_id_ranges: |
| 430 |
- min_value: 4 |
| 431 |
max_value: 6 |
| 432 |
memory_qualifier: |
| 433 |
capacity_range: |
| 434 |
min_value: 64 |
| 435 |
max_value: 512 |
| 436 |
units_range: |
| 437 |
min_value: 10 |
| 438 |
max_value: 20 |
| 439 |
state: present |
| 440 |
|
| 441 |
- name: Create Server Pool Qualification Policy with GPU requirements |
| 442 |
cisco.intersight.intersight_server_pool_qualification_policy: |
| 443 |
api_private_key: "{{ api_private_key }}" |
| 444 |
api_key_id: "{{ api_key_id }}" |
| 445 |
name: "ServerPool-GPU-Policy" |
| 446 |
description: "Policy for servers with NVIDIA GPUs" |
| 447 |
gpu_qualifier: |
| 448 |
evaluation_type: servers_with_gpu |
| 449 |
gpu_count_range: |
| 450 |
min_value: 2 |
| 451 |
max_value: 4 |
| 452 |
vendor: nvidia |
| 453 |
processor_qualifier: |
| 454 |
cores_range: |
| 455 |
min_value: 16 |
| 456 |
max_value: 64 |
| 457 |
vendor: intel |
| 458 |
state: present |
| 459 |
|
| 460 |
- name: Create Server Pool Qualification Policy with tag qualifiers |
| 461 |
cisco.intersight.intersight_server_pool_qualification_policy: |
| 462 |
api_private_key: "{{ api_private_key }}" |
| 463 |
api_key_id: "{{ api_key_id }}" |
| 464 |
name: "ServerPool-Tag-Policy" |
| 465 |
tag_qualifier: |
| 466 |
server_tags: |
| 467 |
- key: "environment" |
| 468 |
value: "production" |
| 469 |
- key: "tier" |
| 470 |
value: "1" |
| 471 |
chassis_tags: |
| 472 |
- key: "location" |
| 473 |
value: "datacenter-a" |
| 474 |
network_adaptor_qualifier: |
| 475 |
adaptors_range: |
| 476 |
min_value: 2 |
| 477 |
max_value: 8 |
| 478 |
state: present |
| 479 |
|
| 480 |
- name: Create comprehensive Server Pool Qualification Policy |
| 481 |
cisco.intersight.intersight_server_pool_qualification_policy: |
| 482 |
api_private_key: "{{ api_private_key }}" |
| 483 |
api_key_id: "{{ api_key_id }}" |
| 484 |
organization: "Production" |
| 485 |
name: "ServerPool-Comprehensive-Policy" |
| 486 |
description: "Comprehensive qualification policy with multiple qualifiers" |
| 487 |
domain_qualifier: |
| 488 |
fabric_interconnect_pids: |
| 489 |
- ucs-fi-6454 |
| 490 |
rack_server_qualifier: |
| 491 |
pids: |
| 492 |
- "UCSC-C220-M6S" |
| 493 |
- "UCSC-C240-M6S" |
| 494 |
blade_qualifier: |
| 495 |
pids: |
| 496 |
- "UCSX-210C-M7" |
| 497 |
- "UCSX-410C-M7" |
| 498 |
memory_qualifier: |
| 499 |
capacity_range: |
| 500 |
min_value: 128 |
| 501 |
max_value: 1024 |
| 502 |
processor_qualifier: |
| 503 |
cores_range: |
| 504 |
min_value: 32 |
| 505 |
max_value: 128 |
| 506 |
vendor: intel |
| 507 |
gpu_qualifier: |
| 508 |
evaluation_type: servers_without_gpu |
| 509 |
network_adaptor_qualifier: |
| 510 |
adaptors_range: |
| 511 |
min_value: 2 |
| 512 |
max_value: 4 |
| 513 |
tags: |
| 514 |
- Key: "Environment" |
| 515 |
Value: "Production" |
| 516 |
state: present |
| 517 |
|
| 518 |
- name: Delete Server Pool Qualification Policy |
| 519 |
cisco.intersight.intersight_server_pool_qualification_policy: |
| 520 |
api_private_key: "{{ api_private_key }}" |
| 521 |
api_key_id: "{{ api_key_id }}" |
| 522 |
name: "ServerPool-Qual-Policy-01" |
| 523 |
state: absent |
| 524 |
''' |
| 525 |
|
| 526 |
RETURN = r''' |
| 527 |
api_response: |
| 528 |
description: The API response output returned by the specified resource. |
| 529 |
returned: always |
| 530 |
type: dict |
| 531 |
sample: |
| 532 |
"api_response": { |
| 533 |
"Name": "ServerPool-Qual-Policy-01", |
| 534 |
"ObjectType": "resourcepool.QualificationPolicy", |
| 535 |
"Organization": { |
| 536 |
"Moid": "675450ee69726530014753e2", |
| 537 |
"ObjectType": "organization.Organization" |
| 538 |
}, |
| 539 |
"Qualifiers": [ |
| 540 |
{ |
| 541 |
"FabricInterConnectPids": ["UCS-FI-6454", "UCS-FI-64108"], |
| 542 |
"DomainNames": ["AC08-6454"], |
| 543 |
"ObjectType": "resource.DomainQualifier" |
| 544 |
}, |
| 545 |
{ |
| 546 |
"RackIdRange": [{"MinValue": 2, "MaxValue": 4}], |
| 547 |
"Pids": ["UCSC-C245-M8SX"], |
| 548 |
"ObjectType": "resource.RackServerQualifier" |
| 549 |
} |
| 550 |
] |
| 551 |
} |
| 552 |
''' |
| 553 |
|
| 554 |
from ansible.module_utils.basic import AnsibleModule |
| 555 |
from ansible_collections.cisco.intersight.plugins.module_utils.intersight import IntersightModule, intersight_argument_spec |
| 556 |
|
| 557 |
|
| 558 |
def build_domain_qualifier(domain_qualifier): |
| 559 |
"""Build domain qualifier API body.""" |
| 560 |
qualifier = {'ObjectType': 'resource.DomainQualifier'} |
| 561 |
|
| 562 |
if domain_qualifier.get('fabric_interconnect_pids'): |
| 563 |
# Convert lowercase choices to API format (uppercase with hyphens) |
| 564 |
qualifier['FabricInterConnectPids'] = [ |
| 565 |
pid.upper() for pid in domain_qualifier['fabric_interconnect_pids'] |
| 566 |
] |
| 567 |
|
| 568 |
if domain_qualifier.get('domain_names'): |
| 569 |
qualifier['DomainNames'] = domain_qualifier['domain_names'] |
| 570 |
|
| 571 |
return qualifier |
| 572 |
|
| 573 |
|
| 574 |
def build_rack_server_qualifier(rack_server_qualifier): |
| 575 |
"""Build rack server qualifier API body.""" |
| 576 |
qualifier = {'ObjectType': 'resource.RackServerQualifier'} |
| 577 |
|
| 578 |
if rack_server_qualifier.get('rack_id_ranges'): |
| 579 |
qualifier['RackIdRange'] = [ |
| 580 |
{'MinValue': range_item['min_value'], 'MaxValue': range_item['max_value']} |
| 581 |
for range_item in rack_server_qualifier['rack_id_ranges'] |
| 582 |
] |
| 583 |
|
| 584 |
if rack_server_qualifier.get('pids'): |
| 585 |
qualifier['Pids'] = rack_server_qualifier['pids'] |
| 586 |
|
| 587 |
if rack_server_qualifier.get('asset_tags'): |
| 588 |
qualifier['AssetTags'] = rack_server_qualifier['asset_tags'] |
| 589 |
|
| 590 |
if rack_server_qualifier.get('user_labels'): |
| 591 |
qualifier['UserLabels'] = rack_server_qualifier['user_labels'] |
| 592 |
|
| 593 |
return qualifier |
| 594 |
|
| 595 |
|
| 596 |
def build_blade_qualifier(blade_qualifier): |
| 597 |
"""Build blade qualifier API body.""" |
| 598 |
qualifier = {'ObjectType': 'resource.BladeQualifier'} |
| 599 |
|
| 600 |
if blade_qualifier.get('pids'): |
| 601 |
qualifier['Pids'] = blade_qualifier['pids'] |
| 602 |
|
| 603 |
if blade_qualifier.get('chassis_pids'): |
| 604 |
qualifier['ChassisPids'] = blade_qualifier['chassis_pids'] |
| 605 |
|
| 606 |
if blade_qualifier.get('asset_tags'): |
| 607 |
qualifier['AssetTags'] = blade_qualifier['asset_tags'] |
| 608 |
|
| 609 |
if blade_qualifier.get('user_labels'): |
| 610 |
qualifier['UserLabels'] = blade_qualifier['user_labels'] |
| 611 |
|
| 612 |
if blade_qualifier.get('chassis_slot_ranges'): |
| 613 |
chassis_slot_list = [] |
| 614 |
for range_item in blade_qualifier['chassis_slot_ranges']: |
| 615 |
chassis_slot = { |
| 616 |
'ChassisIdRange': { |
| 617 |
'MinValue': range_item['chassis_id_range']['min_value'], |
| 618 |
'MaxValue': range_item['chassis_id_range']['max_value'] |
| 619 |
} |
| 620 |
} |
| 621 |
if range_item.get('slot_id_ranges'): |
| 622 |
chassis_slot['SlotIdRanges'] = [ |
| 623 |
{'MinValue': slot['min_value'], 'MaxValue': slot['max_value']} |
| 624 |
for slot in range_item['slot_id_ranges'] |
| 625 |
] |
| 626 |
chassis_slot_list.append(chassis_slot) |
| 627 |
qualifier['ChassisAndSlotIdRange'] = chassis_slot_list |
| 628 |
|
| 629 |
return qualifier |
| 630 |
|
| 631 |
|
| 632 |
def build_tag_qualifier(tag_qualifier): |
| 633 |
"""Build tag qualifier API body.""" |
| 634 |
qualifier = {'ObjectType': 'resource.TagQualifier'} |
| 635 |
|
| 636 |
if tag_qualifier.get('server_tags'): |
| 637 |
qualifier['ServerTags'] = [ |
| 638 |
{'Key': tag['key'], 'Value': tag['value']} |
| 639 |
for tag in tag_qualifier['server_tags'] |
| 640 |
] |
| 641 |
|
| 642 |
if tag_qualifier.get('domain_profile_tags'): |
| 643 |
qualifier['DomainProfileTags'] = [ |
| 644 |
{'Key': tag['key'], 'Value': tag['value']} |
| 645 |
for tag in tag_qualifier['domain_profile_tags'] |
| 646 |
] |
| 647 |
|
| 648 |
if tag_qualifier.get('chassis_tags'): |
| 649 |
qualifier['ChassisTags'] = [ |
| 650 |
{'Key': tag['key'], 'Value': tag['value']} |
| 651 |
for tag in tag_qualifier['chassis_tags'] |
| 652 |
] |
| 653 |
|
| 654 |
return qualifier |
| 655 |
|
| 656 |
|
| 657 |
def build_memory_qualifier(memory_qualifier): |
| 658 |
"""Build memory qualifier API body.""" |
| 659 |
qualifier = {'ObjectType': 'resource.MemoryQualifier'} |
| 660 |
|
| 661 |
if memory_qualifier.get('capacity_range'): |
| 662 |
qualifier['MemoryCapacityRange'] = { |
| 663 |
'MinValue': memory_qualifier['capacity_range']['min_value'], |
| 664 |
'MaxValue': memory_qualifier['capacity_range']['max_value'] |
| 665 |
} |
| 666 |
|
| 667 |
if memory_qualifier.get('units_range'): |
| 668 |
qualifier['MemoryUnitsRange'] = { |
| 669 |
'MinValue': memory_qualifier['units_range']['min_value'], |
| 670 |
'MaxValue': memory_qualifier['units_range']['max_value'] |
| 671 |
} |
| 672 |
|
| 673 |
return qualifier |
| 674 |
|
| 675 |
|
| 676 |
def build_gpu_qualifier(gpu_qualifier): |
| 677 |
"""Build GPU qualifier API body.""" |
| 678 |
qualifier = {'ObjectType': 'resource.GpuQualifier'} |
| 679 |
|
| 680 |
# Convert evaluation type to API format |
| 681 |
eval_type_map = { |
| 682 |
'servers_without_gpu': 'ServerWithoutGpu', |
| 683 |
'all_servers': 'Unspecified', |
| 684 |
'servers_with_gpu': 'ServerWithGpu' |
| 685 |
} |
| 686 |
eval_type = gpu_qualifier.get('evaluation_type', 'servers_without_gpu') |
| 687 |
qualifier['GpuEvaluationType'] = eval_type_map[eval_type] |
| 688 |
|
| 689 |
# GPU-specific fields only apply for ServerWithGpu |
| 690 |
if eval_type == 'servers_with_gpu': |
| 691 |
if gpu_qualifier.get('gpu_count_range'): |
| 692 |
qualifier['GpuCountRange'] = { |
| 693 |
'MinValue': gpu_qualifier['gpu_count_range']['min_value'], |
| 694 |
'MaxValue': gpu_qualifier['gpu_count_range']['max_value'] |
| 695 |
} |
| 696 |
|
| 697 |
if gpu_qualifier.get('pids'): |
| 698 |
qualifier['Pids'] = gpu_qualifier['pids'] |
| 699 |
|
| 700 |
if gpu_qualifier.get('vendor'): |
| 701 |
# Convert vendor to API format |
| 702 |
vendor_map = { |
| 703 |
'nvidia': 'NVIDIA', |
| 704 |
'intel': 'Intel', |
| 705 |
'amd': 'AMD' |
| 706 |
} |
| 707 |
qualifier['Vendor'] = vendor_map[gpu_qualifier['vendor']] |
| 708 |
|
| 709 |
return qualifier |
| 710 |
|
| 711 |
|
| 712 |
def build_processor_qualifier(processor_qualifier): |
| 713 |
"""Build processor qualifier API body.""" |
| 714 |
qualifier = {'ObjectType': 'resource.ProcessorQualifier'} |
| 715 |
|
| 716 |
if processor_qualifier.get('cores_range'): |
| 717 |
qualifier['CpuCoresRange'] = { |
| 718 |
'MinValue': processor_qualifier['cores_range']['min_value'], |
| 719 |
'MaxValue': processor_qualifier['cores_range']['max_value'] |
| 720 |
} |
| 721 |
|
| 722 |
if processor_qualifier.get('speed_range'): |
| 723 |
qualifier['SpeedRange'] = { |
| 724 |
'MinValue': processor_qualifier['speed_range']['min_value'], |
| 725 |
'MaxValue': processor_qualifier['speed_range']['max_value'] |
| 726 |
} |
| 727 |
|
| 728 |
if processor_qualifier.get('pids'): |
| 729 |
qualifier['Pids'] = processor_qualifier['pids'] |
| 730 |
|
| 731 |
if processor_qualifier.get('vendor'): |
| 732 |
# Convert vendor to API format |
| 733 |
vendor_map = { |
| 734 |
'intel': 'Intel(R) Corporation', |
| 735 |
'amd': 'AMD' |
| 736 |
} |
| 737 |
qualifier['Vendor'] = vendor_map[processor_qualifier['vendor']] |
| 738 |
|
| 739 |
return qualifier |
| 740 |
|
| 741 |
|
| 742 |
def build_network_adaptor_qualifier(network_adaptor_qualifier): |
| 743 |
"""Build network adaptor qualifier API body.""" |
| 744 |
qualifier = {'ObjectType': 'resource.NetworkAdaptorQualifier'} |
| 745 |
|
| 746 |
if network_adaptor_qualifier.get('adaptors_range'): |
| 747 |
qualifier['AdaptorsRange'] = { |
| 748 |
'MinValue': network_adaptor_qualifier['adaptors_range']['min_value'], |
| 749 |
'MaxValue': network_adaptor_qualifier['adaptors_range']['max_value'] |
| 750 |
} |
| 751 |
|
| 752 |
return qualifier |
| 753 |
|
| 754 |
|
| 755 |
def validate_range_values(module, range_dict, range_name, min_limit, max_limit): |
| 756 |
"""Validate that range min/max values are within limits and min <= max.""" |
| 757 |
if not range_dict: |
| 758 |
return |
| 759 |
|
| 760 |
min_val = range_dict.get('min_value') |
| 761 |
max_val = range_dict.get('max_value') |
| 762 |
|
| 763 |
if min_val is not None and (min_val < min_limit or min_val > max_limit): |
| 764 |
module.fail_json(msg=f"{range_name} min_value must be between {min_limit} and {max_limit}") |
| 765 |
|
| 766 |
if max_val is not None and (max_val < min_limit or max_val > max_limit): |
| 767 |
module.fail_json(msg=f"{range_name} max_value must be between {min_limit} and {max_limit}") |
| 768 |
|
| 769 |
if min_val is not None and max_val is not None and min_val > max_val: |
| 770 |
module.fail_json(msg=f"{range_name} min_value cannot be greater than max_value") |
| 771 |
|
| 772 |
|
| 773 |
def validate_list_length(module, list_param, max_length, param_name): |
| 774 |
"""Validate that a list parameter does not exceed maximum length.""" |
| 775 |
if list_param and len(list_param) > max_length: |
| 776 |
module.fail_json(msg=f"{param_name} cannot contain more than {max_length} items") |
| 777 |
|
| 778 |
|
| 779 |
def main(): |
| 780 |
argument_spec = intersight_argument_spec.copy() |
| 781 |
argument_spec.update( |
| 782 |
state=dict(type='str', choices=['present', 'absent'], default='present'), |
| 783 |
organization=dict(type='str', default='default'), |
| 784 |
name=dict(type='str', required=True), |
| 785 |
description=dict(type='str', aliases=['descr']), |
| 786 |
tags=dict(type='list', elements='dict'), |
| 787 |
domain_qualifier=dict( |
| 788 |
type='dict', |
| 789 |
options=dict( |
| 790 |
fabric_interconnect_pids=dict( |
| 791 |
type='list', |
| 792 |
elements='str' |
| 793 |
), |
| 794 |
domain_names=dict(type='list', elements='str') |
| 795 |
) |
| 796 |
), |
| 797 |
rack_server_qualifier=dict( |
| 798 |
type='dict', |
| 799 |
options=dict( |
| 800 |
rack_id_ranges=dict( |
| 801 |
type='list', |
| 802 |
elements='dict', |
| 803 |
options=dict( |
| 804 |
min_value=dict(type='int', required=True), |
| 805 |
max_value=dict(type='int', required=True) |
| 806 |
) |
| 807 |
), |
| 808 |
pids=dict(type='list', elements='str'), |
| 809 |
asset_tags=dict(type='list', elements='str'), |
| 810 |
user_labels=dict(type='list', elements='str') |
| 811 |
) |
| 812 |
), |
| 813 |
blade_qualifier=dict( |
| 814 |
type='dict', |
| 815 |
options=dict( |
| 816 |
pids=dict(type='list', elements='str'), |
| 817 |
chassis_pids=dict(type='list', elements='str'), |
| 818 |
asset_tags=dict(type='list', elements='str'), |
| 819 |
user_labels=dict(type='list', elements='str'), |
| 820 |
chassis_slot_ranges=dict( |
| 821 |
type='list', |
| 822 |
elements='dict', |
| 823 |
options=dict( |
| 824 |
chassis_id_range=dict( |
| 825 |
type='dict', |
| 826 |
required=True, |
| 827 |
options=dict( |
| 828 |
min_value=dict(type='int', required=True), |
| 829 |
max_value=dict(type='int', required=True) |
| 830 |
) |
| 831 |
), |
| 832 |
slot_id_ranges=dict( |
| 833 |
type='list', |
| 834 |
elements='dict', |
| 835 |
options=dict( |
| 836 |
min_value=dict(type='int', required=True), |
| 837 |
max_value=dict(type='int', required=True) |
| 838 |
) |
| 839 |
) |
| 840 |
) |
| 841 |
) |
| 842 |
) |
| 843 |
), |
| 844 |
tag_qualifier=dict( |
| 845 |
type='dict', |
| 846 |
options=dict( |
| 847 |
server_tags=dict( |
| 848 |
type='list', |
| 849 |
elements='dict', |
| 850 |
options=dict( |
| 851 |
key=dict(type='str', required=True, no_log=False), |
| 852 |
value=dict(type='str', required=True) |
| 853 |
) |
| 854 |
), |
| 855 |
domain_profile_tags=dict( |
| 856 |
type='list', |
| 857 |
elements='dict', |
| 858 |
options=dict( |
| 859 |
key=dict(type='str', required=True, no_log=False), |
| 860 |
value=dict(type='str', required=True) |
| 861 |
) |
| 862 |
), |
| 863 |
chassis_tags=dict( |
| 864 |
type='list', |
| 865 |
elements='dict', |
| 866 |
options=dict( |
| 867 |
key=dict(type='str', required=True, no_log=False), |
| 868 |
value=dict(type='str', required=True) |
| 869 |
) |
| 870 |
) |
| 871 |
) |
| 872 |
), |
| 873 |
memory_qualifier=dict( |
| 874 |
type='dict', |
| 875 |
options=dict( |
| 876 |
capacity_range=dict( |
| 877 |
type='dict', |
| 878 |
options=dict( |
| 879 |
min_value=dict(type='int', required=True), |
| 880 |
max_value=dict(type='int', required=True) |
| 881 |
) |
| 882 |
), |
| 883 |
units_range=dict( |
| 884 |
type='dict', |
| 885 |
options=dict( |
| 886 |
min_value=dict(type='int', required=True), |
| 887 |
max_value=dict(type='int', required=True) |
| 888 |
) |
| 889 |
) |
| 890 |
) |
| 891 |
), |
| 892 |
gpu_qualifier=dict( |
| 893 |
type='dict', |
| 894 |
options=dict( |
| 895 |
evaluation_type=dict( |
| 896 |
type='str', |
| 897 |
choices=['servers_without_gpu', 'all_servers', 'servers_with_gpu'], |
| 898 |
default='servers_without_gpu' |
| 899 |
), |
| 900 |
gpu_count_range=dict( |
| 901 |
type='dict', |
| 902 |
options=dict( |
| 903 |
min_value=dict(type='int', required=True), |
| 904 |
max_value=dict(type='int', required=True) |
| 905 |
) |
| 906 |
), |
| 907 |
pids=dict(type='list', elements='str'), |
| 908 |
vendor=dict(type='str', choices=['nvidia', 'intel', 'amd']) |
| 909 |
) |
| 910 |
), |
| 911 |
processor_qualifier=dict( |
| 912 |
type='dict', |
| 913 |
options=dict( |
| 914 |
cores_range=dict( |
| 915 |
type='dict', |
| 916 |
options=dict( |
| 917 |
min_value=dict(type='int', required=True), |
| 918 |
max_value=dict(type='int', required=True) |
| 919 |
) |
| 920 |
), |
| 921 |
speed_range=dict( |
| 922 |
type='dict', |
| 923 |
options=dict( |
| 924 |
min_value=dict(type='int', required=True), |
| 925 |
max_value=dict(type='int', required=True) |
| 926 |
) |
| 927 |
), |
| 928 |
pids=dict(type='list', elements='str'), |
| 929 |
vendor=dict(type='str', choices=['intel', 'amd']) |
| 930 |
) |
| 931 |
), |
| 932 |
network_adaptor_qualifier=dict( |
| 933 |
type='dict', |
| 934 |
options=dict( |
| 935 |
adaptors_range=dict( |
| 936 |
type='dict', |
| 937 |
options=dict( |
| 938 |
min_value=dict(type='int', required=True), |
| 939 |
max_value=dict(type='int', required=True) |
| 940 |
) |
| 941 |
) |
| 942 |
) |
| 943 |
) |
| 944 |
) |
| 945 |
|
| 946 |
module = AnsibleModule( |
| 947 |
argument_spec, |
| 948 |
supports_check_mode=True |
| 949 |
) |
| 950 |
|
| 951 |
intersight = IntersightModule(module) |
| 952 |
intersight.result['api_response'] = {} |
| 953 |
intersight.result['trace_id'] = '' |
| 954 |
|
| 955 |
# Resource path used to configure policy |
| 956 |
resource_path = '/resourcepool/QualificationPolicies' |
| 957 |
|
| 958 |
# Define API body used in compares or create |
| 959 |
intersight.api_body = { |
| 960 |
'Organization': { |
| 961 |
'Name': intersight.module.params['organization'], |
| 962 |
}, |
| 963 |
'Name': intersight.module.params['name'], |
| 964 |
} |
| 965 |
|
| 966 |
if intersight.module.params['state'] == 'present': |
| 967 |
intersight.set_tags_and_description() |
| 968 |
|
| 969 |
# Build qualifiers list |
| 970 |
qualifiers = [] |
| 971 |
|
| 972 |
# Domain qualifier |
| 973 |
if module.params.get('domain_qualifier'): |
| 974 |
qualifiers.append(build_domain_qualifier(module.params['domain_qualifier'])) |
| 975 |
|
| 976 |
# Rack server qualifier |
| 977 |
if module.params.get('rack_server_qualifier'): |
| 978 |
rack_qual = module.params['rack_server_qualifier'] |
| 979 |
|
| 980 |
# Validate rack ID ranges |
| 981 |
if rack_qual.get('rack_id_ranges'): |
| 982 |
for rack_range in rack_qual['rack_id_ranges']: |
| 983 |
validate_range_values(module, rack_range, 'Rack ID range', 1, 256) |
| 984 |
|
| 985 |
# Validate PID list length |
| 986 |
validate_list_length(module, rack_qual.get('pids'), 20, 'Rack server PIDs') |
| 987 |
|
| 988 |
qualifiers.append(build_rack_server_qualifier(rack_qual)) |
| 989 |
|
| 990 |
# Blade qualifier |
| 991 |
if module.params.get('blade_qualifier'): |
| 992 |
blade_qual = module.params['blade_qualifier'] |
| 993 |
|
| 994 |
# Validate PID list lengths |
| 995 |
validate_list_length(module, blade_qual.get('pids'), 20, 'Blade server PIDs') |
| 996 |
validate_list_length(module, blade_qual.get('chassis_pids'), 20, 'Chassis PIDs') |
| 997 |
|
| 998 |
# Validate chassis and slot ranges |
| 999 |
if blade_qual.get('chassis_slot_ranges'): |
| 1000 |
for range_item in blade_qual['chassis_slot_ranges']: |
| 1001 |
validate_range_values(module, range_item['chassis_id_range'], |
| 1002 |
'Chassis ID range', 1, 40) |
| 1003 |
if range_item.get('slot_id_ranges'): |
| 1004 |
for slot_range in range_item['slot_id_ranges']: |
| 1005 |
validate_range_values(module, slot_range, 'Slot ID range', 1, 8) |
| 1006 |
|
| 1007 |
qualifiers.append(build_blade_qualifier(blade_qual)) |
| 1008 |
|
| 1009 |
# Tag qualifier |
| 1010 |
if module.params.get('tag_qualifier'): |
| 1011 |
qualifiers.append(build_tag_qualifier(module.params['tag_qualifier'])) |
| 1012 |
|
| 1013 |
# Memory qualifier |
| 1014 |
if module.params.get('memory_qualifier'): |
| 1015 |
mem_qual = module.params['memory_qualifier'] |
| 1016 |
|
| 1017 |
# Validate memory ranges |
| 1018 |
validate_range_values(module, mem_qual.get('capacity_range'), |
| 1019 |
'Memory capacity range', 1, 999999) |
| 1020 |
validate_range_values(module, mem_qual.get('units_range'), |
| 1021 |
'Memory units range', 1, 99999) |
| 1022 |
|
| 1023 |
qualifiers.append(build_memory_qualifier(mem_qual)) |
| 1024 |
|
| 1025 |
# GPU qualifier |
| 1026 |
if module.params.get('gpu_qualifier'): |
| 1027 |
gpu_qual = module.params['gpu_qualifier'] |
| 1028 |
|
| 1029 |
# Validate GPU count range |
| 1030 |
validate_range_values(module, gpu_qual.get('gpu_count_range'), |
| 1031 |
'GPU count range', 1, 16) |
| 1032 |
|
| 1033 |
# Validate GPU PIDs list length |
| 1034 |
validate_list_length(module, gpu_qual.get('pids'), 20, 'GPU PIDs') |
| 1035 |
|
| 1036 |
# Validate GPU-specific fields only for servers_with_gpu |
| 1037 |
if gpu_qual.get('evaluation_type') != 'servers_with_gpu': |
| 1038 |
if gpu_qual.get('gpu_count_range') or gpu_qual.get('pids') or gpu_qual.get('vendor'): |
| 1039 |
module.warn('GPU count, PIDs, and vendor are only applicable when evaluation_type is servers_with_gpu') |
| 1040 |
|
| 1041 |
qualifiers.append(build_gpu_qualifier(gpu_qual)) |
| 1042 |
else: |
| 1043 |
# Add default GPU qualifier if not specified |
| 1044 |
default_gpu_qual = {'evaluation_type': 'servers_without_gpu'} |
| 1045 |
qualifiers.append(build_gpu_qualifier(default_gpu_qual)) |
| 1046 |
|
| 1047 |
# Processor qualifier |
| 1048 |
if module.params.get('processor_qualifier'): |
| 1049 |
proc_qual = module.params['processor_qualifier'] |
| 1050 |
|
| 1051 |
# Validate processor ranges |
| 1052 |
validate_range_values(module, proc_qual.get('cores_range'), |
| 1053 |
'CPU cores range', 1, 9999) |
| 1054 |
validate_range_values(module, proc_qual.get('speed_range'), |
| 1055 |
'CPU speed range', 1, 99) |
| 1056 |
|
| 1057 |
# Validate processor PIDs list length |
| 1058 |
validate_list_length(module, proc_qual.get('pids'), 100, 'Processor PIDs') |
| 1059 |
|
| 1060 |
qualifiers.append(build_processor_qualifier(proc_qual)) |
| 1061 |
|
| 1062 |
# Network adaptor qualifier |
| 1063 |
if module.params.get('network_adaptor_qualifier'): |
| 1064 |
net_qual = module.params['network_adaptor_qualifier'] |
| 1065 |
|
| 1066 |
# Validate adaptors range |
| 1067 |
validate_range_values(module, net_qual.get('adaptors_range'), |
| 1068 |
'Network adaptors range', 1, 16) |
| 1069 |
|
| 1070 |
qualifiers.append(build_network_adaptor_qualifier(net_qual)) |
| 1071 |
|
| 1072 |
# Add qualifiers to API body (always present, at minimum GPU qualifier) |
| 1073 |
intersight.api_body['Qualifiers'] = qualifiers |
| 1074 |
|
| 1075 |
# Configure the policy |
| 1076 |
intersight.configure_policy_or_profile(resource_path=resource_path) |
| 1077 |
|
| 1078 |
module.exit_json(**intersight.result) |
| 1079 |
|
| 1080 |
|
| 1081 |
if __name__ == '__main__': |
| 1082 |
main() |