ansible  2.9.27
About: Ansible is an IT Configuration Management, Deployment \
About: Ansible (2.x) is an IT Configuration Management, Deployment & Orchestration tool.
ansible download page.
  Fossies Dox: ansible-2.9.27.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

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