Debian Codegraph @

ansible_collections/cisco/aci/plugins/modules/aci_l3out_dhcp_relay_label.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": "community"}
12
13 DOCUMENTATION = r"""
14 ---
15 module: aci_l3out_dhcp_relay_label
16 short_description: Manage Layer 3 Outside (L3Out) DHCP Relay Label (dhcp:Lbl)
17 description:
18 - Manage DHCP Relay Labels for L3Out Logical Interface Profiles on Cisco ACI fabrics.
19 - A DHCP Relay Label contains the name of an existing DHCP Relay Policy for the label,
20 the scope, and a DHCP Option Policy.
21 options:
22 tenant:
23 description:
24 - The name of an existing tenant.
25 type: str
26 aliases: [ tenant_name ]
27 l3out:
28 description:
29 - The name of an existing L3Out.
30 type: str
31 aliases: [ l3out_name ]
32 node_profile:
33 description:
34 - The name of an existing node profile.
35 type: str
36 aliases: [ node_profile_name, logical_node ]
37 interface_profile:
38 description:
39 - The name of an existing interface profile.
40 type: str
41 aliases: [ interface_profile_name, logical_interface ]
42 dhcp_relay_label:
43 description:
44 - The name/label of an existing DHCP Relay Policy.
45 type: str
46 aliases: [ name, relay_policy ]
47 scope:
48 description:
49 - The scope is the owner of the relay server.
50 - The APIC defaults to C(infra) when unset during creation.
51 type: str
52 choices: [ infra, tenant ]
53 aliases: [ owner ]
54 dhcp_option_policy:
55 description:
56 - The name of an existing DHCP Option Policy to be associated with the DCHP Relay Policy.
57 - The DHCP option policy supplies DHCP clients with configuration parameters
58 such as domain, nameserver, and subnet router addresses.
59 - Passing an empty string will delete the current linked DHCP Option Policy.
60 However, this will associate the DHCP Relay Label to the default DHCP Option Policy
61 from the common Tenant.
62 type: str
63 aliases: [ dhcp_option_policy_name ]
64 description:
65 description:
66 - The description of the DHCP Relay Label.
67 type: str
68 aliases: [ descr ]
69 state:
70 description:
71 - Use C(present) or C(absent) for adding or removing.
72 - Use C(query) for listing an object or multiple objects.
73 type: str
74 choices: [ absent, present, query ]
75 default: present
76 extends_documentation_fragment:
77 - cisco.aci.aci
78 - cisco.aci.annotation
79 - cisco.aci.owner
80
81 notes:
82 - The C(tenant), C(l3out), C(node_profile), C(interface_profile) and C(relay_policy) must exist before using this module in your playbook.
83 The M(cisco.aci.aci_tenant), M(cisco.aci.aci_l3out), M(cisco.aci.aci_l3out_logical_node_profile), M(cisco.aci.aci_l3out_logical_interface_profile)
84 and M(cisco.aci.aci_dhcp_relay) can be used for this.
85 - If C(dhcp_option_policy) is used, it must exist before using this module in your playbook.
86 The M(cisco.aci.aci_dhcp_option_policy) can be used for this.
87 seealso:
88 - module: cisco.aci.aci_tenant
89 - module: cisco.aci.aci_l3out
90 - module: cisco.aci.aci_l3out_logical_node_profile
91 - module: cisco.aci.aci_l3out_logical_interface_profile
92 - module: cisco.aci.aci_dhcp_relay
93 - module: cisco.aci.aci_dhcp_option_policy
94 - name: APIC Management Information Model reference
95 description: More information about the internal APIC classes
96 link: https://developer.cisco.com/docs/apic-mim-ref/
97 author:
98 - Gaspard Micol (@gmicol)
99 """
100
101 EXAMPLES = r"""
102 - name: Add a new L3Out DHCP Relay Label
103 cisco.aci.aci_l3out_eigrp_interface_profile:
104 host: apic
105 username: admin
106 password: SomeSecretPassword
107 tenant: my_tenant
108 l3out: my_l3out
109 node_profile: my_node_profile
110 interface_profile: my_interface_profile
111 dhcp_relay_label: my_dhcp_relay_label
112 scope: tenant
113 dhcp_option_policy: my_dhcp_option_policy
114 state: present
115 delegate_to: localhost
116
117 - name: Delete an L3Out DHCP Relay Label
118 cisco.aci.aci_l3out_eigrp_interface_profile:
119 host: apic
120 username: admin
121 password: SomeSecretPassword
122 tenant: my_tenant
123 l3out: my_l3out
124 node_profile: my_node_profile
125 interface_profile: my_interface_profile
126 dhcp_relay_label: my_dhcp_relay_label
127 state: absent
128 delegate_to: localhost
129
130 - name: Query an L3Out DHCP Relay Label
131 cisco.aci.aci_l3out_eigrp_interface_profile:
132 host: apic
133 username: admin
134 password: SomeSecretPassword
135 tenant: my_tenant
136 l3out: my_l3out
137 node_profile: my_node_profile
138 interface_profile: my_interface_profile
139 dhcp_relay_label: my_dhcp_relay_label
140 state: query
141 delegate_to: localhost
142 register: query_result
143 """
144
145 RETURN = r"""
146 current:
147 description: The existing configuration from the APIC after the module has finished
148 returned: success
149 type: list
150 sample:
151 [
152 {
153 "fvTenant": {
154 "attributes": {
155 "descr": "Production environment",
156 "dn": "uni/tn-production",
157 "name": "production",
158 "nameAlias": "",
159 "ownerKey": "",
160 "ownerTag": ""
161 }
162 }
163 }
164 ]
165 error:
166 description: The error information as returned from the APIC
167 returned: failure
168 type: dict
169 sample:
170 {
171 "code": "122",
172 "text": "unknown managed object class foo"
173 }
174 raw:
175 description: The raw output returned by the APIC REST API (xml or json)
176 returned: parse error
177 type: str
178 sample: '<?xml version="1.0" encoding="UTF-8"?><imdata totalCount="1"><error code="122" text="unknown managed object class foo"/></imdata>'
179 sent:
180 description: The actual/minimal configuration pushed to the APIC
181 returned: info
182 type: list
183 sample:
184 {
185 "fvTenant": {
186 "attributes": {
187 "descr": "Production environment"
188 }
189 }
190 }
191 previous:
192 description: The original configuration from the APIC before the module has started
193 returned: info
194 type: list
195 sample:
196 [
197 {
198 "fvTenant": {
199 "attributes": {
200 "descr": "Production",
201 "dn": "uni/tn-production",
202 "name": "production",
203 "nameAlias": "",
204 "ownerKey": "",
205 "ownerTag": ""
206 }
207 }
208 }
209 ]
210 proposed:
211 description: The assembled configuration from the user-provided parameters
212 returned: info
213 type: dict
214 sample:
215 {
216 "fvTenant": {
217 "attributes": {
218 "descr": "Production environment",
219 "name": "production"
220 }
221 }
222 }
223 filter_string:
224 description: The filter string used for the request
225 returned: failure or debug
226 type: str
227 sample: ?rsp-prop-include=config-only
228 method:
229 description: The HTTP method used for the request to the APIC
230 returned: failure or debug
231 type: str
232 sample: POST
233 response:
234 description: The HTTP response from the APIC
235 returned: failure or debug
236 type: str
237 sample: OK (30 bytes)
238 status:
239 description: The HTTP status from the APIC
240 returned: failure or debug
241 type: int
242 sample: 200
243 url:
244 description: The HTTP url used for the request to the APIC
245 returned: failure or debug
246 type: str
247 sample: https://10.11.12.13/api/mo/uni/tn-production.json
248 """
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
255 def main():
256 argument_spec = aci_argument_spec()
257 argument_spec.update(aci_annotation_spec())
258 argument_spec.update(aci_owner_spec())
259 argument_spec.update(
260 tenant=dict(type="str", aliases=["tenant_name"]),
261 l3out=dict(type="str", aliases=["l3out_name"]),
262 node_profile=dict(type="str", aliases=["node_profile_name", "logical_node"]),
263 interface_profile=dict(type="str", aliases=["interface_profile_name", "logical_interface"]),
264 dhcp_relay_label=dict(type="str", aliases=["name", "relay_policy"]),
265 scope=dict(type="str", choices=["infra", "tenant"], aliases=["owner"]),
266 dhcp_option_policy=dict(type="str", aliases=["dhcp_option_policy_name"]),
267 description=dict(type="str", aliases=["descr"]),
268 state=dict(type="str", default="present", choices=["absent", "present", "query"]),
269 )
270
271 module = AnsibleModule(
272 argument_spec=argument_spec,
273 supports_check_mode=True,
274 required_if=[
275 ["state", "absent", ["tenant", "l3out", "node_profile", "interface_profile", "dhcp_relay_label"]],
276 ["state", "present", ["tenant", "l3out", "node_profile", "interface_profile", "dhcp_relay_label"]],
277 ],
278 )
279
280 tenant = module.params.get("tenant")
281 l3out = module.params.get("l3out")
282 node_profile = module.params.get("node_profile")
283 interface_profile = module.params.get("interface_profile")
284 dhcp_relay_label = module.params.get("dhcp_relay_label")
285 scope = module.params.get("scope")
286 dhcp_option_policy = module.params.get("dhcp_option_policy")
287 description = module.params.get("description")
288 state = module.params.get("state")
289
290 aci = ACIModule(module)
291
292 child_classes = ["dhcpRsDhcpOptionPol"]
293
294 aci.construct_url(
295 root_class=dict(
296 aci_class="fvTenant",
297 aci_rn="tn-{0}".format(tenant),
298 module_object=tenant,
299 target_filter={"name": tenant},
300 ),
301 subclass_1=dict(
302 aci_class="l3extOut",
303 aci_rn="out-{0}".format(l3out),
304 module_object=l3out,
305 target_filter={"name": l3out},
306 ),
307 subclass_2=dict(
308 aci_class="l3extLNodeP",
309 aci_rn="lnodep-{0}".format(node_profile),
310 module_object=node_profile,
311 target_filter={"name": node_profile},
312 ),
313 subclass_3=dict(
314 aci_class="l3extLIfP",
315 aci_rn="lifp-[{0}]".format(interface_profile),
316 module_object=interface_profile,
317 target_filter={"name": interface_profile},
318 ),
319 subclass_4=dict(
320 aci_class="dhcpLbl",
321 aci_rn="dhcplbl-[{0}]".format(dhcp_relay_label),
322 module_object=dhcp_relay_label,
323 target_filter={"name": dhcp_relay_label},
324 ),
325 child_classes=child_classes,
326 )
327
328 aci.get_existing()
329
330 if state == "present":
331 child_configs = [dict(dhcpRsDhcpOptionPol=dict(attributes=dict(tnDhcpOptionPolName=dhcp_option_policy)))]
332
333 aci.payload(
334 aci_class="dhcpLbl",
335 class_config=dict(
336 descr=description,
337 name=dhcp_relay_label,
338 owner=scope,
339 ),
340 child_configs=child_configs,
341 )
342
343 aci.get_diff(aci_class="dhcpLbl")
344
345 aci.post_config()
346
347 elif state == "absent":
348 aci.delete_config()
349
350 aci.exit_json()
351
352
353 if __name__ == "__main__":
354 main()