Debian Codegraph @

ansible_collections/cisco/intersight/plugins/modules/intersight_ai_storage_policy.py

raw
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
5
6 from __future__ import absolute_import, division, print_function
7 __metaclass__ = type
8
9 ANSIBLE_METADATA = {'metadata_version': '1.1',
10 'status': ['preview'],
11 'supported_by': 'community'}
12
13 DOCUMENTATION = r'''
14 ---
15 module: intersight_ai_storage_policy
16 short_description: AI-optimized storage policy for Cisco Intersight
17 description:
18 - Creates storage policies optimized for AI workloads including inference model storage,
19 training data, and telemetry caches.
20 - Provides named storage presets that configure NVMe tiering, drive groups, and
21 virtual drive layouts for common AI deployment patterns.
22 - Builds on the Intersight storage policy API with AI-specific defaults for
23 high-throughput, low-latency access to model weights and datasets.
24 - For full storage configuration control, use M(cisco.intersight.intersight_storage_policy) instead.
25 - For more information see L(Cisco Intersight,https://intersight.com/apidocs).
26 extends_documentation_fragment: intersight
27 options:
28 state:
29 description:
30 - If C(present), will verify the resource is present and will create if needed.
31 - If C(absent), will verify the resource is absent and will delete if needed.
32 type: str
33 choices: [present, absent]
34 default: present
35 organization:
36 description:
37 - The name of the Organization this resource is assigned to.
38 type: str
39 default: default
40 name:
41 description:
42 - The name assigned to the storage policy.
43 - The name must be between 1 and 62 alphanumeric characters, allowing special characters :-_.
44 type: str
45 required: true
46 tags:
47 description:
48 - List of tags in Key:<user-defined key> Value:<user-defined value> format.
49 type: list
50 elements: dict
51 description:
52 description:
53 - The user-defined description of the storage policy.
54 type: str
55 aliases: [descr]
56 storage_profile:
57 description:
58 - The AI storage preset profile to apply.
59 - C(inference_optimized) configures NVMe drives in direct-attach mode for lowest latency
60 access to model weights. Sets all available NVMe slots to direct-attach, disables
61 JBOD for VD creation, and uses RAID0 with read-ahead caching for maximum throughput.
62 - C(training_data) configures storage for large dataset access during training.
63 Uses RAID5/RAID6 for data protection with write-back caching and larger strip sizes
64 for sequential read throughput.
65 - C(model_cache) configures a fast NVMe cache tier for model artifacts with M.2 boot.
66 Enables M.2 virtual drive for OS boot and sets remaining NVMe drives to direct-attach
67 for model weight caching.
68 - C(edge_compact) configures storage for Unified Edge nodes with limited drive bays.
69 Uses M.2 boot with minimal RAID0 configuration suitable for edge inference with
70 constrained storage capacity.
71 type: str
72 choices: [inference_optimized, training_data, model_cache, edge_compact]
73 required: true
74 nvme_slots:
75 description:
76 - NVMe drive slots to configure in the selected mode.
77 - Overrides the default slot configuration from the storage profile.
78 - Allowed slots are 1-9, 21-24, 101-104.
79 - 'Slot format examples: "1,4,5", "2", "1-5", "1,2,6-8"'
80 type: str
81 nvme_mode:
82 description:
83 - Override the NVMe attachment mode.
84 - C(direct) attaches NVMe drives directly to the CPU for lowest latency.
85 - C(controller) routes NVMe through the RAID controller for management features.
86 type: str
87 choices: [direct, controller]
88 m2_boot_enabled:
89 description:
90 - Override whether to enable M.2 RAID boot drive.
91 - When true, configures M.2 MSTOR-RAID-1 as the boot virtual drive.
92 type: bool
93 raid_level:
94 description:
95 - Override the RAID level for data drive groups.
96 - Only applicable for training_data profile.
97 type: str
98 choices: [Raid0, Raid1, Raid5, Raid6, Raid10]
99 read_policy:
100 description:
101 - Override the read cache policy for virtual drives.
102 type: str
103 choices: [Default, ReadAhead, NoReadAhead]
104 write_policy:
105 description:
106 - Override the write cache policy for virtual drives.
107 type: str
108 choices: [Default, WriteThrough, WriteBackGoodBbu, AlwaysWriteBack]
109 author:
110 - Steve Fulmer (@stevefulme1)
111 '''
112
113 EXAMPLES = r'''
114 - name: Create inference-optimized storage policy
115 cisco.intersight.intersight_ai_storage_policy:
116 api_private_key: "{{ api_private_key }}"
117 api_key_id: "{{ api_key_id }}"
118 organization: AI-Factory
119 name: storage-ai-inference
120 description: NVMe direct-attach for model weight storage
121 storage_profile: inference_optimized
122
123 - name: Create training data storage policy with RAID6
124 cisco.intersight.intersight_ai_storage_policy:
125 api_private_key: "{{ api_private_key }}"
126 api_key_id: "{{ api_key_id }}"
127 name: storage-ai-training
128 description: Protected storage for training datasets
129 storage_profile: training_data
130 raid_level: Raid6
131 write_policy: AlwaysWriteBack
132
133 - name: Create model cache storage for inference servers
134 cisco.intersight.intersight_ai_storage_policy:
135 api_private_key: "{{ api_private_key }}"
136 api_key_id: "{{ api_key_id }}"
137 name: storage-model-cache
138 description: M.2 boot with NVMe model cache
139 storage_profile: model_cache
140 nvme_slots: "1-4"
141
142 - name: Create edge storage policy
143 cisco.intersight.intersight_ai_storage_policy:
144 api_private_key: "{{ api_private_key }}"
145 api_key_id: "{{ api_key_id }}"
146 name: storage-edge-inference
147 storage_profile: edge_compact
148
149 - name: Delete AI storage policy
150 cisco.intersight.intersight_ai_storage_policy:
151 api_private_key: "{{ api_private_key }}"
152 api_key_id: "{{ api_key_id }}"
153 name: storage-ai-inference
154 storage_profile: inference_optimized
155 state: absent
156 '''
157
158 RETURN = r'''
159 api_response:
160 description: The API response output returned by the specified resource.
161 returned: always
162 type: dict
163 sample:
164 "api_response": {
165 "Name": "storage-ai-inference",
166 "ObjectType": "storage.StoragePolicy",
167 "DirectAttachedNvmeSlots": "1-4"
168 }
169 applied_settings:
170 description: The storage settings applied by the profile and any overrides.
171 returned: when state is present
172 type: dict
173 '''
174
175
176 from ansible.module_utils.basic import AnsibleModule
177 from ansible_collections.cisco.intersight.plugins.module_utils.intersight import IntersightModule, intersight_argument_spec
178
179
180 # Default NVMe slot ranges
181 DEFAULT_NVME_SLOTS = '1-4'
182
183 # Storage profile presets
184 STORAGE_PROFILES = {
185 'inference_optimized': {
186 # All NVMe direct-attach for lowest latency model access
187 'DirectAttachedNvmeSlots': DEFAULT_NVME_SLOTS,
188 'UseJbodForVdCreation': False,
189 'UnusedDisksState': 'NoChange',
190 'DefaultDriveMode': 'UnconfiguredGood',
191 'M2VirtualDrive': {
192 'Enable': False,
193 'ControllerSlot': 'MSTOR-RAID-1',
194 'Name': 'MStorBootVd',
195 },
196 'Raid0Drive': {
197 'Enable': True,
198 'VirtualDrivePolicy': {
199 'StripSize': 256,
200 'AccessPolicy': 'ReadWrite',
201 'ReadPolicy': 'ReadAhead',
202 'WritePolicy': 'WriteThrough',
203 'DriveCache': 'Enable',
204 },
205 },
206 },
207 'training_data': {
208 # RAID-protected storage for training datasets
209 'UseJbodForVdCreation': False,
210 'UnusedDisksState': 'UnconfiguredGood',
211 'DefaultDriveMode': 'UnconfiguredGood',
212 'M2VirtualDrive': {
213 'Enable': True,
214 'ControllerSlot': 'MSTOR-RAID-1',
215 'Name': 'MStorBootVd',
216 },
217 'Raid0Drive': {
218 'Enable': False,
219 'VirtualDrivePolicy': {
220 'StripSize': 512,
221 'AccessPolicy': 'ReadWrite',
222 'ReadPolicy': 'ReadAhead',
223 'WritePolicy': 'WriteBackGoodBbu',
224 'DriveCache': 'Enable',
225 },
226 },
227 '_raid_level': 'Raid5',
228 '_read_policy': 'ReadAhead',
229 '_write_policy': 'WriteBackGoodBbu',
230 },
231 'model_cache': {
232 # M.2 boot + NVMe direct-attach model cache
233 'DirectAttachedNvmeSlots': DEFAULT_NVME_SLOTS,
234 'UseJbodForVdCreation': False,
235 'UnusedDisksState': 'NoChange',
236 'DefaultDriveMode': 'UnconfiguredGood',
237 'M2VirtualDrive': {
238 'Enable': True,
239 'ControllerSlot': 'MSTOR-RAID-1',
240 'Name': 'MStorBootVd',
241 },
242 'Raid0Drive': {
243 'Enable': False,
244 'VirtualDrivePolicy': {
245 'StripSize': 64,
246 'AccessPolicy': 'Default',
247 'ReadPolicy': 'Default',
248 'WritePolicy': 'Default',
249 'DriveCache': 'Default',
250 },
251 },
252 },
253 'edge_compact': {
254 # Minimal storage for edge nodes
255 'UseJbodForVdCreation': False,
256 'UnusedDisksState': 'NoChange',
257 'DefaultDriveMode': 'UnconfiguredGood',
258 'M2VirtualDrive': {
259 'Enable': True,
260 'ControllerSlot': 'MSTOR-RAID-1',
261 'Name': 'MStorBootVd',
262 },
263 'Raid0Drive': {
264 'Enable': True,
265 'VirtualDrivePolicy': {
266 'StripSize': 64,
267 'AccessPolicy': 'ReadWrite',
268 'ReadPolicy': 'ReadAhead',
269 'WritePolicy': 'WriteThrough',
270 'DriveCache': 'Default',
271 },
272 },
273 },
274 }
275
276
277 def main():
278 argument_spec = intersight_argument_spec.copy()
279 argument_spec.update(
280 state=dict(type='str', choices=['present', 'absent'], default='present'),
281 organization=dict(type='str', default='default'),
282 name=dict(type='str', required=True),
283 description=dict(type='str', aliases=['descr']),
284 tags=dict(type='list', elements='dict'),
285 storage_profile=dict(
286 type='str',
287 choices=['inference_optimized', 'training_data', 'model_cache', 'edge_compact'],
288 required=True,
289 ),
290 nvme_slots=dict(type='str'),
291 nvme_mode=dict(type='str', choices=['direct', 'controller']),
292 m2_boot_enabled=dict(type='bool'),
293 raid_level=dict(type='str', choices=['Raid0', 'Raid1', 'Raid5', 'Raid6', 'Raid10']),
294 read_policy=dict(type='str', choices=['Default', 'ReadAhead', 'NoReadAhead']),
295 write_policy=dict(type='str', choices=['Default', 'WriteThrough', 'WriteBackGoodBbu', 'AlwaysWriteBack']),
296 )
297
298 module = AnsibleModule(
299 argument_spec,
300 supports_check_mode=True,
301 )
302
303 intersight = IntersightModule(module)
304 intersight.result['api_response'] = {}
305 intersight.result['trace_id'] = ''
306
307 resource_path = '/storage/StoragePolicies'
308
309 intersight.api_body = {
310 'Name': intersight.module.params['name'],
311 'Organization': {
312 'Name': intersight.module.params['organization'],
313 },
314 }
315
316 if module.params['state'] == 'present':
317 intersight.set_tags_and_description()
318
319 # Deep copy profile settings
320 profile_name = module.params['storage_profile']
321 import copy
322 settings = copy.deepcopy(STORAGE_PROFILES[profile_name])
323
324 # Remove internal metadata keys
325 settings.pop('_raid_level', None)
326 settings.pop('_read_policy', None)
327 settings.pop('_write_policy', None)
328
329 # Apply NVMe slot overrides
330 if module.params.get('nvme_slots') is not None:
331 nvme_mode = module.params.get('nvme_mode', 'direct')
332 if nvme_mode == 'direct':
333 settings['DirectAttachedNvmeSlots'] = module.params['nvme_slots']
334 settings.pop('ControllerAttachedNvmeSlots', None)
335 else:
336 settings['ControllerAttachedNvmeSlots'] = module.params['nvme_slots']
337 settings.pop('DirectAttachedNvmeSlots', None)
338 elif module.params.get('nvme_mode') is not None:
339 # Mode override without slot override — move existing slots
340 nvme_slots = settings.pop('DirectAttachedNvmeSlots', settings.pop('ControllerAttachedNvmeSlots', None))
341 if nvme_slots:
342 if module.params['nvme_mode'] == 'direct':
343 settings['DirectAttachedNvmeSlots'] = nvme_slots
344 else:
345 settings['ControllerAttachedNvmeSlots'] = nvme_slots
346
347 # Apply M.2 boot override
348 if module.params.get('m2_boot_enabled') is not None:
349 settings['M2VirtualDrive']['Enable'] = module.params['m2_boot_enabled']
350
351 # Apply cache policy overrides to RAID0 drive config
352 if module.params.get('read_policy') is not None:
353 settings['Raid0Drive']['VirtualDrivePolicy']['ReadPolicy'] = module.params['read_policy']
354 if module.params.get('write_policy') is not None:
355 settings['Raid0Drive']['VirtualDrivePolicy']['WritePolicy'] = module.params['write_policy']
356
357 intersight.api_body.update(settings)
358 intersight.result['applied_settings'] = settings
359
360 intersight.configure_policy_or_profile(resource_path=resource_path)
361
362 module.exit_json(**intersight.result)
363
364
365 if __name__ == '__main__':
366 main()