Debian Codegraph @

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

raw
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 # Copyright: (c) 2020, Shreyas Srish <[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 ANSIBLE_METADATA = {"metadata_version": "1.1", "status": ["preview"], "supported_by": "certified"}
12
13 DOCUMENTATION = r"""
14 ---
15 module: aci_aep
16 short_description: Manage attachable Access Entity Profile (AEP) objects (infra:AttEntityP and infra:ProvAcc)
17 description:
18 - Connect to external virtual and physical domains by using
19 attachable Access Entity Profiles (AEP) on Cisco ACI fabrics.
20 options:
21 aep:
22 description:
23 - The name of the Attachable Access Entity Profile.
24 type: str
25 aliases: [ aep_name, name ]
26 description:
27 description:
28 - Description for the AEP.
29 type: str
30 aliases: [ descr ]
31 infra_vlan:
32 description:
33 - Enable infrastructure VLAN.
34 - The hypervisor functions of the AEP.
35 - C(false) will disable the infrastructure vlan if it is enabled.
36 type: bool
37 aliases: [ infrastructure_vlan ]
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 default: present
44 choices: [ absent, present, query ]
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 seealso:
55 - module: cisco.aci.aci_aep_to_domain
56 - name: APIC Management Information Model reference
57 description: More information about the internal APIC classes B(infra:AttEntityP) and B(infra:ProvAcc).
58 link: https://developer.cisco.com/docs/apic-mim-ref/
59 author:
60 - Swetha Chunduri (@schunduri)
61 - Shreyas Srish (@shrsr)
62 """
63
64 EXAMPLES = r"""
65 - name: Add a new AEP
66 cisco.aci.aci_aep:
67 host: apic
68 username: admin
69 password: SomeSecretPassword
70 aep: ACI-AEP
71 description: default
72 infra_vlan: true
73 state: present
74 delegate_to: localhost
75
76 - name: Remove an existing AEP
77 cisco.aci.aci_aep:
78 host: apic
79 username: admin
80 password: SomeSecretPassword
81 aep: ACI-AEP
82 state: absent
83 delegate_to: localhost
84
85 - name: Query all AEPs
86 cisco.aci.aci_aep:
87 host: apic
88 username: admin
89 password: SomeSecretPassword
90 state: query
91 delegate_to: localhost
92 register: query_result
93
94 - name: Query a specific AEP
95 cisco.aci.aci_aep:
96 host: apic
97 username: admin
98 password: SomeSecretPassword
99 aep: ACI-AEP
100 state: query
101 delegate_to: localhost
102 register: query_result
103 """
104
105 RETURN = r"""
106 current:
107 description: The existing configuration from the APIC after the module has finished
108 returned: success
109 type: list
110 sample:
111 [
112 {
113 "fvTenant": {
114 "attributes": {
115 "descr": "Production environment",
116 "dn": "uni/tn-production",
117 "name": "production",
118 "nameAlias": "",
119 "ownerKey": "",
120 "ownerTag": ""
121 }
122 }
123 }
124 ]
125 error:
126 description: The error information as returned from the APIC
127 returned: failure
128 type: dict
129 sample:
130 {
131 "code": "122",
132 "text": "unknown managed object class foo"
133 }
134 raw:
135 description: The raw output returned by the APIC REST API (xml or json)
136 returned: parse error
137 type: str
138 sample: '<?xml version="1.0" encoding="UTF-8"?><imdata totalCount="1"><error code="122" text="unknown managed object class foo"/></imdata>'
139 sent:
140 description: The actual/minimal configuration pushed to the APIC
141 returned: info
142 type: list
143 sample:
144 {
145 "fvTenant": {
146 "attributes": {
147 "descr": "Production environment"
148 }
149 }
150 }
151 previous:
152 description: The original configuration from the APIC before the module has started
153 returned: info
154 type: list
155 sample:
156 [
157 {
158 "fvTenant": {
159 "attributes": {
160 "descr": "Production",
161 "dn": "uni/tn-production",
162 "name": "production",
163 "nameAlias": "",
164 "ownerKey": "",
165 "ownerTag": ""
166 }
167 }
168 }
169 ]
170 proposed:
171 description: The assembled configuration from the user-provided parameters
172 returned: info
173 type: dict
174 sample:
175 {
176 "fvTenant": {
177 "attributes": {
178 "descr": "Production environment",
179 "name": "production"
180 }
181 }
182 }
183 filter_string:
184 description: The filter string used for the request
185 returned: failure or debug
186 type: str
187 sample: ?rsp-prop-include=config-only
188 method:
189 description: The HTTP method used for the request to the APIC
190 returned: failure or debug
191 type: str
192 sample: POST
193 response:
194 description: The HTTP response from the APIC
195 returned: failure or debug
196 type: str
197 sample: OK (30 bytes)
198 status:
199 description: The HTTP status from the APIC
200 returned: failure or debug
201 type: int
202 sample: 200
203 url:
204 description: The HTTP url used for the request to the APIC
205 returned: failure or debug
206 type: str
207 sample: https://10.11.12.13/api/mo/uni/tn-production.json
208 """
209
210 from ansible.module_utils.basic import AnsibleModule
211 from ansible_collections.cisco.aci.plugins.module_utils.aci import ACIModule, aci_argument_spec, aci_annotation_spec, aci_owner_spec
212
213
214 def main():
215 argument_spec = aci_argument_spec()
216 argument_spec.update(aci_annotation_spec())
217 argument_spec.update(aci_owner_spec())
218 argument_spec.update(
219 aep=dict(type="str", aliases=["name", "aep_name"]), # Not required for querying all objects
220 description=dict(type="str", aliases=["descr"]),
221 infra_vlan=dict(type="bool", aliases=["infrastructure_vlan"]),
222 state=dict(type="str", default="present", choices=["absent", "present", "query"]),
223 name_alias=dict(type="str"),
224 )
225
226 module = AnsibleModule(
227 argument_spec=argument_spec,
228 supports_check_mode=True,
229 required_if=[
230 ["state", "absent", ["aep"]],
231 ["state", "present", ["aep"]],
232 ],
233 )
234
235 aep = module.params.get("aep")
236 description = module.params.get("description")
237 infra_vlan = module.params.get("infra_vlan")
238 state = module.params.get("state")
239 name_alias = module.params.get("name_alias")
240 if infra_vlan:
241 child_configs = [dict(infraProvAcc=dict(attributes=dict(name="provacc")))]
242 elif infra_vlan is False:
243 child_configs = [dict(infraProvAcc=dict(attributes=dict(name="provacc", status="deleted")))]
244 else:
245 child_configs = []
246
247 aci = ACIModule(module)
248 aci.construct_url(
249 root_class=dict(
250 aci_class="infraAttEntityP",
251 aci_rn="infra/attentp-{0}".format(aep),
252 module_object=aep,
253 target_filter={"name": aep},
254 ),
255 child_classes=["infraProvAcc"],
256 )
257
258 aci.get_existing()
259
260 try:
261 if len(aci.existing[0]["infraAttEntityP"]) == 1 and infra_vlan is False:
262 child_configs = []
263 except Exception:
264 pass
265
266 if state == "present":
267 aci.payload(
268 aci_class="infraAttEntityP",
269 class_config=dict(
270 name=aep,
271 descr=description,
272 nameAlias=name_alias,
273 ),
274 child_configs=child_configs,
275 )
276
277 aci.get_diff(aci_class="infraAttEntityP")
278
279 aci.post_config()
280
281 elif state == "absent":
282 aci.delete_config()
283
284 aci.exit_json()
285
286
287 if __name__ == "__main__":
288 main()