Debian Codegraph @

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

raw symbols SCIP
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 # Copyright: (c) 2023, Shreyas Srish (@shrsr) <[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": "community"}
12
13 DOCUMENTATION = r"""
14 ---
15 module: aci_l3out_hsrp_secondary_vip
16 short_description: Manage HSRP Secondary Virtual IP of a HSRP group (hsrp:SecVip)
17 description:
18 - Manage HSRP Secondary Virtual IP of a HSRP group on Cisco ACI fabrics.
19 options:
20 tenant:
21 description:
22 - Name of an existing tenant.
23 type: str
24 aliases: [ tenant_name ]
25 l3out:
26 description:
27 - Name of an existing L3Out.
28 type: str
29 aliases: [ l3out_name ]
30 node_profile:
31 description:
32 - Name of the node profile.
33 type: str
34 aliases: [ node_profile_name, logical_node ]
35 interface_profile:
36 description:
37 - Name of an existing interface profile.
38 type: str
39 aliases: [ interface_profile_name, logical_interface ]
40 hsrp_interface_group:
41 description:
42 - Name of an existing HSRP group.
43 type: str
44 aliases: [ name, hsrp_group ]
45 secondary_virtual_ip:
46 description:
47 - The version of the compatibility catalog.
48 type: str
49 aliases: [ vip, secondary_vip ]
50 state:
51 description:
52 - Use C(present) or C(absent) for adding or removing.
53 - Use C(query) for listing an object or multiple objects.
54 type: str
55 choices: [ absent, present, query ]
56 default: present
57 extends_documentation_fragment:
58 - cisco.aci.aci
59 - cisco.aci.annotation
60 - cisco.aci.owner
61
62 notes:
63 - The C(tenant), C(l3out), C(logical_node_profile), C(logical_interface_profile), C(hsrp_interface_profile) and C(hsrp_group) must exist before using
64 this module in your playbook. The M(cisco.aci.aci_tenant), M(cisco.aci.aci_l3out), M(cisco.aci.aci_l3out_logical_node_profile),
65 M(cisco.aci.aci_l3out_logical_interface_profile), M(cisco.aci.aci_l3out_hsrp_interface_profile) and M(cisco.aci.aci_l3out_hsrp_group) can be used for
66 this.
67 seealso:
68 - module: cisco.aci.aci_tenant
69 - module: cisco.aci.aci_l3out
70 - module: cisco.aci.aci_l3out_logical_node_profile
71 - module: cisco.aci.aci_l3out_logical_interface_profile
72 - module: cisco.aci.aci_l3out_hsrp_interface_profile
73 - module: cisco.aci.aci_l3out_hsrp_group
74 - name: APIC Management Information Model reference
75 description: More information about the internal APIC class B(hsrp:SecVip).
76 link: https://developer.cisco.com/docs/apic-mim-ref/
77 author:
78 - Shreyas Srish (@shrsr)
79 """
80
81 EXAMPLES = r"""
82 - name: Add a HSRP secondary virtual ip
83 cisco.aci.aci_l3out_hsrp_secondary_vip:
84 host: apic
85 username: admin
86 password: SomeSecretPassword
87 tenant: my_tenant
88 l3out: my_l3out
89 node_profile: my_node_profile
90 interface_profile: my_interface_profile
91 hsrp_group: my_hsrp_group
92 secondary_virtual_ip: 191.1.1.1
93 state: present
94 delegate_to: localhost
95
96 - name: Delete a HSRP secondary virtual ip
97 cisco.aci.aci_l3out_hsrp_secondary_vip:
98 host: apic
99 username: admin
100 password: SomeSecretPassword
101 tenant: my_tenant
102 l3out: my_l3out
103 node_profile: my_node_profile
104 interface_profile: my_interface_profile
105 hsrp_group: my_hsrp_interface_group
106 secondary_virtual_ip: 191.1.1.1
107 state: absent
108 delegate_to: localhost
109
110 - name: Query a HSRP secondary virtual ip
111 cisco.aci.aci_l3out_hsrp_secondary_vip:
112 host: apic
113 username: admin
114 password: SomeSecretPassword
115 tenant: my_tenant
116 l3out: my_l3out
117 node_profile: my_node_profile
118 interface_profile: my_interface_profile
119 hsrp_group: my_hsrp_group
120 secondary_virtual_ip: 191.1.1.1
121 state: query
122 delegate_to: localhost
123 register: query_result
124
125 - name: Query all HSRP secondary virtual ips
126 cisco.aci.aci_l3out_hsrp_secondary_vip:
127 host: apic
128 username: admin
129 password: SomeSecretPassword
130 tenant: my_tenant
131 l3out: my_l3out
132 node_profile: my_node_profile
133 interface_profile: my_interface_profile
134 hsrp_group: my_hsrp_group
135 state: query
136 delegate_to: localhost
137 register: query_result
138 """
139
140 RETURN = r"""
141 current:
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 ]
160 error:
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 }
169 raw:
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>'
174 sent:
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 }
186 previous:
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 ]
205 proposed:
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 }
218 filter_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
223 method:
224 description: The HTTP method used for the request to the APIC
225 returned: failure or debug
226 type: str
227 sample: POST
228 response:
229 description: The HTTP response from the APIC
230 returned: failure or debug
231 type: str
232 sample: OK (30 bytes)
233 status:
234 description: The HTTP status from the APIC
235 returned: failure or debug
236 type: int
237 sample: 200
238 url:
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
245
246 from ansible.module_utils.basic import AnsibleModule
247 from ansible_collections.cisco.aci.plugins.module_utils.aci import ACIModule, aci_argument_spec, aci_annotation_spec, aci_owner_spec
248
249
250 def main():
251 argument_spec = aci_argument_spec()
252 argument_spec.update(aci_annotation_spec())
253 argument_spec.update(aci_owner_spec())
254 argument_spec.update(
255 tenant=dict(type="str", aliases=["tenant_name"]),
256 l3out=dict(type="str", aliases=["l3out_name"]),
257 node_profile=dict(type="str", aliases=["node_profile_name", "logical_node"]),
258 interface_profile=dict(type="str", aliases=["interface_profile_name", "logical_interface"]),
259 hsrp_interface_group=dict(type="str", aliases=["name", "hsrp_group"]),
260 secondary_virtual_ip=dict(type="str", aliases=["vip", "secondary_vip"]),
261 state=dict(type="str", default="present", choices=["absent", "present", "query"]),
262 )
263
264 module = AnsibleModule(
265 argument_spec=argument_spec,
266 supports_check_mode=True,
267 required_if=[
268 ["state", "absent", ["tenant", "l3out", "node_profile", "interface_profile", "hsrp_interface_group", "secondary_virtual_ip"]],
269 ["state", "present", ["tenant", "l3out", "node_profile", "interface_profile", "hsrp_interface_group", "secondary_virtual_ip"]],
270 ],
271 )
272
273 tenant = module.params.get("tenant")
274 l3out = module.params.get("l3out")
275 node_profile = module.params.get("node_profile")
276 interface_profile = module.params.get("interface_profile")
277 hsrp_interface_group = module.params.get("hsrp_interface_group")
278 secondary_virtual_ip = module.params.get("secondary_virtual_ip")
279 state = module.params.get("state")
280
281 aci = ACIModule(module)
282
283 aci.construct_url(
284 root_class=dict(
285 aci_class="fvTenant",
286 aci_rn="tn-{0}".format(tenant),
287 module_object=tenant,
288 target_filter={"name": tenant},
289 ),
290 subclass_1=dict(
291 aci_class="l3extOut",
292 aci_rn="out-{0}".format(l3out),
293 module_object=l3out,
294 target_filter={"name": l3out},
295 ),
296 subclass_2=dict(
297 aci_class="l3extLNodeP",
298 aci_rn="lnodep-{0}".format(node_profile),
299 module_object=node_profile,
300 target_filter={"name": node_profile},
301 ),
302 subclass_3=dict(
303 aci_class="l3extLIfP",
304 aci_rn="lifp-[{0}]".format(interface_profile),
305 module_object=interface_profile,
306 target_filter={"name": interface_profile},
307 ),
308 subclass_4=dict(
309 aci_class="hsrpIfP",
310 aci_rn="hsrpIfP",
311 module_object=interface_profile,
312 target_filter={"name": interface_profile},
313 ),
314 subclass_5=dict(
315 aci_class="hsrpGroupP",
316 aci_rn="hsrpGroupP-{0}".format(hsrp_interface_group),
317 module_object=hsrp_interface_group,
318 target_filter={"name": hsrp_interface_group},
319 ),
320 subclass_6=dict(
321 aci_class="hsrpSecVip",
322 aci_rn="hsrpSecVip-[{0}]".format(secondary_virtual_ip),
323 module_object=secondary_virtual_ip,
324 target_filter={"ip": secondary_virtual_ip},
325 ),
326 )
327
328 aci.get_existing()
329
330 if state == "present":
331 aci.payload(aci_class="hsrpSecVip", class_config=dict(ip=secondary_virtual_ip))
332
333 aci.get_diff(aci_class="hsrpSecVip")
334
335 aci.post_config()
336
337 elif state == "absent":
338 aci.delete_config()
339
340 aci.exit_json()
341
342
343 if __name__ == "__main__":
344 main()