Debian Codegraph @

ansible_collections/cisco/intersight/plugins/modules/intersight_adapter_config_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_adapter_config_policy
16 short_description: Adapter Configuration Policy for Cisco Intersight
17 description:
18 - Manages Adapter Configuration Policy on Cisco Intersight.
19 - This policy allows you to configure adapter settings such as LLDP, FIP, Port Channel, and FEC mode.
20 - For more information see L(Cisco Intersight,https://intersight.com/apidocs).
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 Adapter Configuration 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 Adapter Configuration 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 default: []
54 settings:
55 description:
56 - List of adapter configurations.
57 type: list
58 elements: dict
59 suboptions:
60 slot_id:
61 description:
62 - PCIe slot where the VIC adapter is installed.
63 - Supported values are (1-15) and MLOM.
64 type: str
65 required: true
66 enable_lldp:
67 description:
68 - Status of LLDP protocol on the adapter interfaces.
69 type: bool
70 default: true
71 enable_fip:
72 description:
73 - Status of FIP protocol on the adapter interfaces.
74 type: bool
75 default: true
76 enable_port_channel:
77 description:
78 - Status of Port Channel on the adapter interfaces.
79 - When enabled, two vNICs and two vHBAs are available.
80 - When disabled, four vNICs and four vHBAs are available.
81 - Disabling port channel reboots the server.
82 - Supported only for Cisco VIC 1455/1457 adapters.
83 type: bool
84 default: true
85 dce_interface_1_fec_mode:
86 description:
87 - Forward Error Correction (FEC) mode setting for DCE interface 1 (Interface ID 0).
88 - Supported only for Cisco VIC 14xx adapters.
89 - FEC mode 'cl74' is unsupported for Cisco VIC 1495/1497.
90 type: str
91 choices: ['cl91', 'cl74', 'off']
92 default: cl91
93 dce_interface_2_fec_mode:
94 description:
95 - Forward Error Correction (FEC) mode setting for DCE interface 2 (Interface ID 1).
96 type: str
97 choices: ['cl91', 'cl74', 'off']
98 default: cl91
99 dce_interface_3_fec_mode:
100 description:
101 - Forward Error Correction (FEC) mode setting for DCE interface 3 (Interface ID 2).
102 type: str
103 choices: ['cl91', 'cl74', 'off']
104 default: cl91
105 dce_interface_4_fec_mode:
106 description:
107 - Forward Error Correction (FEC) mode setting for DCE interface 4 (Interface ID 3).
108 type: str
109 choices: ['cl91', 'cl74', 'off']
110 default: cl91
111 author:
112 - Ron Gershburg (@rgershbu)
113 '''
114
115 EXAMPLES = r'''
116 - name: Create Adapter Config Policy
117 cisco.intersight.intersight_adapter_config_policy:
118 api_private_key: "{{ api_private_key }}"
119 api_key_id: "{{ api_key_id }}"
120 organization: "default"
121 name: "adapter-config-policy"
122 description: "Policy for VIC 1455"
123 settings:
124 - slot_id: "2"
125 enable_lldp: true
126 enable_fip: true
127 enable_port_channel: true
128 dce_interface_1_fec_mode: "cl91"
129 dce_interface_2_fec_mode: "cl91"
130 dce_interface_3_fec_mode: "cl91"
131 dce_interface_4_fec_mode: "off"
132 state: present
133
134 - name: Delete Adapter Config Policy
135 cisco.intersight.intersight_adapter_config_policy:
136 api_private_key: "{{ api_private_key }}"
137 api_key_id: "{{ api_key_id }}"
138 organization: "default"
139 name: "adapter-config-policy"
140 state: absent
141 '''
142
143 RETURN = r'''
144 api_response:
145 description: The API response output returned by the specified resource.
146 returned: always
147 type: dict
148 sample: {
149 "Name": "adapter-config-policy",
150 "ObjectType": "adapter.ConfigPolicy",
151 "Settings": [
152 {
153 "SlotId": "2",
154 "EthSettings": {
155 "LldpEnabled": true
156 },
157 "FcSettings": {
158 "FipEnabled": true
159 },
160 "PortChannelSettings": {
161 "Enabled": true
162 },
163 "DceInterfaceSettings": [
164 {
165 "FecMode": "cl91",
166 "InterfaceId": 0
167 }
168 ]
169 }
170 ]
171 }
172 '''
173
174 from ansible.module_utils.basic import AnsibleModule
175 from ansible_collections.cisco.intersight.plugins.module_utils.intersight import IntersightModule, intersight_argument_spec
176
177
178 def format_fec_mode(mode):
179 """
180 Format FEC mode string for API.
181 'off' should be 'Off'.
182 """
183 if mode and mode.lower() == 'off':
184 return 'Off'
185 return mode
186
187
188 def build_settings_config(settings):
189 """
190 Build Settings configuration for API body.
191 """
192 settings_list = []
193 for setting in settings:
194 config = {
195 'ObjectType': 'adapter.AdapterConfig',
196 'SlotId': setting['slot_id'],
197 'EthSettings': {
198 'LldpEnabled': setting['enable_lldp'],
199 'ObjectType': 'adapter.EthSettings'
200 },
201 'FcSettings': {
202 'FipEnabled': setting['enable_fip'],
203 'ObjectType': 'adapter.FcSettings'
204 },
205 'PortChannelSettings': {
206 'Enabled': setting['enable_port_channel'],
207 'ObjectType': 'adapter.PortChannelSettings'
208 },
209 'PhysicalNicModeSettings': {
210 'PhyNicEnabled': False,
211 'ObjectType': 'adapter.PhysicalNicModeSettings'
212 }
213 }
214
215 dce_settings = []
216 # Interface 1
217 dce_settings.append({
218 'ObjectType': 'adapter.DceInterfaceSettings',
219 'InterfaceId': 0,
220 'FecMode': format_fec_mode(setting['dce_interface_1_fec_mode'])
221 })
222 # Interface 2
223 dce_settings.append({
224 'ObjectType': 'adapter.DceInterfaceSettings',
225 'InterfaceId': 1,
226 'FecMode': format_fec_mode(setting['dce_interface_2_fec_mode'])
227 })
228 # Interface 3
229 dce_settings.append({
230 'ObjectType': 'adapter.DceInterfaceSettings',
231 'InterfaceId': 2,
232 'FecMode': format_fec_mode(setting['dce_interface_3_fec_mode'])
233 })
234 # Interface 4
235 dce_settings.append({
236 'ObjectType': 'adapter.DceInterfaceSettings',
237 'InterfaceId': 3,
238 'FecMode': format_fec_mode(setting['dce_interface_4_fec_mode'])
239 })
240
241 config['DceInterfaceSettings'] = dce_settings
242 settings_list.append(config)
243
244 return settings_list
245
246
247 def main():
248 argument_spec = intersight_argument_spec.copy()
249 argument_spec.update(
250 state=dict(type='str', choices=['present', 'absent'], default='present'),
251 organization=dict(type='str', default='default'),
252 name=dict(type='str', required=True),
253 description=dict(type='str', aliases=['descr']),
254 tags=dict(type='list', elements='dict', default=[]),
255 settings=dict(
256 type='list',
257 elements='dict',
258 options=dict(
259 slot_id=dict(type='str', required=True),
260 enable_lldp=dict(type='bool', default=True),
261 enable_fip=dict(type='bool', default=True),
262 enable_port_channel=dict(type='bool', default=True),
263 dce_interface_1_fec_mode=dict(type='str', choices=['cl91', 'cl74', 'off'], default='cl91'),
264 dce_interface_2_fec_mode=dict(type='str', choices=['cl91', 'cl74', 'off'], default='cl91'),
265 dce_interface_3_fec_mode=dict(type='str', choices=['cl91', 'cl74', 'off'], default='cl91'),
266 dce_interface_4_fec_mode=dict(type='str', choices=['cl91', 'cl74', 'off'], default='cl91'),
267 )
268 )
269 )
270
271 module = AnsibleModule(
272 argument_spec,
273 supports_check_mode=True,
274 )
275
276 intersight = IntersightModule(module)
277 intersight.result['api_response'] = {}
278 intersight.result['trace_id'] = ''
279
280 intersight.api_body = {
281 'Organization': {
282 'Name': module.params['organization'],
283 },
284 'Name': module.params['name'],
285 'ObjectType': 'adapter.ConfigPolicy'
286 }
287
288 if module.params['state'] == 'present':
289 intersight.set_tags_and_description()
290
291 if module.params.get('settings'):
292 intersight.api_body['Settings'] = build_settings_config(module.params['settings'])
293
294 resource_path = '/adapter/ConfigPolicies'
295 intersight.configure_policy_or_profile(resource_path=resource_path)
296
297 module.exit_json(**intersight.result)
298
299
300 if __name__ == '__main__':
301 main()