Debian Codegraph @

ansible_collections/cisco/aci/plugins/modules/aci_bd_to_l3out.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_bd_to_l3out
15 short_description: Bind Bridge Domain to L3 Out (fv:RsBDToOut)
16 description:
17 - Bind Bridge Domain to L3 Out on Cisco ACI fabrics.
18 options:
19 bd:
20 description:
21 - The name of the Bridge Domain.
22 type: str
23 aliases: [ bd_name, bridge_domain ]
24 l3out:
25 description:
26 - The name of the l3out to associate with th Bridge Domain.
27 type: str
28 tenant:
29 description:
30 - The name of the Tenant.
31 type: str
32 aliases: [ tenant_name ]
33 state:
34 description:
35 - Use C(present) or C(absent) for adding or removing.
36 - Use C(query) for listing an object or multiple objects.
37 type: str
38 choices: [ absent, present, query ]
39 default: present
40 extends_documentation_fragment:
41 - cisco.aci.aci
42 - cisco.aci.annotation
43
44 notes:
45 - The C(bd) and C(l3out) parameters should exist before using this module.
46 The M(cisco.aci.aci_bd) and C(aci_l3out) can be used for these.
47 seealso:
48 - module: cisco.aci.aci_bd
49 - module: cisco.aci.aci_l3out
50 - name: APIC Management Information Model reference
51 description: More information about the internal APIC class B(fv:RsBDToOut).
52 link: https://developer.cisco.com/docs/apic-mim-ref/
53 author:
54 - Jacob McGill (@jmcgill298)
55 """
56
57 EXAMPLES = r"""
58 - name: Bind Bridge Domain to L3 Out
59 cisco.aci.aci_bd_to_l3out:
60 host: apic
61 username: admin
62 password: SomeSecretPassword
63 bd: web_servers
64 l3out: prod_l3out
65 tenant: prod
66 state: present
67 delegate_to: localhost
68
69 - name: Unbind Bridge Domain from L3 Out
70 cisco.aci.aci_bd_to_l3out:
71 host: apic
72 username: admin
73 password: SomeSecretPassword
74 bd: web_servers
75 l3out: prod_l3out
76 tenant: prod
77 state: absent
78 delegate_to: localhost
79
80 - name: Query all Bridge Domains bound to L3 Outs
81 cisco.aci.aci_bd_to_l3out:
82 host: apic
83 username: admin
84 password: SomeSecretPassword
85 state: query
86 delegate_to: localhost
87 register: query_result
88
89 - name: Query specific Bridge Domain(s) bound to an L3 Out
90 cisco.aci.aci_bd_to_l3out:
91 host: apic
92 username: admin
93 password: SomeSecretPassword
94 bd: web_servers
95 l3out: prod_l3out
96 tenant: prod
97 state: query
98 delegate_to: localhost
99 register: query_result
100 """
101
102 RETURN = r"""
103 current:
104 description: The existing configuration from the APIC after the module has finished
105 returned: success
106 type: list
107 sample:
108 [
109 {
110 "fvTenant": {
111 "attributes": {
112 "descr": "Production environment",
113 "dn": "uni/tn-production",
114 "name": "production",
115 "nameAlias": "",
116 "ownerKey": "",
117 "ownerTag": ""
118 }
119 }
120 }
121 ]
122 error:
123 description: The error information as returned from the APIC
124 returned: failure
125 type: dict
126 sample:
127 {
128 "code": "122",
129 "text": "unknown managed object class foo"
130 }
131 raw:
132 description: The raw output returned by the APIC REST API (xml or json)
133 returned: parse error
134 type: str
135 sample: '<?xml version="1.0" encoding="UTF-8"?><imdata totalCount="1"><error code="122" text="unknown managed object class foo"/></imdata>'
136 sent:
137 description: The actual/minimal configuration pushed to the APIC
138 returned: info
139 type: list
140 sample:
141 {
142 "fvTenant": {
143 "attributes": {
144 "descr": "Production environment"
145 }
146 }
147 }
148 previous:
149 description: The original configuration from the APIC before the module has started
150 returned: info
151 type: list
152 sample:
153 [
154 {
155 "fvTenant": {
156 "attributes": {
157 "descr": "Production",
158 "dn": "uni/tn-production",
159 "name": "production",
160 "nameAlias": "",
161 "ownerKey": "",
162 "ownerTag": ""
163 }
164 }
165 }
166 ]
167 proposed:
168 description: The assembled configuration from the user-provided parameters
169 returned: info
170 type: dict
171 sample:
172 {
173 "fvTenant": {
174 "attributes": {
175 "descr": "Production environment",
176 "name": "production"
177 }
178 }
179 }
180 filter_string:
181 description: The filter string used for the request
182 returned: failure or debug
183 type: str
184 sample: ?rsp-prop-include=config-only
185 method:
186 description: The HTTP method used for the request to the APIC
187 returned: failure or debug
188 type: str
189 sample: POST
190 response:
191 description: The HTTP response from the APIC
192 returned: failure or debug
193 type: str
194 sample: OK (30 bytes)
195 status:
196 description: The HTTP status from the APIC
197 returned: failure or debug
198 type: int
199 sample: 200
200 url:
201 description: The HTTP url used for the request to the APIC
202 returned: failure or debug
203 type: str
204 sample: https://10.11.12.13/api/mo/uni/tn-production.json
205 """
206
207 from ansible.module_utils.basic import AnsibleModule
208 from ansible_collections.cisco.aci.plugins.module_utils.aci import ACIModule, aci_argument_spec, aci_annotation_spec
209
210 SUBNET_CONTROL_MAPPING = dict(
211 nd_ra="nd",
212 no_gw="no-default-gateway",
213 querier_ip="querier",
214 unspecified="",
215 )
216
217
218 def main():
219 argument_spec = aci_argument_spec()
220 argument_spec.update(aci_annotation_spec())
221 argument_spec.update(
222 bd=dict(type="str", aliases=["bd_name", "bridge_domain"]), # Not required for querying all objects
223 l3out=dict(type="str"), # Not required for querying all objects
224 tenant=dict(type="str", aliases=["tenant_name"]), # Not required for querying all objects
225 state=dict(type="str", default="present", choices=["absent", "present", "query"]),
226 )
227
228 module = AnsibleModule(
229 argument_spec=argument_spec,
230 supports_check_mode=True,
231 required_if=[
232 ["state", "present", ["bd", "l3out", "tenant"]],
233 ["state", "absent", ["bd", "l3out", "tenant"]],
234 ],
235 )
236
237 bd = module.params.get("bd")
238 l3out = module.params.get("l3out")
239 state = module.params.get("state")
240 tenant = module.params.get("tenant")
241
242 aci = ACIModule(module)
243 aci.construct_url(
244 root_class=dict(
245 aci_class="fvTenant",
246 aci_rn="tn-{0}".format(tenant),
247 module_object=tenant,
248 target_filter={"name": tenant},
249 ),
250 subclass_1=dict(
251 aci_class="fvBD",
252 aci_rn="BD-{0}".format(bd),
253 module_object=bd,
254 target_filter={"name": bd},
255 ),
256 subclass_2=dict(
257 aci_class="fvRsBDToOut",
258 aci_rn="rsBDToOut-{0}".format(l3out),
259 module_object=l3out,
260 target_filter={"tnL3extOutName": l3out},
261 ),
262 )
263
264 aci.get_existing()
265
266 if state == "present":
267 aci.payload(
268 aci_class="fvRsBDToOut",
269 class_config=dict(tnL3extOutName=l3out),
270 )
271
272 aci.get_diff(aci_class="fvRsBDToOut")
273
274 aci.post_config()
275
276 elif state == "absent":
277 aci.delete_config()
278
279 aci.exit_json()
280
281
282 if __name__ == "__main__":
283 main()