Debian Codegraph @

ansible_collections/cisco/intersight/plugins/modules/intersight_fibre_channel_adapter_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_fibre_channel_adapter_policy
16 short_description: Manage Fibre Channel Adapter Policies for Cisco Intersight
17 description:
18 - Create, update, and delete Fibre Channel Adapter Policies on Cisco Intersight.
19 - Fibre Channel Adapter policies configure FC adapter settings for Fibre Channel virtual interfaces.
20 - These policies control error recovery, timeouts, retry counts, interrupt modes, queue settings, and LUN configurations.
21 - For more information see L(Cisco Intersight,https://intersight.com/apidocs/vnic/FcAdapterPolicies/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 - Policies created within a Custom Organization are applicable only to devices in the same Organization.
35 - Use 'default' for the default organization.
36 type: str
37 default: default
38 name:
39 description:
40 - The name assigned to the Fibre Channel Adapter Policy.
41 - Must be unique within the organization.
42 - The name must be between 1 and 62 alphanumeric characters, allowing special characters :-_.
43 type: str
44 required: true
45 description:
46 description:
47 - The user-defined description for the Fibre Channel Adapter Policy.
48 - Description can contain letters(a-z, A-Z), numbers(0-9), hyphen(-), period(.), colon(:), or an underscore(_).
49 type: str
50 aliases: [descr]
51 tags:
52 description:
53 - List of tags in Key:<user-defined key> Value:<user-defined value> format.
54 type: list
55 elements: dict
56 error_recovery_enabled:
57 description:
58 - Enables Fibre Channel Error recovery.
59 type: bool
60 default: false
61 port_down_timeout:
62 description:
63 - The number of milliseconds a remote Fibre Channel port should be offline before informing the SCSI upper layer.
64 - This determines when the port is considered unavailable.
65 - For a server with a VIC adapter running ESXi, the recommended value is 10000.
66 - For a server with a port used to boot a Windows OS from the SAN, the recommended value is 5000 milliseconds.
67 type: int
68 default: 10000
69 io_retry_timeout:
70 description:
71 - The number of seconds the adapter waits before aborting the pending command.
72 - After timeout, it resends the same IO request.
73 type: int
74 default: 5
75 link_down_timeout:
76 description:
77 - The number of milliseconds the port should actually be down before it is marked down.
78 - After this timeout, fabric connectivity is considered lost.
79 type: int
80 default: 30000
81 port_down_io_retry_count:
82 description:
83 - The number of times an I/O request to a port is retried because the port is busy.
84 - After this count, the system decides the port is unavailable.
85 type: int
86 default: 8
87 error_detection_timeout:
88 description:
89 - Error Detection Timeout, also referred to as EDTOV, is the number of milliseconds to wait.
90 - This is the time before the system assumes that an error has occurred.
91 type: int
92 default: 2000
93 resource_allocation_timeout:
94 description:
95 - Resource Allocation Timeout, also referred to as RATOV, is the number of milliseconds to wait.
96 - This is the time before the system assumes that a resource cannot be properly allocated.
97 type: int
98 default: 10000
99 flogi_retries:
100 description:
101 - The number of times that the system tries to log in to the fabric after the first failure.
102 type: int
103 default: 8
104 flogi_timeout:
105 description:
106 - The number of milliseconds that the system waits before it tries to log in again.
107 type: int
108 default: 4000
109 plogi_retries:
110 description:
111 - The number of times that the system tries to log in to a port after the first failure.
112 type: int
113 default: 8
114 plogi_timeout:
115 description:
116 - The number of milliseconds that the system waits before it tries to log in again.
117 type: int
118 default: 20000
119 interrupt_mode:
120 description:
121 - The preferred driver interrupt mode.
122 - MSIx is the recommended option.
123 type: str
124 choices: [MSIx, MSI, INTx]
125 default: MSIx
126 io_throttle_count:
127 description:
128 - The maximum number of data or control I/O operations that can be pending for the virtual interface at one time.
129 - If this value is exceeded, the additional I/O operations wait in the queue.
130 - They wait until the number of pending I/O operations decreases and the additional operations can be processed.
131 type: int
132 default: 512
133 lun_count:
134 description:
135 - The maximum number of LUNs that the Fibre Channel driver will export or show.
136 - The maximum number of LUNs is usually controlled by the operating system running on the server.
137 - Lun Count value can exceed 1024 only for vHBA of type 'FC Initiator' and on servers having supported firmware version.
138 type: int
139 default: 1024
140 lun_queue_depth:
141 description:
142 - The number of commands that the HBA can send and receive in a single transmission per LUN.
143 type: int
144 default: 20
145 rx_ring_size:
146 description:
147 - The number of descriptors in each receive queue.
148 - The maximum value for Receive queue is 2048.
149 type: int
150 default: 64
151 tx_ring_size:
152 description:
153 - The number of descriptors in each transmit queue.
154 - The maximum value for Transmit queue is 128.
155 type: int
156 default: 64
157 scsi_io_queue_count:
158 description:
159 - The number of SCSI I/O queue resources the system should allocate.
160 type: int
161 default: 1
162 scsi_io_ring_size:
163 description:
164 - The number of descriptors in each SCSI I/O queue.
165 type: int
166 default: 512
167 author:
168 - Ron Gershburg (@rgershbu)
169 '''
170
171 EXAMPLES = r'''
172 - name: Create Fibre Channel Adapter Policy with default settings
173 cisco.intersight.intersight_fibre_channel_adapter_policy:
174 api_private_key: "{{ api_private_key }}"
175 api_key_id: "{{ api_key_id }}"
176 organization: "default"
177 name: "fc-adapter-default"
178 description: "Fibre Channel Adapter policy with default values"
179 state: present
180
181 - name: Create Fibre Channel Adapter Policy with custom error recovery settings
182 cisco.intersight.intersight_fibre_channel_adapter_policy:
183 api_private_key: "{{ api_private_key }}"
184 api_key_id: "{{ api_key_id }}"
185 organization: "default"
186 name: "fc-adapter-error-recovery"
187 description: "FC Adapter policy with error recovery enabled"
188 error_recovery_enabled: true
189 port_down_timeout: 5000
190 io_retry_timeout: 8
191 link_down_timeout: 20000
192 port_down_io_retry_count: 10
193 tags:
194 - Key: Environment
195 Value: Production
196 state: present
197
198 - name: Create Fibre Channel Adapter Policy with custom queue settings
199 cisco.intersight.intersight_fibre_channel_adapter_policy:
200 api_private_key: "{{ api_private_key }}"
201 api_key_id: "{{ api_key_id }}"
202 organization: "default"
203 name: "fc-adapter-high-performance"
204 description: "FC Adapter policy with optimized queue settings"
205 io_throttle_count: 1024
206 lun_count: 4096
207 lun_queue_depth: 254
208 rx_ring_size: 128
209 tx_ring_size: 128
210 scsi_io_queue_count: 8
211 scsi_io_ring_size: 512
212 state: present
213
214 - name: Create Fibre Channel Adapter Policy with custom timeout settings
215 cisco.intersight.intersight_fibre_channel_adapter_policy:
216 api_private_key: "{{ api_private_key }}"
217 api_key_id: "{{ api_key_id }}"
218 organization: "Engineering"
219 name: "fc-adapter-custom-timeouts"
220 description: "FC Adapter policy with custom timeout values"
221 error_detection_timeout: 5000
222 resource_allocation_timeout: 15000
223 flogi_retries: 12
224 flogi_timeout: 8000
225 plogi_retries: 12
226 plogi_timeout: 30000
227 state: present
228
229 - name: Create Fibre Channel Adapter Policy with MSI interrupt mode
230 cisco.intersight.intersight_fibre_channel_adapter_policy:
231 api_private_key: "{{ api_private_key }}"
232 api_key_id: "{{ api_key_id }}"
233 organization: "default"
234 name: "fc-adapter-msi-mode"
235 description: "FC Adapter policy with MSI interrupt mode"
236 interrupt_mode: MSI
237 state: present
238
239 - name: Update Fibre Channel Adapter Policy description
240 cisco.intersight.intersight_fibre_channel_adapter_policy:
241 api_private_key: "{{ api_private_key }}"
242 api_key_id: "{{ api_key_id }}"
243 organization: "default"
244 name: "fc-adapter-default"
245 description: "Updated FC Adapter policy description"
246 state: present
247
248 - name: Delete Fibre Channel Adapter Policy
249 cisco.intersight.intersight_fibre_channel_adapter_policy:
250 api_private_key: "{{ api_private_key }}"
251 api_key_id: "{{ api_key_id }}"
252 organization: "default"
253 name: "fc-adapter-default"
254 state: absent
255 '''
256
257 RETURN = r'''
258 api_response:
259 description: The API response output returned by the specified resource.
260 returned: always
261 type: dict
262 sample:
263 "api_response": {
264 "Name": "fc-adapter-default",
265 "ObjectType": "vnic.FcAdapterPolicy",
266 "Moid": "1234567890abcdef12345678",
267 "Description": "Fibre Channel Adapter policy with default values",
268 "ErrorRecoverySettings": {
269 "Enabled": false,
270 "PortDownTimeout": 10000,
271 "LinkDownTimeout": 30000,
272 "IoRetryTimeout": 5,
273 "IoRetryCount": 8
274 },
275 "ErrorDetectionTimeout": 2000,
276 "ResourceAllocationTimeout": 10000,
277 "FlogiSettings": {
278 "Retries": 8,
279 "Timeout": 4000
280 },
281 "PlogiSettings": {
282 "Retries": 8,
283 "Timeout": 20000
284 },
285 "InterruptSettings": {
286 "Mode": "MSIx"
287 },
288 "IoThrottleCount": 512,
289 "LunCount": 1024,
290 "LunQueueDepth": 20,
291 "RxQueueSettings": {
292 "RingSize": 64
293 },
294 "TxQueueSettings": {
295 "RingSize": 64
296 },
297 "ScsiQueueSettings": {
298 "Count": 1,
299 "RingSize": 512
300 },
301 "Organization": {
302 "Moid": "abcdef1234567890abcdef12",
303 "ObjectType": "organization.Organization"
304 },
305 "Tags": [
306 {
307 "Key": "Environment",
308 "Value": "Production"
309 }
310 ]
311 }
312 '''
313
314
315 from ansible.module_utils.basic import AnsibleModule
316 from ansible_collections.cisco.intersight.plugins.module_utils.intersight import IntersightModule, intersight_argument_spec
317
318
319 def validate_parameters(module):
320 """
321 Validate module parameters for Fibre Channel Adapter policy configuration.
322 """
323 if module.params['state'] != 'present':
324 return
325 # Validate port_down_timeout range (0-240000)
326 port_down_timeout = module.params.get('port_down_timeout')
327 if port_down_timeout is not None and (port_down_timeout < 0 or port_down_timeout > 240000):
328 module.fail_json(msg="Parameter 'port_down_timeout' must be between 0 and 240000")
329 # Validate io_retry_timeout range (1-59)
330 io_retry_timeout = module.params.get('io_retry_timeout')
331 if io_retry_timeout is not None and (io_retry_timeout < 1 or io_retry_timeout > 59):
332 module.fail_json(msg="Parameter 'io_retry_timeout' must be between 1 and 59")
333 # Validate link_down_timeout range (0-240000)
334 link_down_timeout = module.params.get('link_down_timeout')
335 if link_down_timeout is not None and (link_down_timeout < 0 or link_down_timeout > 240000):
336 module.fail_json(msg="Parameter 'link_down_timeout' must be between 0 and 240000")
337 # Validate port_down_io_retry_count range (0-255)
338 port_down_io_retry_count = module.params.get('port_down_io_retry_count')
339 if port_down_io_retry_count is not None and (port_down_io_retry_count < 0 or port_down_io_retry_count > 255):
340 module.fail_json(msg="Parameter 'port_down_io_retry_count' must be between 0 and 255")
341 # Validate error_detection_timeout range (1000-100000)
342 error_detection_timeout = module.params.get('error_detection_timeout')
343 if error_detection_timeout is not None and (error_detection_timeout < 1000 or error_detection_timeout > 100000):
344 module.fail_json(msg="Parameter 'error_detection_timeout' must be between 1000 and 100000")
345 # Validate resource_allocation_timeout range (5000-100000)
346 resource_allocation_timeout = module.params.get('resource_allocation_timeout')
347 if resource_allocation_timeout is not None and (resource_allocation_timeout < 5000 or resource_allocation_timeout > 100000):
348 module.fail_json(msg="Parameter 'resource_allocation_timeout' must be between 5000 and 100000")
349 # Validate flogi_retries range (0-4294967295)
350 flogi_retries = module.params.get('flogi_retries')
351 if flogi_retries is not None and (flogi_retries < 0 or flogi_retries > 4294967295):
352 module.fail_json(msg="Parameter 'flogi_retries' must be between 0 and 4294967295")
353 # Validate flogi_timeout range (1000-255000)
354 flogi_timeout = module.params.get('flogi_timeout')
355 if flogi_timeout is not None and (flogi_timeout < 1000 or flogi_timeout > 255000):
356 module.fail_json(msg="Parameter 'flogi_timeout' must be between 1000 and 255000")
357 # Validate plogi_retries range (0-255)
358 plogi_retries = module.params.get('plogi_retries')
359 if plogi_retries is not None and (plogi_retries < 0 or plogi_retries > 255):
360 module.fail_json(msg="Parameter 'plogi_retries' must be between 0 and 255")
361 # Validate plogi_timeout range (1000-255000)
362 plogi_timeout = module.params.get('plogi_timeout')
363 if plogi_timeout is not None and (plogi_timeout < 1000 or plogi_timeout > 255000):
364 module.fail_json(msg="Parameter 'plogi_timeout' must be between 1000 and 255000")
365 # Validate io_throttle_count range (1-1024)
366 io_throttle_count = module.params.get('io_throttle_count')
367 if io_throttle_count is not None and (io_throttle_count < 1 or io_throttle_count > 1024):
368 module.fail_json(msg="Parameter 'io_throttle_count' must be between 1 and 1024")
369 # Validate lun_count range (1-4096)
370 lun_count = module.params.get('lun_count')
371 if lun_count is not None and (lun_count < 1 or lun_count > 4096):
372 module.fail_json(msg="Parameter 'lun_count' must be between 1 and 4096")
373 # Validate lun_queue_depth range (1-254)
374 lun_queue_depth = module.params.get('lun_queue_depth')
375 if lun_queue_depth is not None and (lun_queue_depth < 1 or lun_queue_depth > 254):
376 module.fail_json(msg="Parameter 'lun_queue_depth' must be between 1 and 254")
377 # Validate rx_ring_size (>= 64)
378 rx_ring_size = module.params.get('rx_ring_size')
379 if rx_ring_size is not None and rx_ring_size < 64:
380 module.fail_json(msg="Parameter 'rx_ring_size' must be at least 64")
381 # Validate tx_ring_size (>= 64)
382 tx_ring_size = module.params.get('tx_ring_size')
383 if tx_ring_size is not None and tx_ring_size < 64:
384 module.fail_json(msg="Parameter 'tx_ring_size' must be at least 64")
385 # Validate scsi_io_queue_count range (1-245)
386 scsi_io_queue_count = module.params.get('scsi_io_queue_count')
387 if scsi_io_queue_count is not None and (scsi_io_queue_count < 1 or scsi_io_queue_count > 245):
388 module.fail_json(msg="Parameter 'scsi_io_queue_count' must be between 1 and 245")
389 # Validate scsi_io_ring_size range (64-512)
390 scsi_io_ring_size = module.params.get('scsi_io_ring_size')
391 if scsi_io_ring_size is not None and (scsi_io_ring_size < 64 or scsi_io_ring_size > 512):
392 module.fail_json(msg="Parameter 'scsi_io_ring_size' must be between 64 and 512")
393
394
395 def main():
396 argument_spec = intersight_argument_spec.copy()
397 argument_spec.update(
398 state=dict(type='str', choices=['present', 'absent'], default='present'),
399 organization=dict(type='str', default='default'),
400 name=dict(type='str', required=True),
401 description=dict(type='str', aliases=['descr']),
402 tags=dict(type='list', elements='dict'),
403 error_recovery_enabled=dict(type='bool', default=False),
404 port_down_timeout=dict(type='int', default=10000),
405 io_retry_timeout=dict(type='int', default=5),
406 link_down_timeout=dict(type='int', default=30000),
407 port_down_io_retry_count=dict(type='int', default=8),
408 error_detection_timeout=dict(type='int', default=2000),
409 resource_allocation_timeout=dict(type='int', default=10000),
410 flogi_retries=dict(type='int', default=8),
411 flogi_timeout=dict(type='int', default=4000),
412 plogi_retries=dict(type='int', default=8),
413 plogi_timeout=dict(type='int', default=20000),
414 interrupt_mode=dict(type='str', choices=['MSIx', 'MSI', 'INTx'], default='MSIx'),
415 io_throttle_count=dict(type='int', default=512),
416 lun_count=dict(type='int', default=1024),
417 lun_queue_depth=dict(type='int', default=20),
418 rx_ring_size=dict(type='int', default=64),
419 tx_ring_size=dict(type='int', default=64),
420 scsi_io_queue_count=dict(type='int', default=1),
421 scsi_io_ring_size=dict(type='int', default=512),
422 )
423 module = AnsibleModule(
424 argument_spec,
425 supports_check_mode=True,
426 )
427 intersight = IntersightModule(module)
428 intersight.result['api_response'] = {}
429 intersight.result['trace_id'] = ''
430
431 # Validate module parameters
432 validate_parameters(module)
433
434 # Resource path used to configure policy
435 resource_path = '/vnic/FcAdapterPolicies'
436
437 # Define API body used in compares or create
438 intersight.api_body = {
439 'Organization': {
440 'Name': module.params['organization'],
441 },
442 'Name': module.params['name'],
443 }
444
445 if module.params['state'] == 'present':
446 intersight.api_body['ErrorRecoverySettings'] = {
447 'Enabled': module.params['error_recovery_enabled'],
448 'PortDownTimeout': module.params['port_down_timeout'],
449 'LinkDownTimeout': module.params['link_down_timeout'],
450 'IoRetryTimeout': module.params['io_retry_timeout'],
451 'IoRetryCount': module.params['port_down_io_retry_count'],
452 }
453 intersight.api_body['ErrorDetectionTimeout'] = module.params['error_detection_timeout']
454 intersight.api_body['ResourceAllocationTimeout'] = module.params['resource_allocation_timeout']
455 intersight.api_body['FlogiSettings'] = {
456 'Retries': module.params['flogi_retries'],
457 'Timeout': module.params['flogi_timeout'],
458 }
459 intersight.api_body['PlogiSettings'] = {
460 'Retries': module.params['plogi_retries'],
461 'Timeout': module.params['plogi_timeout'],
462 }
463 intersight.api_body['InterruptSettings'] = {
464 'Mode': module.params['interrupt_mode'],
465 }
466 intersight.api_body['IoThrottleCount'] = module.params['io_throttle_count']
467 intersight.api_body['LunCount'] = module.params['lun_count']
468 intersight.api_body['LunQueueDepth'] = module.params['lun_queue_depth']
469 intersight.api_body['RxQueueSettings'] = {
470 'RingSize': module.params['rx_ring_size'],
471 }
472 intersight.api_body['TxQueueSettings'] = {
473 'RingSize': module.params['tx_ring_size'],
474 }
475 intersight.api_body['ScsiQueueSettings'] = {
476 'Count': module.params['scsi_io_queue_count'],
477 'RingSize': module.params['scsi_io_ring_size'],
478 }
479 intersight.set_tags_and_description()
480 intersight.configure_policy_or_profile(resource_path=resource_path)
481 module.exit_json(**intersight.result)
482
483
484 if __name__ == '__main__':
485 main()