Debian Codegraph @

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

raw
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 # GNU General Public License v3.0+ (see LICENSE or https://www.gnu.org/licenses/gpl-3.0.txt)
5
6 from __future__ import absolute_import, division, print_function
7
8 __metaclass__ = type
9
10 ANSIBLE_METADATA = {"metadata_version": "1.1", "status": ["preview"], "supported_by": "certified"}
11
12 DOCUMENTATION = r"""
13 ---
14 module: aci_tenant_ep_retention_policy
15 short_description: Manage End Point (EP) retention protocol policies (fv:EpRetPol)
16 description:
17 - Manage End Point (EP) retention protocol policies on Cisco ACI fabrics.
18 options:
19 tenant:
20 description:
21 - The name of an existing tenant.
22 type: str
23 aliases: [ tenant_name ]
24 epr_policy:
25 description:
26 - The name of the end point retention policy.
27 type: str
28 aliases: [ epr_name, name ]
29 bounce_age:
30 description:
31 - Bounce entry aging interval in seconds.
32 - Accepted values range between C(150) and C(65535); 0 is used for infinite.
33 - The APIC defaults to C(630) when unset during creation.
34 type: int
35 bounce_trigger:
36 description:
37 - Determines if the bounce entries are installed by RARP Flood or COOP Protocol.
38 - The APIC defaults to C(coop) when unset during creation.
39 type: str
40 choices: [ coop, flood ]
41 hold_interval:
42 description:
43 - Hold interval in seconds.
44 - Accepted values range between C(5) and C(65535).
45 - The APIC defaults to C(300) when unset during creation.
46 type: int
47 local_ep_interval:
48 description:
49 - Local end point aging interval in seconds.
50 - Accepted values range between C(120) and C(65535); 0 is used for infinite.
51 - The APIC defaults to C(900) when unset during creation.
52 type: int
53 remote_ep_interval:
54 description:
55 - Remote end point aging interval in seconds.
56 - Accepted values range between C(120) and C(65535); 0 is used for infinite.
57 - The APIC defaults to C(300) when unset during creation.
58 type: int
59 move_frequency:
60 description:
61 - Move frequency per second.
62 - Accepted values range between C(0) and C(65535); 0 is used for none.
63 - The APIC defaults to C(256) when unset during creation.
64 type: int
65 description:
66 description:
67 - Description for the End point retention policy.
68 type: str
69 aliases: [ descr ]
70 state:
71 description:
72 - Use C(present) or C(absent) for adding or removing.
73 - Use C(query) for listing an object or multiple objects.
74 type: str
75 choices: [ absent, present, query ]
76 default: present
77 name_alias:
78 description:
79 - The alias for the current object. This relates to the nameAlias field in ACI.
80 type: str
81 extends_documentation_fragment:
82 - cisco.aci.aci
83 - cisco.aci.annotation
84 - cisco.aci.owner
85
86 notes:
87 - The C(tenant) used must exist before using this module in your playbook.
88 The M(cisco.aci.aci_tenant) module can be used for this.
89 seealso:
90 - module: cisco.aci.aci_tenant
91 - name: APIC Management Information Model reference
92 description: More information about the internal APIC class B(fv:EpRetPol).
93 link: https://developer.cisco.com/docs/apic-mim-ref/
94 author:
95 - Swetha Chunduri (@schunduri)
96 """
97
98 EXAMPLES = r"""
99 - name: Add a new EPR policy
100 cisco.aci.aci_tenant_ep_retention_policy:
101 host: apic
102 username: admin
103 password: SomeSecretPassword
104 tenant: production
105 epr_policy: EPRPol1
106 bounce_age: 630
107 hold_interval: 300
108 local_ep_interval: 900
109 remote_ep_interval: 300
110 move_frequency: 256
111 description: test
112 state: present
113 delegate_to: localhost
114
115 - name: Remove an EPR policy
116 cisco.aci.aci_tenant_ep_retention_policy:
117 host: apic
118 username: admin
119 password: SomeSecretPassword
120 tenant: production
121 epr_policy: EPRPol1
122 state: absent
123 delegate_to: localhost
124
125 - name: Query an EPR policy
126 cisco.aci.aci_tenant_ep_retention_policy:
127 host: apic
128 username: admin
129 password: SomeSecretPassword
130 tenant: production
131 epr_policy: EPRPol1
132 state: query
133 delegate_to: localhost
134 register: query_result
135
136 - name: Query all EPR policies
137 cisco.aci.aci_tenant_ep_retention_policy:
138 host: apic
139 username: admin
140 password: SomeSecretPassword
141 state: query
142 delegate_to: localhost
143 register: query_result
144 """
145
146 RETURN = r"""
147 current:
148 description: The existing configuration from the APIC after the module has finished
149 returned: success
150 type: list
151 sample:
152 [
153 {
154 "fvTenant": {
155 "attributes": {
156 "descr": "Production environment",
157 "dn": "uni/tn-production",
158 "name": "production",
159 "nameAlias": "",
160 "ownerKey": "",
161 "ownerTag": ""
162 }
163 }
164 }
165 ]
166 error:
167 description: The error information as returned from the APIC
168 returned: failure
169 type: dict
170 sample:
171 {
172 "code": "122",
173 "text": "unknown managed object class foo"
174 }
175 raw:
176 description: The raw output returned by the APIC REST API (xml or json)
177 returned: parse error
178 type: str
179 sample: '<?xml version="1.0" encoding="UTF-8"?><imdata totalCount="1"><error code="122" text="unknown managed object class foo"/></imdata>'
180 sent:
181 description: The actual/minimal configuration pushed to the APIC
182 returned: info
183 type: list
184 sample:
185 {
186 "fvTenant": {
187 "attributes": {
188 "descr": "Production environment"
189 }
190 }
191 }
192 previous:
193 description: The original configuration from the APIC before the module has started
194 returned: info
195 type: list
196 sample:
197 [
198 {
199 "fvTenant": {
200 "attributes": {
201 "descr": "Production",
202 "dn": "uni/tn-production",
203 "name": "production",
204 "nameAlias": "",
205 "ownerKey": "",
206 "ownerTag": ""
207 }
208 }
209 }
210 ]
211 proposed:
212 description: The assembled configuration from the user-provided parameters
213 returned: info
214 type: dict
215 sample:
216 {
217 "fvTenant": {
218 "attributes": {
219 "descr": "Production environment",
220 "name": "production"
221 }
222 }
223 }
224 filter_string:
225 description: The filter string used for the request
226 returned: failure or debug
227 type: str
228 sample: ?rsp-prop-include=config-only
229 method:
230 description: The HTTP method used for the request to the APIC
231 returned: failure or debug
232 type: str
233 sample: POST
234 response:
235 description: The HTTP response from the APIC
236 returned: failure or debug
237 type: str
238 sample: OK (30 bytes)
239 status:
240 description: The HTTP status from the APIC
241 returned: failure or debug
242 type: int
243 sample: 200
244 url:
245 description: The HTTP url used for the request to the APIC
246 returned: failure or debug
247 type: str
248 sample: https://10.11.12.13/api/mo/uni/tn-production.json
249 """
250
251 from ansible.module_utils.basic import AnsibleModule
252 from ansible_collections.cisco.aci.plugins.module_utils.aci import ACIModule, aci_argument_spec, aci_annotation_spec, aci_owner_spec
253
254 BOUNCE_TRIG_MAPPING = dict(
255 coop="protocol",
256 flood="rarp-flood",
257 )
258
259
260 def main():
261 argument_spec = aci_argument_spec()
262 argument_spec.update(aci_annotation_spec())
263 argument_spec.update(aci_owner_spec())
264 argument_spec.update(
265 tenant=dict(type="str", aliases=["tenant_name"]), # Not required for querying all objects
266 epr_policy=dict(type="str", aliases=["epr_name", "name"]), # Not required for querying all objects
267 bounce_age=dict(type="int"),
268 bounce_trigger=dict(type="str", choices=["coop", "flood"]),
269 hold_interval=dict(type="int"),
270 local_ep_interval=dict(type="int"),
271 remote_ep_interval=dict(type="int"),
272 description=dict(type="str", aliases=["descr"]),
273 move_frequency=dict(type="int"),
274 state=dict(type="str", default="present", choices=["absent", "present", "query"]),
275 name_alias=dict(type="str"),
276 )
277
278 module = AnsibleModule(
279 argument_spec=argument_spec,
280 supports_check_mode=True,
281 required_if=[
282 ["state", "absent", ["epr_policy", "tenant"]],
283 ["state", "present", ["epr_policy", "tenant"]],
284 ],
285 )
286
287 epr_policy = module.params.get("epr_policy")
288 bounce_age = module.params.get("bounce_age")
289 if bounce_age is not None and bounce_age != 0 and bounce_age not in range(150, 65536):
290 module.fail_json(msg="The bounce_age must be a value of 0 or between 150 and 65535")
291 if bounce_age == 0:
292 bounce_age = "infinite"
293 bounce_trigger = module.params.get("bounce_trigger")
294 if bounce_trigger is not None:
295 bounce_trigger = BOUNCE_TRIG_MAPPING[bounce_trigger]
296 description = module.params.get("description")
297 hold_interval = module.params.get("hold_interval")
298 if hold_interval is not None and hold_interval not in range(5, 65536):
299 module.fail_json(msg="The hold_interval must be a value between 5 and 65535")
300 local_ep_interval = module.params.get("local_ep_interval")
301 if local_ep_interval is not None and local_ep_interval != 0 and local_ep_interval not in range(120, 65536):
302 module.fail_json(msg="The local_ep_interval must be a value of 0 or between 120 and 65535")
303 if local_ep_interval == 0:
304 local_ep_interval = "infinite"
305 move_frequency = module.params.get("move_frequency")
306 if move_frequency is not None and move_frequency not in range(65536):
307 module.fail_json(msg="The move_frequency must be a value between 0 and 65535")
308 if move_frequency == 0:
309 move_frequency = "none"
310 remote_ep_interval = module.params.get("remote_ep_interval")
311 if remote_ep_interval is not None and remote_ep_interval != 0 and remote_ep_interval not in range(120, 65536):
312 module.fail_json(msg="The remote_ep_interval must be a value of 0 or between 120 and 65535")
313 if remote_ep_interval == 0:
314 remote_ep_interval = "infinite"
315 state = module.params.get("state")
316 tenant = module.params.get("tenant")
317 name_alias = module.params.get("name_alias")
318
319 aci = ACIModule(module)
320 aci.construct_url(
321 root_class=dict(
322 aci_class="fvTenant",
323 aci_rn="tn-{0}".format(tenant),
324 module_object=tenant,
325 target_filter={"name": tenant},
326 ),
327 subclass_1=dict(
328 aci_class="fvEpRetPol",
329 aci_rn="epRPol-{0}".format(epr_policy),
330 module_object=epr_policy,
331 target_filter={"name": epr_policy},
332 ),
333 )
334
335 aci.get_existing()
336
337 if state == "present":
338 aci.payload(
339 aci_class="fvEpRetPol",
340 class_config=dict(
341 name=epr_policy,
342 descr=description,
343 bounceAgeIntvl=bounce_age,
344 bounceTrig=bounce_trigger,
345 holdIntvl=hold_interval,
346 localEpAgeIntvl=local_ep_interval,
347 remoteEpAgeIntvl=remote_ep_interval,
348 moveFreq=move_frequency,
349 nameAlias=name_alias,
350 ),
351 )
352
353 aci.get_diff(aci_class="fvEpRetPol")
354
355 aci.post_config()
356
357 elif state == "absent":
358 aci.delete_config()
359
360 aci.exit_json()
361
362
363 if __name__ == "__main__":
364 main()