Debian Codegraph @

ansible_collections/cisco/intersight/plugins/modules/intersight_flow_control_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_flow_control_policy
16 short_description: Flow Control Policy configuration for Cisco Intersight
17 description:
18 - Manages Flow Control Policy configuration on Cisco Intersight.
19 - A policy to configure Priority Flow Control (PFC) and link-level flow control settings for Cisco Intersight managed fabric interconnects.
20 - Priority Flow Control (PFC) enables no-drop behavior for specific traffic classes, while link-level flow control manages traffic flow at the link layer.
21 - For more information see L(Cisco Intersight,https://intersight.com/apidocs/fabric/FlowControlPolicies/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 Flow Control 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 Flow Control 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 priority_flow_control_mode:
55 description:
56 - Configure the Priority Flow Control (PFC) for each port to enable the no-drop behavior for the CoS defined by the System QoS Policy.
57 - PFC works with Ethernet QoS policy to enable no-drop behavior for specific CoS values.
58 - If Auto or On is selected for PFC, the Receive and Send link level flow control will be Off.
59 - C(auto) - PFC is automatically configured based on the QoS policies (default).
60 - C(on) - PFC is always enabled for the configured CoS values.
61 - C(off) - PFC is disabled. Link-level flow control settings will be used instead.
62 type: str
63 choices: ['auto', 'on', 'off']
64 default: auto
65 receive_direction:
66 description:
67 - Link-level Flow Control configured in the receive direction.
68 - This parameter is only applicable when C(priority_flow_control_mode) is set to C(off).
69 - When C(priority_flow_control_mode) is C(auto) or C(on), this will be automatically set to C(disabled).
70 - C(enabled) - Enable receive direction flow control.
71 - C(disabled) - Disable receive direction flow control.
72 type: str
73 choices: [enabled, disabled]
74 default: enabled
75 send_direction:
76 description:
77 - Link-level Flow Control configured in the send direction.
78 - This parameter is only applicable when C(priority_flow_control_mode) is set to C(off).
79 - When C(priority_flow_control_mode) is C(auto) or C(on), this will be automatically set to C(disabled).
80 - C(enabled) - Enable send direction flow control.
81 - C(disabled) - Disable send direction flow control.
82 type: str
83 choices: [enabled, disabled]
84 default: enabled
85 author:
86 - Ron Gershburg (@rgershbu)
87 '''
88
89 EXAMPLES = r'''
90 - name: Create a Flow Control Policy with auto PFC mode
91 cisco.intersight.intersight_flow_control_policy:
92 api_private_key: "{{ api_private_key }}"
93 api_key_id: "{{ api_key_id }}"
94 organization: "default"
95 name: "FlowControl-Auto-Policy"
96 description: "Flow control policy with auto PFC"
97 priority_flow_control_mode: auto
98 tags:
99 - Key: "Site"
100 Value: "DataCenter-A"
101 state: present
102
103 - name: Create a Flow Control Policy with PFC enabled
104 cisco.intersight.intersight_flow_control_policy:
105 api_private_key: "{{ api_private_key }}"
106 api_key_id: "{{ api_key_id }}"
107 name: "FlowControl-PFC-On-Policy"
108 description: "Flow control policy with PFC always on"
109 priority_flow_control_mode: on
110 state: present
111
112 - name: Create a Flow Control Policy with link-level flow control
113 cisco.intersight.intersight_flow_control_policy:
114 api_private_key: "{{ api_private_key }}"
115 api_key_id: "{{ api_key_id }}"
116 name: "FlowControl-LinkLevel-Policy"
117 description: "Flow control policy with link-level settings"
118 priority_flow_control_mode: off
119 receive_direction: enabled
120 send_direction: enabled
121 state: present
122
123 - name: Create a Flow Control Policy with disabled flow control
124 cisco.intersight.intersight_flow_control_policy:
125 api_private_key: "{{ api_private_key }}"
126 api_key_id: "{{ api_key_id }}"
127 name: "FlowControl-Disabled-Policy"
128 priority_flow_control_mode: off
129 receive_direction: disabled
130 send_direction: disabled
131 state: present
132
133 - name: Update a Flow Control Policy
134 cisco.intersight.intersight_flow_control_policy:
135 api_private_key: "{{ api_private_key }}"
136 api_key_id: "{{ api_key_id }}"
137 name: "FlowControl-Auto-Policy"
138 description: "Updated flow control policy"
139 priority_flow_control_mode: on
140 state: present
141
142 - name: Delete a Flow Control Policy
143 cisco.intersight.intersight_flow_control_policy:
144 api_private_key: "{{ api_private_key }}"
145 api_key_id: "{{ api_key_id }}"
146 name: "FlowControl-Auto-Policy"
147 state: absent
148 '''
149
150 RETURN = r'''
151 api_response:
152 description: The API response output returned by the specified resource.
153 returned: always
154 type: dict
155 sample:
156 "api_response": {
157 "Name": "FlowControl-Auto-Policy",
158 "ObjectType": "fabric.FlowControlPolicy",
159 "PriorityFlowControlMode": "auto",
160 "ReceiveDirection": "Enabled",
161 "SendDirection": "Enabled",
162 "Tags": [
163 {
164 "Key": "Site",
165 "Value": "DataCenter-A"
166 }
167 ]
168 }
169 '''
170
171 from ansible.module_utils.basic import AnsibleModule
172 from ansible_collections.cisco.intersight.plugins.module_utils.intersight import IntersightModule, intersight_argument_spec
173
174
175 def main():
176 argument_spec = intersight_argument_spec.copy()
177 argument_spec.update(
178 state=dict(type='str', choices=['present', 'absent'], default='present'),
179 organization=dict(type='str', default='default'),
180 name=dict(type='str', required=True),
181 description=dict(type='str', aliases=['descr']),
182 tags=dict(type='list', elements='dict'),
183 priority_flow_control_mode=dict(type='str', choices=['auto', 'on', 'off'], default='auto'),
184 receive_direction=dict(type='str', choices=['enabled', 'disabled'], default='enabled'),
185 send_direction=dict(type='str', choices=['enabled', 'disabled'], default='enabled')
186 )
187 module = AnsibleModule(
188 argument_spec,
189 supports_check_mode=True
190 )
191
192 intersight = IntersightModule(module)
193 intersight.result['api_response'] = {}
194 intersight.result['trace_id'] = ''
195
196 # Resource path used to configure policy
197 resource_path = '/fabric/FlowControlPolicies'
198
199 # Define API body used in compares or create
200 intersight.api_body = {
201 'Organization': {
202 'Name': intersight.module.params['organization'],
203 },
204 'Name': intersight.module.params['name'],
205 }
206
207 if intersight.module.params['state'] == 'present':
208 intersight.set_tags_and_description()
209
210 # Convert lowercase choices to API format
211 priority_mode = intersight.module.params['priority_flow_control_mode']
212 intersight.api_body['PriorityFlowControlMode'] = priority_mode
213
214 # Set receive and send direction based on priority flow control mode
215 # When PFC is auto or on, receive/send must be disabled
216 # When PFC is off, use the configured receive/send direction values
217 if priority_mode in ['auto', 'on']:
218 intersight.api_body['ReceiveDirection'] = 'Disabled'
219 intersight.api_body['SendDirection'] = 'Disabled'
220 else:
221 receive_dir = intersight.module.params['receive_direction']
222 intersight.api_body['ReceiveDirection'] = receive_dir.capitalize()
223 send_dir = intersight.module.params['send_direction']
224 intersight.api_body['SendDirection'] = send_dir.capitalize()
225
226 # Configure the policy
227 intersight.configure_policy_or_profile(resource_path=resource_path)
228
229 module.exit_json(**intersight.result)
230
231
232 if __name__ == '__main__':
233 main()