Debian Codegraph @

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

raw
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_interface_profile
16 short_description: Manages Layer 3 Outside (L3Out) HSRP interface profile (hsrp:IfP)
17 description:
18 - Manages L3Out HSRP interface profile 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_policy:
41 description:
42 - Name of an existing HSRP interface policy.
43 type: str
44 aliases: [ name, hsrp_policy_name ]
45 version:
46 description:
47 - The version of the compatibility catalog.
48 type: str
49 choices: [ v1, v2 ]
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) and C(logical_interface_profile) must exist before using this module in your playbook.
64 The M(cisco.aci.aci_tenant), M(cisco.aci.aci_l3out), M(cisco.aci.aci_l3out_logical_node_profile) and M(cisco.aci.aci_l3out_logical_interface_profile)
65 can be used for this.
66 - If C(hsrp_policy) is used, it must exist before using this module in your playbook.
67 The M(cisco.aci.aci_interface_policy_hsrp) can be used for this.
68 seealso:
69 - module: cisco.aci.aci_tenant
70 - module: cisco.aci.aci_l3out
71 - module: cisco.aci.aci_l3out_logical_node_profile
72 - module: cisco.aci.aci_l3out_logical_interface_profile
73 - module: cisco.aci.aci_interface_policy_hsrp
74 - name: APIC Management Information Model reference
75 description: More information about the internal APIC class B(hsrp:IfP).
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 new HSRP interface profile
83 cisco.aci.aci_l3out_hsrp_interface_profile:
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_policy: default
92 state: present
93 delegate_to: localhost
94
95 - name: Delete a HSRP interface profile
96 cisco.aci.aci_l3out_hsrp_interface_profile:
97 host: apic
98 username: admin
99 password: SomeSecretPassword
100 tenant: my_tenant
101 l3out: my_l3out
102 node_profile: my_node_profile
103 interface_profile: my_interface_profile
104 hsrp_policy: default
105 state: absent
106 delegate_to: localhost
107
108 - name: Query a HSRP interface profile
109 cisco.aci.aci_l3out_hsrp_interface_profile:
110 host: apic
111 username: admin
112 password: SomeSecretPassword
113 tenant: my_tenant
114 l3out: my_l3out
115 node_profile: my_node_profile
116 interface_profile: my_interface_profile
117 hsrp_policy: default
118 state: query
119 delegate_to: localhost
120 register: query_result
121 """
122
123 RETURN = r"""
124 current:
125 description: The existing configuration from the APIC after the module has finished
126 returned: success
127 type: list
128 sample:
129 [
130 {
131 "fvTenant": {
132 "attributes": {
133 "descr": "Production environment",
134 "dn": "uni/tn-production",
135 "name": "production",
136 "nameAlias": "",
137 "ownerKey": "",
138 "ownerTag": ""
139 }
140 }
141 }
142 ]
143 error:
144 description: The error information as returned from the APIC
145 returned: failure
146 type: dict
147 sample:
148 {
149 "code": "122",
150 "text": "unknown managed object class foo"
151 }
152 raw:
153 description: The raw output returned by the APIC REST API (xml or json)
154 returned: parse error
155 type: str
156 sample: '<?xml version="1.0" encoding="UTF-8"?><imdata totalCount="1"><error code="122" text="unknown managed object class foo"/></imdata>'
157 sent:
158 description: The actual/minimal configuration pushed to the APIC
159 returned: info
160 type: list
161 sample:
162 {
163 "fvTenant": {
164 "attributes": {
165 "descr": "Production environment"
166 }
167 }
168 }
169 previous:
170 description: The original configuration from the APIC before the module has started
171 returned: info
172 type: list
173 sample:
174 [
175 {
176 "fvTenant": {
177 "attributes": {
178 "descr": "Production",
179 "dn": "uni/tn-production",
180 "name": "production",
181 "nameAlias": "",
182 "ownerKey": "",
183 "ownerTag": ""
184 }
185 }
186 }
187 ]
188 proposed:
189 description: The assembled configuration from the user-provided parameters
190 returned: info
191 type: dict
192 sample:
193 {
194 "fvTenant": {
195 "attributes": {
196 "descr": "Production environment",
197 "name": "production"
198 }
199 }
200 }
201 filter_string:
202 description: The filter string used for the request
203 returned: failure or debug
204 type: str
205 sample: ?rsp-prop-include=config-only
206 method:
207 description: The HTTP method used for the request to the APIC
208 returned: failure or debug
209 type: str
210 sample: POST
211 response:
212 description: The HTTP response from the APIC
213 returned: failure or debug
214 type: str
215 sample: OK (30 bytes)
216 status:
217 description: The HTTP status from the APIC
218 returned: failure or debug
219 type: int
220 sample: 200
221 url:
222 description: The HTTP url used for the request to the APIC
223 returned: failure or debug
224 type: str
225 sample: https://10.11.12.13/api/mo/uni/tn-production.json
226 """
227
228
229 from ansible.module_utils.basic import AnsibleModule
230 from ansible_collections.cisco.aci.plugins.module_utils.aci import ACIModule, aci_argument_spec, aci_annotation_spec, aci_owner_spec
231
232
233 def main():
234 argument_spec = aci_argument_spec()
235 argument_spec.update(aci_annotation_spec())
236 argument_spec.update(aci_owner_spec())
237 argument_spec.update(
238 tenant=dict(type="str", aliases=["tenant_name"]),
239 l3out=dict(type="str", aliases=["l3out_name"]),
240 node_profile=dict(type="str", aliases=["node_profile_name", "logical_node"]),
241 interface_profile=dict(type="str", aliases=["interface_profile_name", "logical_interface"]),
242 hsrp_policy=dict(type="str", aliases=["name", "hsrp_policy_name"]),
243 version=dict(type="str", choices=["v1", "v2"]),
244 state=dict(type="str", default="present", choices=["absent", "present", "query"]),
245 )
246
247 module = AnsibleModule(
248 argument_spec=argument_spec,
249 supports_check_mode=True,
250 required_if=[
251 ["state", "absent", ["tenant", "l3out", "node_profile", "interface_profile"]],
252 ["state", "present", ["tenant", "l3out", "node_profile", "interface_profile"]],
253 ],
254 )
255
256 tenant = module.params.get("tenant")
257 l3out = module.params.get("l3out")
258 node_profile = module.params.get("node_profile")
259 interface_profile = module.params.get("interface_profile")
260 hsrp_policy = module.params.get("hsrp_policy")
261 version = module.params.get("version")
262 state = module.params.get("state")
263
264 aci = ACIModule(module)
265
266 aci.construct_url(
267 root_class=dict(
268 aci_class="fvTenant",
269 aci_rn="tn-{0}".format(tenant),
270 module_object=tenant,
271 target_filter={"name": tenant},
272 ),
273 subclass_1=dict(
274 aci_class="l3extOut",
275 aci_rn="out-{0}".format(l3out),
276 module_object=l3out,
277 target_filter={"name": l3out},
278 ),
279 subclass_2=dict(
280 aci_class="l3extLNodeP",
281 aci_rn="lnodep-{0}".format(node_profile),
282 module_object=node_profile,
283 target_filter={"name": node_profile},
284 ),
285 subclass_3=dict(
286 aci_class="l3extLIfP",
287 aci_rn="lifp-[{0}]".format(interface_profile),
288 module_object=interface_profile,
289 target_filter={"name": interface_profile},
290 ),
291 subclass_4=dict(
292 aci_class="hsrpIfP",
293 aci_rn="hsrpIfP",
294 module_object=interface_profile,
295 target_filter={"name": interface_profile},
296 ),
297 child_classes=["hsrpRsIfPol"],
298 )
299
300 aci.get_existing()
301
302 if state == "present":
303 child_configs = []
304 if hsrp_policy is not None:
305 child_configs = [dict(hsrpRsIfPol=dict(attributes=dict(tnHsrpIfPolName=hsrp_policy)))]
306
307 aci.payload(aci_class="hsrpIfP", class_config=dict(version=version), child_configs=child_configs)
308
309 aci.get_diff(aci_class="hsrpIfP")
310
311 aci.post_config()
312
313 elif state == "absent":
314 aci.delete_config()
315
316 aci.exit_json()
317
318
319 if __name__ == "__main__":
320 main()