| 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_gpu_policy |
| 16 |
short_description: GPU policy configuration for Cisco Intersight |
| 17 |
description: |
| 18 |
- GPU policy configuration for Cisco Intersight. |
| 19 |
- Used to configure Multi-Instance GPU (MIG) partitioning and GPU assignment on server profiles. |
| 20 |
- Supports NVIDIA H100, B200, and other MIG-capable GPUs managed through Intersight. |
| 21 |
- For more information see L(Cisco Intersight,https://intersight.com/apidocs). |
| 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 GPU policy. |
| 40 |
- The name must be between 1 and 62 alphanumeric characters, allowing special characters :-_. |
| 41 |
type: str |
| 42 |
required: true |
| 43 |
tags: |
| 44 |
description: |
| 45 |
- List of tags in Key:<user-defined key> Value:<user-defined value> format. |
| 46 |
type: list |
| 47 |
elements: dict |
| 48 |
description: |
| 49 |
description: |
| 50 |
- The user-defined description of the GPU policy. |
| 51 |
type: str |
| 52 |
aliases: [descr] |
| 53 |
gpu_mode: |
| 54 |
description: |
| 55 |
- The operating mode for GPUs in the server. |
| 56 |
- C(graphics) configures GPUs for standard graphics/display use. |
| 57 |
- C(compute) configures GPUs for compute workloads (CUDA, inference, training). |
| 58 |
type: str |
| 59 |
choices: [graphics, compute] |
| 60 |
default: compute |
| 61 |
mig_enabled: |
| 62 |
description: |
| 63 |
- Enable or disable Multi-Instance GPU (MIG) partitioning. |
| 64 |
- When enabled, each physical GPU can be partitioned into multiple isolated GPU instances. |
| 65 |
- MIG is supported on NVIDIA A100, H100, B200 and newer architectures. |
| 66 |
type: bool |
| 67 |
default: false |
| 68 |
mig_profiles: |
| 69 |
description: |
| 70 |
- List of MIG partition profiles to apply when mig_enabled is true. |
| 71 |
- Each entry defines the partition configuration for a GPU slot. |
| 72 |
- If fewer profiles are specified than available GPUs, remaining GPUs use the default profile. |
| 73 |
type: list |
| 74 |
elements: dict |
| 75 |
suboptions: |
| 76 |
slot_id: |
| 77 |
description: |
| 78 |
- The GPU slot number (1-8) this profile applies to. |
| 79 |
type: int |
| 80 |
required: true |
| 81 |
partition_profile: |
| 82 |
description: |
| 83 |
- The MIG partition profile name. |
| 84 |
- Common profiles for H100/B200 include 1g.10gb, 2g.20gb, 3g.40gb, 4g.40gb, 7g.80gb. |
| 85 |
- Use C(none) to disable MIG on this specific slot. |
| 86 |
type: str |
| 87 |
required: true |
| 88 |
instance_count: |
| 89 |
description: |
| 90 |
- Number of MIG instances to create with the specified partition profile. |
| 91 |
- Maximum depends on the GPU model and partition profile selected. |
| 92 |
type: int |
| 93 |
default: 1 |
| 94 |
gpu_thermal_threshold: |
| 95 |
description: |
| 96 |
- GPU thermal throttle threshold temperature in Celsius. |
| 97 |
- When GPU temperature exceeds this threshold, performance will be throttled to prevent damage. |
| 98 |
- Valid range depends on GPU model. Typical values are 80-95 for data center GPUs. |
| 99 |
- Set to 0 to use the platform default. |
| 100 |
type: int |
| 101 |
power_capping_enabled: |
| 102 |
description: |
| 103 |
- Enable or disable GPU power capping. |
| 104 |
- When enabled, GPU power consumption is limited to the power_cap_watts value. |
| 105 |
type: bool |
| 106 |
default: false |
| 107 |
power_cap_watts: |
| 108 |
description: |
| 109 |
- Maximum power consumption per GPU in watts when power_capping_enabled is true. |
| 110 |
- Valid range depends on GPU model (e.g., H100 SXM supports 300-700W). |
| 111 |
- Set to 0 to use the platform default TDP. |
| 112 |
type: int |
| 113 |
author: |
| 114 |
- Steve Fulmer (@stevefulme1) |
| 115 |
''' |
| 116 |
|
| 117 |
EXAMPLES = r''' |
| 118 |
- name: Create GPU compute policy without MIG |
| 119 |
cisco.intersight.intersight_gpu_policy: |
| 120 |
api_private_key: "{{ api_private_key }}" |
| 121 |
api_key_id: "{{ api_key_id }}" |
| 122 |
organization: AI-Factory |
| 123 |
name: gpu-compute-default |
| 124 |
description: Standard GPU compute mode for inference |
| 125 |
gpu_mode: compute |
| 126 |
|
| 127 |
- name: Create GPU policy with MIG partitioning for H100 |
| 128 |
cisco.intersight.intersight_gpu_policy: |
| 129 |
api_private_key: "{{ api_private_key }}" |
| 130 |
api_key_id: "{{ api_key_id }}" |
| 131 |
name: gpu-mig-inference |
| 132 |
description: MIG partitioned for multi-tenant inference |
| 133 |
gpu_mode: compute |
| 134 |
mig_enabled: true |
| 135 |
mig_profiles: |
| 136 |
- slot_id: 1 |
| 137 |
partition_profile: 3g.40gb |
| 138 |
instance_count: 2 |
| 139 |
- slot_id: 2 |
| 140 |
partition_profile: 7g.80gb |
| 141 |
instance_count: 1 |
| 142 |
|
| 143 |
- name: Create GPU policy with thermal and power limits |
| 144 |
cisco.intersight.intersight_gpu_policy: |
| 145 |
api_private_key: "{{ api_private_key }}" |
| 146 |
api_key_id: "{{ api_key_id }}" |
| 147 |
name: gpu-power-managed |
| 148 |
description: Power-managed GPU policy for dense deployments |
| 149 |
gpu_mode: compute |
| 150 |
gpu_thermal_threshold: 85 |
| 151 |
power_capping_enabled: true |
| 152 |
power_cap_watts: 400 |
| 153 |
|
| 154 |
- name: Delete GPU policy |
| 155 |
cisco.intersight.intersight_gpu_policy: |
| 156 |
api_private_key: "{{ api_private_key }}" |
| 157 |
api_key_id: "{{ api_key_id }}" |
| 158 |
name: gpu-compute-default |
| 159 |
state: absent |
| 160 |
''' |
| 161 |
|
| 162 |
RETURN = r''' |
| 163 |
api_response: |
| 164 |
description: The API response output returned by the specified resource. |
| 165 |
returned: always |
| 166 |
type: dict |
| 167 |
sample: |
| 168 |
"api_response": { |
| 169 |
"Name": "gpu-compute-default", |
| 170 |
"ObjectType": "graphics.GpuPolicy", |
| 171 |
"GpuMode": "compute", |
| 172 |
"MigEnabled": false |
| 173 |
} |
| 174 |
''' |
| 175 |
|
| 176 |
|
| 177 |
from ansible.module_utils.basic import AnsibleModule |
| 178 |
from ansible_collections.cisco.intersight.plugins.module_utils.intersight import IntersightModule, intersight_argument_spec |
| 179 |
|
| 180 |
|
| 181 |
def main(): |
| 182 |
mig_profile = dict( |
| 183 |
slot_id=dict(type='int', required=True), |
| 184 |
partition_profile=dict(type='str', required=True), |
| 185 |
instance_count=dict(type='int', default=1), |
| 186 |
) |
| 187 |
argument_spec = intersight_argument_spec.copy() |
| 188 |
argument_spec.update( |
| 189 |
state=dict(type='str', choices=['present', 'absent'], default='present'), |
| 190 |
organization=dict(type='str', default='default'), |
| 191 |
name=dict(type='str', required=True), |
| 192 |
description=dict(type='str', aliases=['descr']), |
| 193 |
tags=dict(type='list', elements='dict'), |
| 194 |
gpu_mode=dict(type='str', choices=['graphics', 'compute'], default='compute'), |
| 195 |
mig_enabled=dict(type='bool', default=False), |
| 196 |
mig_profiles=dict(type='list', elements='dict', options=mig_profile), |
| 197 |
gpu_thermal_threshold=dict(type='int'), |
| 198 |
power_capping_enabled=dict(type='bool', default=False), |
| 199 |
power_cap_watts=dict(type='int'), |
| 200 |
) |
| 201 |
|
| 202 |
module = AnsibleModule( |
| 203 |
argument_spec, |
| 204 |
supports_check_mode=True, |
| 205 |
) |
| 206 |
|
| 207 |
intersight = IntersightModule(module) |
| 208 |
intersight.result['api_response'] = {} |
| 209 |
intersight.result['trace_id'] = '' |
| 210 |
|
| 211 |
resource_path = '/graphics/GpuPolicies' |
| 212 |
|
| 213 |
intersight.api_body = { |
| 214 |
'Name': intersight.module.params['name'], |
| 215 |
'Organization': { |
| 216 |
'Name': intersight.module.params['organization'], |
| 217 |
}, |
| 218 |
} |
| 219 |
|
| 220 |
if module.params['state'] == 'present': |
| 221 |
intersight.set_tags_and_description() |
| 222 |
|
| 223 |
intersight.api_body['GpuMode'] = module.params['gpu_mode'] |
| 224 |
intersight.api_body['MigEnabled'] = module.params['mig_enabled'] |
| 225 |
|
| 226 |
# MIG partition profiles |
| 227 |
if module.params['mig_enabled'] and module.params.get('mig_profiles'): |
| 228 |
mig_configs = [] |
| 229 |
for profile in module.params['mig_profiles']: |
| 230 |
mig_configs.append({ |
| 231 |
'SlotId': profile['slot_id'], |
| 232 |
'PartitionProfile': profile['partition_profile'], |
| 233 |
'InstanceCount': profile['instance_count'], |
| 234 |
}) |
| 235 |
intersight.api_body['MigProfiles'] = mig_configs |
| 236 |
|
| 237 |
# Thermal threshold |
| 238 |
if module.params.get('gpu_thermal_threshold') is not None: |
| 239 |
intersight.api_body['GpuThermalThreshold'] = module.params['gpu_thermal_threshold'] |
| 240 |
|
| 241 |
# Power capping |
| 242 |
if module.params['power_capping_enabled']: |
| 243 |
intersight.api_body['PowerCappingEnabled'] = True |
| 244 |
if module.params.get('power_cap_watts') is not None: |
| 245 |
intersight.api_body['PowerCapWatts'] = module.params['power_cap_watts'] |
| 246 |
else: |
| 247 |
intersight.api_body['PowerCappingEnabled'] = False |
| 248 |
|
| 249 |
intersight.configure_policy_or_profile(resource_path=resource_path) |
| 250 |
|
| 251 |
module.exit_json(**intersight.result) |
| 252 |
|
| 253 |
|
| 254 |
if __name__ == '__main__': |
| 255 |
main() |