Debian Codegraph @

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