Debian Codegraph @

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

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