Debian Codegraph @

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

raw
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 # Copyright: (c) 2023, Gaspard Micol (@gmicol) <[email protected]>
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_mcp
16 short_description: Manage MCP interface policies (mcp:IfPol)
17 description:
18 - Manage MCP interface policies on Cisco ACI fabrics.
19 options:
20 mcp:
21 description:
22 - The name of the MCP interface.
23 type: str
24 aliases: [ mcp_interface, name ]
25 description:
26 description:
27 - The description of the MCP interface.
28 type: str
29 aliases: [ descr ]
30 admin_state:
31 description:
32 - Enable or disable admin state.
33 - The APIC defaults to C(true) when unset during creation.
34 type: bool
35 mcp_mode:
36 description:
37 - Instance MCP mode
38 - The APIC defaults to C(non_strict) when unset during creation.
39 type: str
40 choices: [ non_strict, strict ]
41 grace_period:
42 description:
43 - For strict mode, grace period timeout in sec during which early loop detection takes place.
44 type: int
45 aliases: [ gracePeriod ]
46 grace_period_millisec:
47 description:
48 - For strict mode, grace period timeout in millisec during which early loop detection takes place
49 type: int
50 aliases: [ grace_period_msec, gracePeriodMsec ]
51 init_delay_time:
52 description:
53 - For strict mode, delay time in seconds for mcp to wait before sending BPDUs.
54 - This gives time for STP on the external network to converge.
55 type: int
56 aliases: [ strict_init_delay_time, strictInitDelayTime ]
57 tx_frequence:
58 description:
59 - For strict mode, transmission frequency of MCP packets until grace period on each L2 interface in seconds.
60 type: int
61 aliases: [ strict_tx_freq, strictTxFreq ]
62 tx_frequence_millisec:
63 description:
64 - For strict mode, transmission frequency of MCP packets until grace period on each L2 interface in milliseconds
65 type: int
66 aliases: [strict_tx_freq_msec, strictTxFreqMsec ]
67 state:
68 description:
69 - Use C(present) or C(absent) for adding or removing.
70 - Use C(query) for listing an object or multiple objects.
71 type: str
72 choices: [ absent, present, query ]
73 default: present
74 name_alias:
75 description:
76 - The alias for the current object. This relates to the nameAlias field in ACI.
77 type: str
78 extends_documentation_fragment:
79 - cisco.aci.aci
80 - cisco.aci.annotation
81 - cisco.aci.owner
82
83 seealso:
84 - name: APIC Management Information Model reference
85 description: More information about the internal APIC class B(mcp:IfPol).
86 link: https://developer.cisco.com/docs/apic-mim-ref/
87 author:
88 - Dag Wieers (@dagwieers)
89 - Gaspard Micol (@gmicol)
90 """
91
92 EXAMPLES = r"""
93 - name: Create a MCP interface policy
94 cisco.aci.aci_interface_policy_mcp:
95 host: apic
96 username: admin
97 password: SomeSecretPassword
98 mcp: MCP_OFF
99 admin_state: false
100 state: present
101 delegate_to: localhost
102
103 - name: Delete a MCP interface policy
104 cisco.aci.aci_interface_policy_mcp:
105 host: apic
106 username: admin
107 password: SomeSecretPassword
108 mcp: MCP_OFF
109 state: absent
110 delegate_to: localhost
111
112 - name: Query all MCP interface policies
113 cisco.aci.aci_interface_policy_mcp:
114 host: apic
115 username: admin
116 password: SomeSecretPassword
117 state: query
118 delegate_to: localhost
119 register: query_result
120
121 - name: Query a specific MCP interface policy
122 cisco.aci.aci_interface_policy_mcp:
123 host: apic
124 username: admin
125 password: SomeSecretPassword
126 mcp: MCP_OFF
127 state: query
128 delegate_to: localhost
129 register: query_result
130 """
131
132 RETURN = r"""
133 current:
134 description: The existing configuration from the APIC after the module has finished
135 returned: success
136 type: list
137 sample:
138 [
139 {
140 "fvTenant": {
141 "attributes": {
142 "descr": "Production environment",
143 "dn": "uni/tn-production",
144 "name": "production",
145 "nameAlias": "",
146 "ownerKey": "",
147 "ownerTag": ""
148 }
149 }
150 }
151 ]
152 error:
153 description: The error information as returned from the APIC
154 returned: failure
155 type: dict
156 sample:
157 {
158 "code": "122",
159 "text": "unknown managed object class foo"
160 }
161 raw:
162 description: The raw output returned by the APIC REST API (xml or json)
163 returned: parse error
164 type: str
165 sample: '<?xml version="1.0" encoding="UTF-8"?><imdata totalCount="1"><error code="122" text="unknown managed object class foo"/></imdata>'
166 sent:
167 description: The actual/minimal configuration pushed to the APIC
168 returned: info
169 type: list
170 sample:
171 {
172 "fvTenant": {
173 "attributes": {
174 "descr": "Production environment"
175 }
176 }
177 }
178 previous:
179 description: The original configuration from the APIC before the module has started
180 returned: info
181 type: list
182 sample:
183 [
184 {
185 "fvTenant": {
186 "attributes": {
187 "descr": "Production",
188 "dn": "uni/tn-production",
189 "name": "production",
190 "nameAlias": "",
191 "ownerKey": "",
192 "ownerTag": ""
193 }
194 }
195 }
196 ]
197 proposed:
198 description: The assembled configuration from the user-provided parameters
199 returned: info
200 type: dict
201 sample:
202 {
203 "fvTenant": {
204 "attributes": {
205 "descr": "Production environment",
206 "name": "production"
207 }
208 }
209 }
210 filter_string:
211 description: The filter string used for the request
212 returned: failure or debug
213 type: str
214 sample: ?rsp-prop-include=config-only
215 method:
216 description: The HTTP method used for the request to the APIC
217 returned: failure or debug
218 type: str
219 sample: POST
220 response:
221 description: The HTTP response from the APIC
222 returned: failure or debug
223 type: str
224 sample: OK (30 bytes)
225 status:
226 description: The HTTP status from the APIC
227 returned: failure or debug
228 type: int
229 sample: 200
230 url:
231 description: The HTTP url used for the request to the APIC
232 returned: failure or debug
233 type: str
234 sample: https://10.11.12.13/api/mo/uni/tn-production.json
235 """
236
237 from ansible.module_utils.basic import AnsibleModule
238 from ansible_collections.cisco.aci.plugins.module_utils.aci import ACIModule, aci_argument_spec, aci_annotation_spec, aci_owner_spec
239
240
241 MATCH_MCP_MODE_MAPPING = {"non_strict": "off", "strict": "on"}
242
243
244 def main():
245 argument_spec = aci_argument_spec()
246 argument_spec.update(aci_annotation_spec())
247 argument_spec.update(aci_owner_spec())
248 argument_spec.update(
249 mcp=dict(type="str", aliases=["mcp_interface", "name"]), # Not required for querying all objects
250 description=dict(type="str", aliases=["descr"]),
251 admin_state=dict(type="bool"),
252 mcp_mode=dict(type="str", choices=list(MATCH_MCP_MODE_MAPPING.keys())),
253 grace_period=dict(type="int", aliases=["gracePeriod"]),
254 grace_period_millisec=dict(type="int", aliases=["grace_period_msec", "gracePeriodMsec"]),
255 init_delay_time=dict(type="int", aliases=["strict_init_delay_time", "strictInitDelayTime"]),
256 tx_frequence=dict(type="int", aliases=["strict_tx_freq", "strictTxFreq"]),
257 tx_frequence_millisec=dict(type="int", aliases=["strict_tx_freq_msec", "strictTxFreqMsec"]),
258 state=dict(type="str", default="present", choices=["absent", "present", "query"]),
259 name_alias=dict(type="str"),
260 )
261
262 module = AnsibleModule(
263 argument_spec=argument_spec,
264 supports_check_mode=True,
265 required_if=[
266 ["state", "absent", ["mcp"]],
267 ["state", "present", ["mcp"]],
268 ],
269 )
270
271 aci = ACIModule(module)
272
273 mcp = module.params.get("mcp")
274 description = module.params.get("description")
275 admin_state = aci.boolean(module.params.get("admin_state"), "enabled", "disabled")
276 mcp_mode = MATCH_MCP_MODE_MAPPING.get(module.params.get("mcp_mode"))
277 grace_period = module.params.get("grace_period")
278 grace_period_millisec = module.params.get("grace_period_millisec")
279 init_delay_time = module.params.get("init_delay_time")
280 tx_frequence = module.params.get("tx_frequence")
281 tx_frequence_millisec = module.params.get("tx_frequence_millisec")
282 state = module.params.get("state")
283 name_alias = module.params.get("name_alias")
284
285 aci.construct_url(
286 root_class=dict(
287 aci_class="mcpIfPol",
288 aci_rn="infra/mcpIfP-{0}".format(mcp),
289 module_object=mcp,
290 target_filter={"name": mcp},
291 ),
292 )
293
294 aci.get_existing()
295
296 if state == "present":
297 aci.payload(
298 aci_class="mcpIfPol",
299 class_config=dict(
300 name=mcp,
301 descr=description,
302 adminSt=admin_state,
303 mcpMode=mcp_mode,
304 gracePeriod=grace_period,
305 gracePeriodMsec=grace_period_millisec,
306 strictInitDelayTime=init_delay_time,
307 strictTxFreq=tx_frequence,
308 strictTxFreqMsec=tx_frequence_millisec,
309 nameAlias=name_alias,
310 ),
311 )
312
313 aci.get_diff(aci_class="mcpIfPol")
314
315 aci.post_config()
316
317 elif state == "absent":
318 aci.delete_config()
319
320 aci.exit_json()
321
322
323 if __name__ == "__main__":
324 main()