Debian Codegraph @

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

raw
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 # Copyright: (c) 2020, Sudhakar Shet Kudtarkar (@kudtarkar1)
5 # Copyright: (c) 2020, Shreyas Srish <[email protected]>
6 # GNU General Public License v3.0+ (see LICENSE or https://www.gnu.org/licenses/gpl-3.0.txt)
7
8 from __future__ import absolute_import, division, print_function
9
10 __metaclass__ = type
11
12 ANSIBLE_METADATA = {"metadata_version": "1.1", "status": ["preview"], "supported_by": "community"}
13
14
15 DOCUMENTATION = r"""
16 ---
17 module: aci_l2out_extepg
18 short_description: Manage External Network Instance (L2Out External EPG) objects (l2ext:InstP).
19 description:
20 - Manage External Network Instance (L2Out External EPG) objects on ACI fabrics.
21 options:
22 tenant:
23 description:
24 - Name of existing tenant.
25 type: str
26 l2out:
27 description:
28 - Name of the l2out.
29 type: str
30 extepg:
31 description:
32 - Name of the external end point group.
33 type: str
34 aliases: [ external_epg, extepg_name, name ]
35 description:
36 description:
37 - Description for the l2out.
38 type: str
39 preferred_group:
40 description:
41 - This depicts whether this External EPG is part of the Preferred Group and can communicate without contracts.
42 - This is convenient for migration scenarios, or when ACI is used for network automation but not for policy.
43 - The APIC defaults to C(false) when unset during creation.
44 type: bool
45 qos_class:
46 description:
47 - The bandwidth level for Quality of service.
48 type: str
49 choices: [ level1, level2, level3, level4, level5, level6, Unspecified ]
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
61 notes:
62 - The C(tenant) and C(l2out) must exist before using this module in your playbook.
63 The M(cisco.aci.aci_tenant) and M(cisco.aci.aci_l2out) modules can be used for this.
64 seealso:
65 - name: APIC Management Information Model reference
66 description: More information about the internal APIC class B(l2ext:InstP).
67 link: https://developer.cisco.com/docs/apic-mim-ref/
68 author:
69 - Sudhakar Shet Kudtarkar (@kudtarkar1)
70 - Shreyas Srish (@shrsr)
71 """
72
73 EXAMPLES = r"""
74 - name: Add a new L2 external end point group
75 cisco.aci.aci_l2out_extepg:
76 host: apic
77 username: admin
78 password: SomeSecretePassword
79 tenant: Auto-Demo
80 l2out: l2out
81 extepg: NewExt
82 description: external epg
83 preferred_group: false
84 state: present
85 delegate_to: localhost
86
87 - name: Remove an L2 external end point group
88 cisco.aci.aci_l2out_extepg:
89 host: apic
90 username: admin
91 password: SomeSecretePassword
92 tenant: Auto-Demo
93 l2out: l2out
94 extepg: NewExt
95 state: absent
96 delegate_to: localhost
97
98 - name: Query the L2 external end point group
99 cisco.aci.aci_l2out_extepg:
100 host: apic
101 username: admin
102 password: SomeSecretePassword
103 tenant: Auto-Demo
104 l2out: l2out
105 extepg: NewExt
106 state: query
107 delegate_to: localhost
108 register: query_result
109
110 - name: Query all L2 external end point groups in a tenant
111 cisco.aci.aci_l2out_extepg:
112 host: apic
113 username: admin
114 password: SomeSecretePassword
115 tenant: Auto-Demo
116 state: query
117 delegate_to: localhost
118 register: query_result
119 """
120
121 RETURN = r"""
122 current:
123 description: The existing configuration from the APIC after the module has finished
124 returned: success
125 type: list
126 sample:
127 [
128 {
129 "fvTenant": {
130 "attributes": {
131 "descr": "Production environment",
132 "dn": "uni/tn-production",
133 "name": "production",
134 "nameAlias": "",
135 "ownerKey": "",
136 "ownerTag": ""
137 }
138 }
139 }
140 ]
141 error:
142 description: The error information as returned from the APIC
143 returned: failure
144 type: dict
145 sample:
146 {
147 "code": "122",
148 "text": "unknown managed object class foo"
149 }
150 raw:
151 description: The raw output returned by the APIC REST API (xml or json)
152 returned: parse error
153 type: str
154 sample: '<?xml version="1.0" encoding="UTF-8"?><imdata totalCount="1"><error code="122" text="unknown managed object class "/></imdata>'
155 sent:
156 description: The actual/minimal configuration pushed to the APIC
157 returned: info
158 type: list
159 sample:
160 {
161 "fvTenant": {
162 "attributes": {
163 "descr": "Production environment"
164 }
165 }
166 }
167 previous:
168 description: The original configuration from the APIC before the module has started
169 returned: info
170 type: list
171 sample:
172 [
173 {
174 "fvTenant": {
175 "attributes": {
176 "descr": "Production",
177 "dn": "uni/tn-production",
178 "name": "production",
179 "nameAlias": "",
180 "ownerKey": "",
181 "ownerTag": ""
182 }
183 }
184 }
185 ]
186 proposed:
187 description: The assembled configuration from the user-provided parameters
188 returned: info
189 type: dict
190 sample:
191 {
192 "fvTenant": {
193 "attributes": {
194 "descr": "Production environment",
195 "name": "production"
196 }
197 }
198 }
199 filter_string:
200 description: The filter string used for the request
201 returned: failure or debug
202 type: str
203 sample: ?rsp-prop-include=config-only
204 method:
205 description: The HTTP method used for the request to the APIC
206 returned: failure or debug
207 type: str
208 sample: POST
209 response:
210 description: The HTTP response from the APIC
211 returned: failure or debug
212 type: str
213 sample: OK (30 bytes)
214 status:
215 description: The HTTP status from the APIC
216 returned: failure or debug
217 type: int
218 sample: 200
219 url:
220 description: The HTTP url used for the request to the APIC
221 returned: failure or debug
222 type: str
223 sample: https://10.11.12.13/api/mo/uni/tn-production.json
224 """
225
226 from ansible.module_utils.basic import AnsibleModule
227 from ansible_collections.cisco.aci.plugins.module_utils.aci import ACIModule, aci_argument_spec, aci_annotation_spec
228
229
230 def main():
231 argument_spec = aci_argument_spec()
232 argument_spec.update(aci_annotation_spec())
233 argument_spec.update(
234 l2out=dict(type="str"),
235 description=dict(type="str"),
236 extepg=dict(type="str", aliases=["external_epg", "extepg_name", "name"]),
237 preferred_group=dict(type="bool"),
238 state=dict(type="str", default="present", choices=["absent", "present", "query"]),
239 tenant=dict(type="str"),
240 qos_class=dict(type="str", choices=["level1", "level2", "level3", "level4", "level5", "level6", "Unspecified"]),
241 )
242
243 module = AnsibleModule(
244 argument_spec=argument_spec,
245 supports_check_mode=True,
246 required_if=[
247 ["state", "absent", ["l2out", "tenant", "extepg"]],
248 ["state", "present", ["l2out", "tenant", "extepg"]],
249 ],
250 )
251
252 aci = ACIModule(module)
253
254 l2out = module.params.get("l2out")
255 description = module.params.get("description")
256 preferred_group = aci.boolean(module.params.get("preferred_group"), "include", "exclude")
257 state = module.params.get("state")
258 tenant = module.params.get("tenant")
259 extepg = module.params.get("extepg")
260 qos_class = module.params.get("qos_class")
261
262 aci.construct_url(
263 root_class=dict(
264 aci_class="fvTenant",
265 aci_rn="tn-{0}".format(tenant),
266 module_object=tenant,
267 target_filter={"name": tenant},
268 ),
269 subclass_1=dict(
270 aci_class="l2extOut",
271 aci_rn="l2out-{0}".format(l2out),
272 module_object=l2out,
273 target_filter={"name": l2out},
274 ),
275 subclass_2=dict(
276 aci_class="l2extInstP",
277 aci_rn="instP-{0}".format(extepg),
278 module_object=extepg,
279 target_filter={"name": extepg},
280 ),
281 )
282
283 aci.get_existing()
284
285 if state == "present":
286 config = dict(name=extepg, descr=description, dn="uni/tn-{0}/l2out-{1}/instP-{2}".format(tenant, l2out, extepg), prefGrMemb=preferred_group)
287 if qos_class:
288 config.update(prio=qos_class)
289 aci.payload(
290 class_config=config,
291 aci_class="l2extInstP",
292 )
293
294 aci.get_diff(aci_class="l2extInstP")
295
296 aci.post_config()
297
298 elif state == "absent":
299 aci.delete_config()
300
301 aci.exit_json()
302
303
304 if __name__ == "__main__":
305 main()