Debian Codegraph @

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

raw
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 # Copyright: (c) 2021, Anvitha Jain (@anvitha-jain) <[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 DOCUMENTATION = r"""
12 ---
13 module: aci_cloud_external_epg
14 short_description: Manage Cloud External EPG (cloud:ExtEPg)
15 description:
16 - Configures WAN router connectivity to the cloud infrastructure.
17 options:
18 description:
19 description:
20 - configuration item description.
21 aliases: [ descr ]
22 type: str
23 name:
24 description:
25 - Name of Object cloud_external_epg.
26 aliases: [ cloud_external_epg, cloud_external_epg_name, external_epg, external_epg_name, extepg, extepg_name ]
27 type: str
28 route_reachability:
29 description:
30 - Route reachability for this EPG.
31 choices: [ inter-site, internet, unspecified ]
32 type: str
33 tenant:
34 description:
35 - The name of tenant.
36 type: str
37 ap:
38 description:
39 - The name of the cloud application profile.
40 aliases: [ app_profile, app_profile_name ]
41 type: str
42 vrf:
43 description:
44 - The name of the VRF.
45 type: str
46 aliases: [ context, vrf_name ]
47 state:
48 description:
49 - Use C(present) or C(absent) for adding or removing.
50 - Use C(query) for listing an object or multiple objects.
51 choices: [ absent, present, query ]
52 default: present
53 type: str
54 extends_documentation_fragment:
55 - cisco.aci.aci
56 - cisco.aci.annotation
57
58 notes:
59 - More information about the internal APIC class B(cloud:ExtEPg) from
60 L(the APIC Management Information Model reference,https://developer.cisco.com/docs/apic-mim-ref/).
61 author:
62 - Anvitha Jain (@anvitha-jain)
63 """
64
65 EXAMPLES = r"""
66 - name: Add a new cloud external EPG
67 cisco.aci.aci_cloud_external_epg:
68 host: apic
69 username: admin
70 password: SomeSecretPassword
71 tenant: tenant1
72 ap: ap1
73 vrf: vrf1
74 description: Cloud External EPG description
75 name: ext_epg
76 route_reachability: internet
77 state: present
78 delegate_to: localhost
79
80 - name: Remove a cloud external EPG
81 cisco.aci.aci_cloud_external_epg:
82 host: apic
83 username: admin
84 password: SomeSecretPassword
85 validate_certs: false
86 tenant: tenant1
87 ap: ap1
88 name: ext_epg
89 state: absent
90 delegate_to: localhost
91
92 - name: Query a cloud external EPG
93 cisco.aci.aci_cloud_external_epg:
94 host: apic
95 username: admin
96 password: SomeSecretPassword
97 tenant: tenant1
98 ap: ap1
99 name: ext_epg
100 state: query
101 delegate_to: localhost
102
103 - name: query all
104 cisco.aci.aci_cloud_external_epg:
105 host: apic
106 username: admin
107 password: SomeSecretPassword
108 tenant: tenant1
109 ap: ap1
110 state: query
111 delegate_to: localhost
112 """
113
114 RETURN = r"""
115 current:
116 description: The existing configuration from the APIC after the module has finished
117 returned: success
118 type: list
119 sample:
120 [
121 {
122 "fvTenant": {
123 "attributes": {
124 "descr": "Production environment",
125 "dn": "uni/tn-production",
126 "name": "production",
127 "name_alias": "",
128 "ownerKey": "",
129 "ownerTag": ""
130 }
131 }
132 }
133 ]
134 error:
135 description: The error information as returned from the APIC
136 returned: failure
137 type: dict
138 sample:
139 {
140 "code": "122",
141 "text": "unknown managed object class foo"
142 }
143 raw:
144 description: The raw output returned by the APIC REST API (xml or json)
145 returned: parse error
146 type: str
147 sample: '<?xml version="1.0" encoding="UTF-8"?><imdata totalCount="1"><error code="122" text="unknown managed object class foo"/></imdata>'
148 sent:
149 description: The actual/minimal configuration pushed to the APIC
150 returned: info
151 type: list
152 sample:
153 {
154 "fvTenant": {
155 "attributes": {
156 "descr": "Production environment"
157 }
158 }
159 }
160 previous:
161 description: The original configuration from the APIC before the module has started
162 returned: info
163 type: list
164 sample:
165 [
166 {
167 "fvTenant": {
168 "attributes": {
169 "descr": "Production",
170 "dn": "uni/tn-production",
171 "name": "production",
172 "name_alias": "",
173 "ownerKey": "",
174 "ownerTag": ""
175 }
176 }
177 }
178 ]
179 proposed:
180 description: The assembled configuration from the user-provided parameters
181 returned: info
182 type: dict
183 sample:
184 {
185 "fvTenant": {
186 "attributes": {
187 "descr": "Production environment",
188 "name": "production"
189 }
190 }
191 }
192 filter_string:
193 description: The filter string used for the request
194 returned: failure or debug
195 type: str
196 sample: ?rsp-prop-include=config-only
197 method:
198 description: The HTTP method used for the request to the APIC
199 returned: failure or debug
200 type: str
201 sample: POST
202 response:
203 description: The HTTP response from the APIC
204 returned: failure or debug
205 type: str
206 sample: OK (30 bytes)
207 status:
208 description: The HTTP status from the APIC
209 returned: failure or debug
210 type: int
211 sample: 200
212 url:
213 description: The HTTP url used for the request to the APIC
214 returned: failure or debug
215 type: str
216 sample: https://10.11.12.13/api/mo/uni/tn-production.json
217 """
218
219 from ansible_collections.cisco.aci.plugins.module_utils.aci import ACIModule, aci_argument_spec, aci_annotation_spec
220 from ansible.module_utils.basic import AnsibleModule
221
222
223 def main():
224 argument_spec = aci_argument_spec()
225 argument_spec.update(aci_annotation_spec())
226 argument_spec.update(
227 {
228 "description": dict(type="str", aliases=["descr"]),
229 "name": dict(type="str", aliases=["cloud_external_epg", "cloud_external_epg_name", "external_epg", "external_epg_name", "extepg", "extepg_name"]),
230 "route_reachability": dict(type="str", choices=["inter-site", "internet", "unspecified"]),
231 "tenant": dict(type="str"),
232 "ap": dict(type="str", aliases=["app_profile", "app_profile_name"]),
233 "state": dict(type="str", default="present", choices=["absent", "present", "query"]),
234 "vrf": dict(type="str", aliases=["context", "vrf_name"]),
235 }
236 )
237
238 module = AnsibleModule(
239 argument_spec=argument_spec,
240 supports_check_mode=True,
241 required_if=[
242 ["state", "absent", ["name", "tenant", "ap"]],
243 ["state", "present", ["name", "tenant", "ap"]],
244 ],
245 )
246
247 description = module.params.get("description")
248 name = module.params.get("name")
249 route_reachability = module.params.get("route_reachability")
250 tenant = module.params.get("tenant")
251 ap = module.params.get("ap")
252 state = module.params.get("state")
253 child_configs = []
254 relation_vrf = module.params.get("vrf")
255
256 if relation_vrf:
257 child_configs.append({"cloudRsCloudEPgCtx": {"attributes": {"tnFvCtxName": relation_vrf}}})
258
259 aci = ACIModule(module)
260 aci.construct_url(
261 root_class={
262 "aci_class": "fvTenant",
263 "aci_rn": "tn-{0}".format(tenant),
264 "target_filter": 'eq(fvTenant.name, "{0}")'.format(tenant),
265 "module_object": tenant,
266 },
267 subclass_1={"aci_class": "cloudApp", "aci_rn": "cloudapp-{0}".format(ap), "target_filter": 'eq(cloudApp.name, "{0}")'.format(ap), "module_object": ap},
268 subclass_2={
269 "aci_class": "cloudExtEPg",
270 "aci_rn": "cloudextepg-{0}".format(name),
271 "target_filter": 'eq(cloudExtEPg.name, "{0}")'.format(name),
272 "module_object": name,
273 },
274 child_classes=["fvRsCustQosPol", "cloudRsCloudEPgCtx"],
275 )
276
277 aci.get_existing()
278
279 if state == "present":
280 aci.payload(
281 aci_class="cloudExtEPg",
282 class_config={
283 "descr": description,
284 "name": name,
285 "routeReachability": route_reachability,
286 },
287 child_configs=child_configs,
288 )
289
290 aci.get_diff(aci_class="cloudExtEPg")
291
292 aci.post_config()
293
294 elif state == "absent":
295 aci.delete_config()
296
297 aci.exit_json()
298
299
300 if __name__ == "__main__":
301 main()