Debian Codegraph @

ansible_collections/cisco/aci/plugins/modules/aci_interface_policy_link_level.py

raw
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 # Copyright: (c) 2019, Vasily Prokopov (@vasilyprokopov)
5 # GNU General Public License v3.0+ (see LICENSE or https://www.gnu.org/licenses/gpl-3.0.txt)
6
7 from __future__ import absolute_import, division, print_function
8
9 __metaclass__ = type
10
11 ANSIBLE_METADATA = {"metadata_version": "1.1", "status": ["preview"], "supported_by": "certified"}
12
13 DOCUMENTATION = r"""
14 ---
15 module: aci_interface_policy_link_level
16 short_description: Manage Link Level interface policies (fabric:HIfPol)
17 description:
18 - The link level interface policy specifies the layer 1 parameters of switch interfaces.
19 options:
20 link_level_policy:
21 description:
22 - The name of the Link Level interface policy.
23 type: str
24 aliases: [ name ]
25 description:
26 description:
27 - The description of the Link Level interface policy.
28 type: str
29 aliases: [ descr ]
30 auto_negotiation:
31 description:
32 - Auto-negotiation enables devices to automatically exchange information over a link about speed and duplex abilities.
33 - The APIC defaults to C(on) when unset during creation.
34 type: bool
35 default: true
36 speed:
37 description:
38 - Determines the interface policy administrative port speed.
39 - The C(auto) option is only supported in APIC version 5.2 or later.
40 - The APIC defaults to C(inherit) when unset during creation.
41 type: str
42 choices: [ 100M, 1G, 10G, 25G, 40G, 50G, 100G, 200G, 400G, auto, inherit ]
43 default: inherit
44 link_debounce_interval:
45 description:
46 - Enables the debounce timer for physical interface ports and sets it for a specified amount of time in milliseconds.
47 - The APIC defaults to C(100) when unset during creation.
48 type: int
49 default: 100
50 forwarding_error_correction:
51 description:
52 - Determines the forwarding error correction (FEC) mode.
53 - The APIC defaults to C(inherit) when unset during creation.
54 type: str
55 choices: [ inherit, kp-fec, cl91-rs-fec, cl74-fc-fec, disable-fec, ieee-rs-fec, cons16-rs-fec ]
56 default: inherit
57 state:
58 description:
59 - Use C(present) or C(absent) for adding or removing.
60 - Use C(query) for listing an object or multiple objects.
61 type: str
62 choices: [ absent, present, query ]
63 default: present
64 extends_documentation_fragment:
65 - cisco.aci.aci
66 - cisco.aci.annotation
67 - cisco.aci.owner
68
69 seealso:
70 - name: APIC Management Information Model reference
71 description: More information about the internal APIC class B(fabric:HIfPol).
72 link: https://developer.cisco.com/docs/apic-mim-ref/
73 author:
74 - Vasily Prokopov (@vasilyprokopov)
75 """
76
77 EXAMPLES = r"""
78 - name: Add a Link Level Policy
79 cisco.aci.aci_interface_policy_link_level:
80 host: apic
81 username: admin
82 password: SomeSecretPassword
83 link_level_policy: link_level_policy_test
84 description: via Ansible
85 auto_negotiation: 'on'
86 speed: 100M
87 link_debounce_interval: 100
88 forwarding_error_correction: cl91-rs-fec
89 state: present
90 delegate_to: localhost
91
92 - name: Remove a Link Level Policy
93 cisco.aci.aci_interface_policy_link_level:
94 host: apic
95 username: admin
96 password: SomeSecretPassword
97 link_level_policy: ansible_test
98 state: absent
99
100 - name: Query a Link Level Policy
101 cisco.aci.aci_interface_policy_link_level:
102 host: apic
103 username: admin
104 password: SomeSecretPassword
105 link_level_policy: link_level_policy_test
106 state: query
107 delegate_to: localhost
108
109 - name: Query all Link Level Policies
110 cisco.aci.aci_interface_policy_link_level:
111 host: apic
112 username: admin
113 password: SomeSecretPassword
114 state: query
115 delegate_to: localhost
116 """
117
118 RETURN = r"""
119 current:
120 description: The existing configuration from the APIC after the module has finished
121 returned: success
122 type: list
123 sample:
124 [
125 {
126 "fvTenant": {
127 "attributes": {
128 "descr": "Production environment",
129 "dn": "uni/tn-production",
130 "name": "production",
131 "nameAlias": "",
132 "ownerKey": "",
133 "ownerTag": ""
134 }
135 }
136 }
137 ]
138 error:
139 description: The error information as returned from the APIC
140 returned: failure
141 type: dict
142 sample:
143 {
144 "code": "122",
145 "text": "unknown managed object class foo"
146 }
147 raw:
148 description: The raw output returned by the APIC REST API (xml or json)
149 returned: parse error
150 type: str
151 sample: '<?xml version="1.0" encoding="UTF-8"?><imdata totalCount="1"><error code="122" text="unknown managed object class foo"/></imdata>'
152 sent:
153 description: The actual/minimal configuration pushed to the APIC
154 returned: info
155 type: list
156 sample:
157 {
158 "fvTenant": {
159 "attributes": {
160 "descr": "Production environment"
161 }
162 }
163 }
164 previous:
165 description: The original configuration from the APIC before the module has started
166 returned: info
167 type: list
168 sample:
169 [
170 {
171 "fvTenant": {
172 "attributes": {
173 "descr": "Production",
174 "dn": "uni/tn-production",
175 "name": "production",
176 "nameAlias": "",
177 "ownerKey": "",
178 "ownerTag": ""
179 }
180 }
181 }
182 ]
183 proposed:
184 description: The assembled configuration from the user-provided parameters
185 returned: info
186 type: dict
187 sample:
188 {
189 "fvTenant": {
190 "attributes": {
191 "descr": "Production environment",
192 "name": "production"
193 }
194 }
195 }
196 filter_string:
197 description: The filter string used for the request
198 returned: failure or debug
199 type: str
200 sample: ?rsp-prop-include=config-only
201 method:
202 description: The HTTP method used for the request to the APIC
203 returned: failure or debug
204 type: str
205 sample: POST
206 response:
207 description: The HTTP response from the APIC
208 returned: failure or debug
209 type: str
210 sample: OK (30 bytes)
211 status:
212 description: The HTTP status from the APIC
213 returned: failure or debug
214 type: int
215 sample: 200
216 url:
217 description: The HTTP url used for the request to the APIC
218 returned: failure or debug
219 type: str
220 sample: https://10.11.12.13/api/mo/uni/tn-production.json
221 """
222
223 from ansible.module_utils.basic import AnsibleModule
224 from ansible_collections.cisco.aci.plugins.module_utils.aci import ACIModule, aci_argument_spec, aci_annotation_spec, aci_owner_spec
225
226
227 def main():
228 argument_spec = aci_argument_spec()
229 argument_spec.update(aci_annotation_spec())
230 argument_spec.update(aci_owner_spec())
231 argument_spec.update(
232 link_level_policy=dict(type="str", aliases=["name"]),
233 description=dict(type="str", aliases=["descr"]),
234 auto_negotiation=dict(type="bool", default="true"),
235 speed=dict(type="str", default="inherit", choices=["100M", "1G", "10G", "25G", "40G", "50G", "100G", "200G", "400G", "auto", "inherit"]),
236 link_debounce_interval=dict(type="int", default="100"),
237 forwarding_error_correction=dict(
238 type="str", default="inherit", choices=["inherit", "kp-fec", "cl91-rs-fec", "cl74-fc-fec", "disable-fec", "ieee-rs-fec", "cons16-rs-fec"]
239 ),
240 state=dict(type="str", default="present", choices=["absent", "present", "query"]),
241 )
242
243 module = AnsibleModule(
244 argument_spec=argument_spec,
245 supports_check_mode=True,
246 required_if=[
247 ["state", "absent", ["link_level_policy"]],
248 ["state", "present", ["link_level_policy"]],
249 ],
250 )
251
252 aci = ACIModule(module)
253
254 link_level_policy = module.params["link_level_policy"]
255 description = module.params["description"]
256 auto_negotiation = aci.boolean(module.params["auto_negotiation"], "on", "off")
257 speed = module.params["speed"]
258 link_debounce_interval = module.params["link_debounce_interval"]
259 if link_debounce_interval is not None and link_debounce_interval not in range(0, 5001):
260 module.fail_json(msg='The "link_debounce_interval" must be a value between 0 and 5000')
261 forwarding_error_correction = module.params["forwarding_error_correction"]
262 state = module.params["state"]
263
264 aci.construct_url(
265 root_class=dict(
266 aci_class="fabricHIfPol",
267 aci_rn="infra/hintfpol-{0}".format(link_level_policy),
268 module_object=link_level_policy,
269 target_filter={"name": link_level_policy},
270 ),
271 )
272
273 aci.get_existing()
274
275 if state == "present":
276 aci.payload(
277 aci_class="fabricHIfPol",
278 class_config=dict(
279 name=link_level_policy,
280 descr=description,
281 autoNeg=auto_negotiation,
282 speed=speed,
283 linkDebounce=link_debounce_interval,
284 fecMode=forwarding_error_correction,
285 ),
286 )
287
288 aci.get_diff(aci_class="fabricHIfPol")
289
290 aci.post_config()
291
292 elif state == "absent":
293 aci.delete_config()
294
295 aci.exit_json()
296
297
298 if __name__ == "__main__":
299 main()