Debian Codegraph @

ansible_collections/cisco/intersight/plugins/modules/intersight_ethernet_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_ethernet_adapter_policy
16 short_description: Ethernet Adapter Policy configuration for Cisco Intersight
17 description:
18 - Manages Ethernet Adapter Policy configuration on Cisco Intersight.
19 - Configure virtual ethernet interface settings including advanced features like RDMA, QoS, and offload capabilities.
20 - For more information see L(Cisco Intersight,https://intersight.com/apidocs/vnic/EthAdapterPolicy/get/).
21 extends_documentation_fragment: intersight
22 options:
23 state:
24 description:
25 - If C(present), will verify the resource is present and will create if needed.
26 - If C(absent), will verify the resource is absent and will delete if needed.
27 type: str
28 choices: [present, absent]
29 default: present
30 organization:
31 description:
32 - The name of the Organization this resource is assigned to.
33 - Profiles, Policies, and Pools that are created within a Custom Organization are applicable only to devices in the same Organization.
34 type: str
35 default: default
36 name:
37 description:
38 - The name assigned to the Ethernet Adapter Policy.
39 - The name must be between 1 and 62 alphanumeric characters, allowing special characters :-_.
40 type: str
41 required: true
42 description:
43 description:
44 - The user-defined description for the Ethernet Adapter Policy.
45 - Description can contain letters(a-z, A-Z), numbers(0-9), hyphen(-), period(.), colon(:), or an underscore(_).
46 type: str
47 aliases: [descr]
48 tags:
49 description:
50 - List of tags in Key:<user-defined key> Value:<user-defined value> format.
51 type: list
52 elements: dict
53 vxlan_enabled:
54 description:
55 - Status of the Virtual Extensible LAN Protocol on the virtual ethernet interface.
56 type: bool
57 default: false
58 nvgre_enabled:
59 description:
60 - Status of the Network Virtualization using Generic Routing Encapsulation on the virtual ethernet interface.
61 type: bool
62 default: false
63 arfs_enabled:
64 description:
65 - Status of Accelerated Receive Flow Steering on the virtual ethernet interface.
66 type: bool
67 default: false
68 ptp_enabled:
69 description:
70 - Status of Precision Time Protocol (PTP) on the virtual ethernet interface.
71 - PTP can be enabled only on one vNIC on an adapter.
72 type: bool
73 default: false
74 advanced_filter:
75 description:
76 - Enables advanced filtering on the interface.
77 type: bool
78 default: false
79 interrupt_scaling:
80 description:
81 - Enables Interrupt Scaling on the interface.
82 type: bool
83 default: false
84 geneve_enabled:
85 description:
86 - GENEVE offload protocol allows you to create logical networks that span physical network boundaries.
87 - Cannot be enabled simultaneously with ARFS.
88 type: bool
89 default: false
90 etherchannel_pinning_enabled:
91 description:
92 - Enables EtherChannel Pinning to combine multiple physical links between two network switches into a single logical link.
93 - Transmit Queue Count should be at least 2 to enable ether channel pinning.
94 type: bool
95 default: false
96 roce_enabled:
97 description:
98 - If enabled sets RDMA over Converged Ethernet (RoCE) on this virtual interface.
99 - Cannot be enabled simultaneously with NVGRE.
100 type: bool
101 default: false
102 roce_queue_pairs:
103 description:
104 - The number of queue pairs per adapter. Recommended value = integer power of 2.
105 - Only applicable when roce_enabled is true.
106 type: int
107 default: 256
108 roce_memory_regions:
109 description:
110 - The number of memory regions per adapter. Recommended value = integer power of 2.
111 - Only applicable when roce_enabled is true.
112 type: int
113 default: 131072
114 roce_resource_groups:
115 description:
116 - The number of resource groups per adapter. Recommended value = be an integer power of 2 greater than or equal to the number of CPU cores.
117 - Only applicable when roce_enabled is true.
118 type: int
119 default: 2
120 roce_version:
121 description:
122 - Configure RDMA over Converged Ethernet (RoCE) version on the virtual interface.
123 - Only RoCEv1 is supported on Cisco VIC 13xx series adapters and only RoCEv2 is supported on Cisco VIC 14xx series adapters.
124 - Only applicable when roce_enabled is true.
125 type: int
126 choices: [1, 2]
127 default: 1
128 roce_class_of_service:
129 description:
130 - The Class of Service for RoCE on this virtual interface.
131 - Only applicable when roce_enabled is true.
132 type: int
133 choices: [1, 2, 4, 5, 6]
134 default: 5
135 interrupt_count:
136 description:
137 - The number of interrupt resources to allocate. Typical value is be equal to the number of completion queue resources.
138 type: int
139 default: 8
140 interrupt_mode:
141 description:
142 - Preferred driver interrupt mode.
143 - MSIx - Message Signaled Interrupts (MSI) with the optional extension (recommended).
144 - MSI - MSI only.
145 - INTx - PCI INTx interrupts.
146 type: str
147 choices: ['MSIx', 'MSI', 'INTx']
148 default: 'MSIx'
149 interrupt_coalescing_time:
150 description:
151 - The time to wait between interrupts or the idle period that must be encountered before an interrupt is sent.
152 - To turn off interrupt coalescing, enter 0 (zero) in this field.
153 type: int
154 default: 125
155 interrupt_coalescing_type:
156 description:
157 - Interrupt Coalescing Type.
158 - MIN - The system waits for the time specified in the Coalescing Time field before sending another interrupt event.
159 - IDLE - The system does not send an interrupt until there is a period of no activity
160 lasting at least as long as the time specified in the Coalescing Time field.
161 type: str
162 choices: ['MIN', 'IDLE']
163 default: 'MIN'
164 rx_queue_count:
165 description:
166 - The number of receive queue resources to allocate.
167 type: int
168 default: 4
169 rx_ring_size:
170 description:
171 - The number of descriptors in each receive queue.
172 type: int
173 default: 512
174 tx_queue_count:
175 description:
176 - The number of transmit queue resources to allocate.
177 type: int
178 default: 1
179 tx_ring_size:
180 description:
181 - The number of descriptors in each transmit queue.
182 type: int
183 default: 256
184 completion_queue_count:
185 description:
186 - The number of completion queue resources to allocate.
187 - In general, the number of completion queue resources to allocate is equal to the number of transmit queue resources
188 plus the number of receive queue resources.
189 type: int
190 default: 5
191 completion_ring_size:
192 description:
193 - The number of descriptors in each completion queue.
194 type: int
195 default: 1
196 uplink_failback_timeout:
197 description:
198 - Uplink Failback Timeout in seconds when uplink failover is enabled for a vNIC.
199 - After a vNIC has started using its secondary interface, this setting controls how long
200 the primary interface must be available before the system resumes using the primary
201 interface for the vNIC.
202 type: int
203 default: 5
204 tcp_tx_checksum:
205 description:
206 - When enabled, the CPU sends all packets to the hardware so that the checksum can be calculated.
207 type: bool
208 default: true
209 tcp_rx_checksum:
210 description:
211 - When enabled, the CPU sends all packet checksums to the hardware for validation.
212 type: bool
213 default: true
214 tcp_large_send:
215 description:
216 - Enables the CPU to send large packets to the hardware for segmentation.
217 type: bool
218 default: true
219 tcp_large_receive:
220 description:
221 - Enables the reassembly of segmented packets in hardware before sending them to the CPU.
222 type: bool
223 default: true
224 rss_enabled:
225 description:
226 - Receive Side Scaling allows the incoming traffic to be spread across multiple CPU cores.
227 type: bool
228 default: true
229 rss_ipv4_hash:
230 description:
231 - When enabled, the IPv4 address is used for traffic distribution.
232 type: bool
233 default: true
234 rss_ipv6_hash:
235 description:
236 - When enabled, the IPv6 address is used for traffic distribution.
237 type: bool
238 default: false
239 rss_ipv6_ext_hash:
240 description:
241 - When enabled, the IPv6 extensions are used for traffic distribution.
242 type: bool
243 default: true
244 rss_tcp_ipv4_hash:
245 description:
246 - When enabled, both the IPv4 address and TCP port number are used for traffic distribution.
247 type: bool
248 default: true
249 rss_tcp_ipv6_hash:
250 description:
251 - When enabled, both the IPv6 address and TCP port number are used for traffic distribution.
252 type: bool
253 default: false
254 rss_tcp_ipv6_ext_hash:
255 description:
256 - When enabled, both the IPv6 extensions and TCP port number are used for traffic distribution.
257 type: bool
258 default: true
259 rss_udp_ipv4_hash:
260 description:
261 - When enabled, both the IPv4 address and UDP port number are used for traffic distribution.
262 type: bool
263 default: false
264 rss_udp_ipv6_hash:
265 description:
266 - When enabled, both the IPv6 address and UDP port number are used for traffic distribution.
267 type: bool
268 default: false
269 author:
270 - Ron Gershburg (@rgershbu)
271 '''
272
273 EXAMPLES = r'''
274 - name: Create a basic Ethernet Adapter Policy
275 cisco.intersight.intersight_ethernet_adapter_policy:
276 api_private_key: "{{ api_private_key }}"
277 api_key_id: "{{ api_key_id }}"
278 name: "basic-ethernet-adapter-policy"
279 description: "Basic Ethernet adapter policy with default settings"
280 tags:
281 - Key: "Environment"
282 Value: "Production"
283
284 - name: Create an Ethernet Adapter Policy with VXLAN and advanced features
285 cisco.intersight.intersight_ethernet_adapter_policy:
286 api_private_key: "{{ api_private_key }}"
287 api_key_id: "{{ api_key_id }}"
288 name: "advanced-ethernet-adapter-policy"
289 description: "Advanced Ethernet adapter policy with VXLAN and PTP"
290 vxlan_enabled: true
291 ptp_enabled: true
292 advanced_filter: true
293 interrupt_scaling: true
294 interrupt_count: 16
295 rx_queue_count: 8
296 tx_queue_count: 4
297 completion_queue_count: 12
298 tags:
299 - Key: "Environment"
300 Value: "Production"
301 - Key: "Feature"
302 Value: "Advanced"
303
304 - name: Create an Ethernet Adapter Policy with RoCE enabled
305 cisco.intersight.intersight_ethernet_adapter_policy:
306 api_private_key: "{{ api_private_key }}"
307 api_key_id: "{{ api_key_id }}"
308 name: "roce-ethernet-adapter-policy"
309 description: "Ethernet adapter policy with RoCE v2 enabled"
310 roce_enabled: true
311 roce_queue_pairs: 256
312 roce_memory_regions: 131072
313 roce_resource_groups: 2
314 roce_version: 2
315 roce_class_of_service: 5
316 tags:
317 - Key: "Protocol"
318 Value: "RoCE"
319
320 - name: Create an Ethernet Adapter Policy with EtherChannel pinning
321 cisco.intersight.intersight_ethernet_adapter_policy:
322 api_private_key: "{{ api_private_key }}"
323 api_key_id: "{{ api_key_id }}"
324 name: "etherchannel-adapter-policy"
325 description: "Ethernet adapter policy with EtherChannel pinning"
326 etherchannel_pinning_enabled: true
327 tx_queue_count: 2
328 completion_queue_count: 6
329 tags:
330 - Key: "Feature"
331 Value: "EtherChannel"
332
333 - name: Create an Ethernet Adapter Policy with custom RSS settings
334 cisco.intersight.intersight_ethernet_adapter_policy:
335 api_private_key: "{{ api_private_key }}"
336 api_key_id: "{{ api_key_id }}"
337 name: "custom-rss-adapter-policy"
338 description: "Ethernet adapter policy with custom RSS configuration"
339 rss_enabled: true
340 rss_ipv4_hash: true
341 rss_ipv6_hash: false
342 rss_tcp_ipv4_hash: false
343 rss_tcp_ipv6_hash: false
344 rss_udp_ipv4_hash: true
345 rss_udp_ipv6_hash: true
346 tags:
347 - Key: "Feature"
348 Value: "CustomRSS"
349
350 - name: Delete an Ethernet Adapter Policy
351 cisco.intersight.intersight_ethernet_adapter_policy:
352 api_private_key: "{{ api_private_key }}"
353 api_key_id: "{{ api_key_id }}"
354 name: "old-ethernet-adapter-policy"
355 state: absent
356 '''
357
358 RETURN = r'''
359 api_response:
360 description: The API response output returned by the specified resource.
361 returned: always
362 type: dict
363 sample:
364 {
365 "Moid": "6889f3e8f654d9f7013baae4",
366 "ObjectType": "vnic.EthAdapterPolicy",
367 "Name": "basic-ethernet-adapter-policy",
368 "Description": "Basic Ethernet adapter policy with default settings",
369 "AdvancedFilter": false,
370 "ArfsSettings": {
371 "Enabled": false
372 },
373 "VxlanSettings": {
374 "Enabled": false
375 },
376 "NvgreSettings": {
377 "Enabled": false
378 },
379 "PtpSettings": {
380 "Enabled": false
381 },
382 "RoceSettings": {
383 "Enabled": false
384 },
385 "InterruptSettings": {
386 "Count": 8,
387 "Mode": "MSIx",
388 "CoalescingTime": 125,
389 "CoalescingType": "MIN"
390 },
391 "RxQueueSettings": {
392 "Count": 4,
393 "RingSize": 512
394 },
395 "TxQueueSettings": {
396 "Count": 1,
397 "RingSize": 256
398 },
399 "CompletionQueueSettings": {
400 "Count": 5,
401 "RingSize": 1
402 },
403 "TcpOffloadSettings": {
404 "TxChecksum": true,
405 "RxChecksum": true,
406 "LargeSend": true,
407 "LargeReceive": true
408 },
409 "RssSettings": true,
410 "RssHashSettings": {
411 "Ipv4Hash": true,
412 "Ipv6Hash": true,
413 "Ipv6ExtHash": false,
414 "TcpIpv4Hash": true,
415 "TcpIpv6Hash": true,
416 "TcpIpv6ExtHash": false,
417 "UdpIpv4Hash": false,
418 "UdpIpv6Hash": false
419 }
420 }
421 '''
422
423
424 from ansible.module_utils.basic import AnsibleModule
425 from ansible_collections.cisco.intersight.plugins.module_utils.intersight import IntersightModule, intersight_argument_spec
426
427
428 def validate_configuration(module):
429 """
430 Validate configuration according to Intersight constraints.
431 """
432 # Constraint 1: Cannot enable RDMA over Converged Ethernet and NVGRE simultaneously
433 if module.params['roce_enabled'] and module.params['nvgre_enabled']:
434 module.fail_json(
435 msg="Cannot enable RDMA over Converged Ethernet and NVGRE simultaneously."
436 )
437
438 # Constraint 2: Cannot enable 'GENEVE Offload' and 'Accelerated Receive Flow Steering (ARFS)' simultaneously
439 if module.params['geneve_enabled'] and module.params['arfs_enabled']:
440 module.fail_json(
441 msg="Cannot enable 'GENEVE Offload' and 'Accelerated Receive Flow Steering (ARFS)' simultaneously."
442 )
443
444 # Constraint 3: Cannot enable ether channel pinning with transmit queue count less than 2
445 if module.params['etherchannel_pinning_enabled'] and module.params['tx_queue_count'] < 2:
446 module.fail_json(
447 msg="Cannot enable ether channel pinning with transmit queue count less than 2. "
448 "Current tx_queue_count is {}. Set tx_queue_count to at least 2.".format(
449 module.params['tx_queue_count']
450 )
451 )
452
453 # Validate ranges
454 if not (1 <= module.params['interrupt_count'] <= 1024):
455 module.fail_json(msg="interrupt_count must be between 1 and 1024")
456
457 if not (0 <= module.params['interrupt_coalescing_time'] <= 65535):
458 module.fail_json(msg="interrupt_coalescing_time must be between 0 and 65535")
459
460 if not (1 <= module.params['rx_queue_count'] <= 1000):
461 module.fail_json(msg="rx_queue_count must be between 1 and 1000")
462
463 if not (64 <= module.params['rx_ring_size'] <= 16384):
464 module.fail_json(msg="rx_ring_size must be between 64 and 16384")
465
466 if not (1 <= module.params['tx_queue_count'] <= 1000):
467 module.fail_json(msg="tx_queue_count must be between 1 and 1000")
468
469 if not (64 <= module.params['tx_ring_size'] <= 16384):
470 module.fail_json(msg="tx_ring_size must be between 64 and 16384")
471
472 if not (1 <= module.params['completion_queue_count'] <= 2000):
473 module.fail_json(msg="completion_queue_count must be between 1 and 2000")
474
475 if not (1 <= module.params['completion_ring_size'] <= 256):
476 module.fail_json(msg="completion_ring_size must be between 1 and 256")
477
478 if not (0 <= module.params['uplink_failback_timeout'] <= 600):
479 module.fail_json(msg="uplink_failback_timeout must be between 0 and 600")
480
481 # RoCE specific validations
482 if module.params['roce_enabled']:
483 if not (1 <= module.params['roce_queue_pairs'] <= 8192):
484 module.fail_json(msg="roce_queue_pairs must be between 1 and 8192")
485
486 if not (1 <= module.params['roce_memory_regions'] <= 524288):
487 module.fail_json(msg="roce_memory_regions must be between 1 and 524288")
488
489 if not (1 <= module.params['roce_resource_groups'] <= 128):
490 module.fail_json(msg="roce_resource_groups must be between 1 and 128")
491
492
493 def main():
494 argument_spec = intersight_argument_spec.copy()
495 argument_spec.update(
496 state=dict(type='str', choices=['present', 'absent'], default='present'),
497 organization=dict(type='str', default='default'),
498 name=dict(type='str', required=True),
499 description=dict(type='str', aliases=['descr']),
500 tags=dict(type='list', elements='dict'),
501 # VXLAN, NVGRE, ARFS, PTP settings
502 vxlan_enabled=dict(type='bool', default=False),
503 nvgre_enabled=dict(type='bool', default=False),
504 arfs_enabled=dict(type='bool', default=False),
505 ptp_enabled=dict(type='bool', default=False),
506 # Advanced features
507 advanced_filter=dict(type='bool', default=False),
508 interrupt_scaling=dict(type='bool', default=False),
509 geneve_enabled=dict(type='bool', default=False),
510 etherchannel_pinning_enabled=dict(type='bool', default=False),
511 # RoCE settings
512 roce_enabled=dict(type='bool', default=False),
513 roce_queue_pairs=dict(type='int', default=256),
514 roce_memory_regions=dict(type='int', default=131072),
515 roce_resource_groups=dict(type='int', default=2),
516 roce_version=dict(type='int', choices=[1, 2], default=1),
517 roce_class_of_service=dict(type='int', choices=[1, 2, 4, 5, 6], default=5),
518 # Interrupt settings
519 interrupt_count=dict(type='int', default=8),
520 interrupt_mode=dict(type='str', choices=['MSIx', 'MSI', 'INTx'], default='MSIx'),
521 interrupt_coalescing_time=dict(type='int', default=125),
522 interrupt_coalescing_type=dict(type='str', choices=['MIN', 'IDLE'], default='MIN'),
523 # Queue settings
524 rx_queue_count=dict(type='int', default=4),
525 rx_ring_size=dict(type='int', default=512),
526 tx_queue_count=dict(type='int', default=1),
527 tx_ring_size=dict(type='int', default=256),
528 # Completion
529 completion_queue_count=dict(type='int', default=5),
530 completion_ring_size=dict(type='int', default=1),
531 uplink_failback_timeout=dict(type='int', default=5),
532 # TCP offload settings
533 tcp_tx_checksum=dict(type='bool', default=True),
534 tcp_rx_checksum=dict(type='bool', default=True),
535 tcp_large_send=dict(type='bool', default=True),
536 tcp_large_receive=dict(type='bool', default=True),
537 # RSS settings
538 rss_enabled=dict(type='bool', default=True),
539 rss_ipv4_hash=dict(type='bool', default=True),
540 rss_ipv6_hash=dict(type='bool', default=False),
541 rss_ipv6_ext_hash=dict(type='bool', default=True),
542 rss_tcp_ipv4_hash=dict(type='bool', default=True),
543 rss_tcp_ipv6_hash=dict(type='bool', default=False),
544 rss_tcp_ipv6_ext_hash=dict(type='bool', default=True),
545 rss_udp_ipv4_hash=dict(type='bool', default=False),
546 rss_udp_ipv6_hash=dict(type='bool', default=False),
547 )
548
549 module = AnsibleModule(
550 argument_spec,
551 supports_check_mode=True,
552 )
553
554 validate_configuration(module)
555 intersight = IntersightModule(module)
556 intersight.result['api_response'] = {}
557 intersight.result['trace_id'] = ''
558
559 # Resource path used to configure policy
560 resource_path = '/vnic/EthAdapterPolicies'
561 # Define API body used in compares or create
562 intersight.api_body = {
563 'Organization': {
564 'Name': intersight.module.params['organization'],
565 },
566 'Name': intersight.module.params['name']
567 }
568
569 if module.params['state'] == 'present':
570 intersight.set_tags_and_description()
571
572 # Build the API body with all the settings
573 intersight.api_body.update({
574 'VxlanSettings': {
575 'Enabled': module.params['vxlan_enabled']
576 },
577 'NvgreSettings': {
578 'Enabled': module.params['nvgre_enabled']
579 },
580 'ArfsSettings': {
581 'Enabled': module.params['arfs_enabled']
582 },
583 'PtpSettings': {
584 'Enabled': module.params['ptp_enabled']
585 },
586 'AdvancedFilter': module.params['advanced_filter'],
587 'InterruptScaling': module.params['interrupt_scaling'],
588 'GeneveEnabled': module.params['geneve_enabled'],
589 'EtherChannelPinningEnabled': module.params['etherchannel_pinning_enabled'],
590 'RoceSettings': {
591 'Enabled': module.params['roce_enabled']
592 },
593 'InterruptSettings': {
594 'Count': module.params['interrupt_count'],
595 'Mode': module.params['interrupt_mode'],
596 'CoalescingTime': module.params['interrupt_coalescing_time'],
597 'CoalescingType': module.params['interrupt_coalescing_type']
598 },
599 'RxQueueSettings': {
600 'Count': module.params['rx_queue_count'],
601 'RingSize': module.params['rx_ring_size']
602 },
603 'TxQueueSettings': {
604 'Count': module.params['tx_queue_count'],
605 'RingSize': module.params['tx_ring_size']
606 },
607 'CompletionQueueSettings': {
608 'Count': module.params['completion_queue_count'],
609 'RingSize': module.params['completion_ring_size']
610 },
611 'UplinkFailbackTimeout': module.params['uplink_failback_timeout'],
612 'TcpOffloadSettings': {
613 'TxChecksum': module.params['tcp_tx_checksum'],
614 'RxChecksum': module.params['tcp_rx_checksum'],
615 'LargeSend': module.params['tcp_large_send'],
616 'LargeReceive': module.params['tcp_large_receive']
617 },
618 'RssSettings': module.params['rss_enabled'],
619 'RssHashSettings': {
620 'Ipv4Hash': module.params['rss_ipv4_hash'],
621 'Ipv6Hash': module.params['rss_ipv6_hash'],
622 'Ipv6ExtHash': module.params['rss_ipv6_ext_hash'],
623 'TcpIpv4Hash': module.params['rss_tcp_ipv4_hash'],
624 'TcpIpv6Hash': module.params['rss_tcp_ipv6_hash'],
625 'TcpIpv6ExtHash': module.params['rss_tcp_ipv6_ext_hash'],
626 'UdpIpv4Hash': module.params['rss_udp_ipv4_hash'],
627 'UdpIpv6Hash': module.params['rss_udp_ipv6_hash']
628 }
629 })
630
631 # Add RoCE-specific settings only when RoCE is enabled
632 if module.params['roce_enabled']:
633 intersight.api_body['RoceSettings'].update({
634 'QueuePairs': module.params['roce_queue_pairs'],
635 'MemoryRegions': module.params['roce_memory_regions'],
636 'ResourceGroups': module.params['roce_resource_groups'],
637 'Version': module.params['roce_version'],
638 'ClassOfService': module.params['roce_class_of_service']
639 })
640
641 intersight.configure_policy_or_profile(resource_path=resource_path)
642
643 module.exit_json(**intersight.result)
644
645
646 if __name__ == '__main__':
647 main()