Debian Codegraph @

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

raw
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 # Copyright: (c) 2017, Dag Wieers <[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_to_domain
16 short_description: Bind AEPs to Physical or Virtual Domains (infra:RsDomP)
17 description:
18 - Bind AEPs to Physical or Virtual Domains on Cisco ACI fabrics.
19 options:
20 aep:
21 description:
22 - The name of the Attachable Access Entity Profile.
23 type: str
24 aliases: [ aep_name ]
25 domain:
26 description:
27 - Name of the physical or virtual domain being associated with the AEP.
28 type: str
29 aliases: [ domain_name, domain_profile ]
30 domain_type:
31 description:
32 - Determines if the Domain is physical (phys) or virtual (vmm).
33 type: str
34 choices: [ fc, l2dom, l3dom, phys, vmm ]
35 aliases: [ type ]
36 state:
37 description:
38 - Use C(present) or C(absent) for adding or removing.
39 - Use C(query) for listing an object or multiple objects.
40 type: str
41 choices: [ absent, present, query ]
42 default: present
43 vm_provider:
44 description:
45 - The VM platform for VMM Domains.
46 - Support for Kubernetes was added in ACI v3.0.
47 - Support for CloudFoundry, OpenShift and Red Hat was added in ACI v3.1.
48 type: str
49 choices: [ cloudfoundry, kubernetes, microsoft, openshift, openstack, redhat, vmware, nutanix ]
50 extends_documentation_fragment:
51 - cisco.aci.aci
52 - cisco.aci.annotation
53
54 notes:
55 - The C(aep) and C(domain) parameters should exist before using this module.
56 The M(cisco.aci.aci_aep) and M(cisco.aci.aci_domain) can be used for these.
57 seealso:
58 - module: cisco.aci.aci_aep
59 - module: cisco.aci.aci_domain
60 - name: APIC Management Information Model reference
61 description: More information about the internal APIC class B(infra:RsDomP).
62 link: https://developer.cisco.com/docs/apic-mim-ref/
63 author:
64 - Dag Wieers (@dagwieers)
65 """
66
67 EXAMPLES = r"""
68 - name: Add AEP to domain binding
69 cisco.aci.aci_aep_to_domain: &binding_present
70 host: apic
71 username: admin
72 password: SomeSecretPassword
73 aep: test_aep
74 domain: phys_dom
75 domain_type: phys
76 state: present
77 delegate_to: localhost
78
79 - name: Remove AEP to domain binding
80 cisco.aci.aci_aep_to_domain: &binding_absent
81 host: apic
82 username: admin
83 password: SomeSecretPassword
84 aep: test_aep
85 domain: phys_dom
86 domain_type: phys
87 state: absent
88 delegate_to: localhost
89
90 - name: Query our AEP to domain binding
91 cisco.aci.aci_aep_to_domain:
92 host: apic
93 username: admin
94 password: SomeSecretPassword
95 aep: test_aep
96 domain: phys_dom
97 domain_type: phys
98 state: query
99 delegate_to: localhost
100 register: query_result
101
102 - name: Query all AEP to domain bindings
103 cisco.aci.aci_aep_to_domain: &binding_query
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
219 from ansible_collections.cisco.aci.plugins.module_utils.constants import VM_PROVIDER_MAPPING
220
221
222 def main():
223 argument_spec = aci_argument_spec()
224 argument_spec.update(aci_annotation_spec())
225 argument_spec.update(
226 aep=dict(type="str", aliases=["aep_name"]), # Not required for querying all objects
227 domain=dict(type="str", aliases=["domain_name", "domain_profile"]), # Not required for querying all objects
228 domain_type=dict(type="str", choices=["fc", "l2dom", "l3dom", "phys", "vmm"], aliases=["type"]), # Not required for querying all objects
229 state=dict(type="str", default="present", choices=["absent", "present", "query"]),
230 vm_provider=dict(type="str", choices=list(VM_PROVIDER_MAPPING)),
231 )
232
233 module = AnsibleModule(
234 argument_spec=argument_spec,
235 supports_check_mode=True,
236 required_if=[
237 ["domain_type", "vmm", ["vm_provider"]],
238 ["state", "absent", ["aep", "domain", "domain_type"]],
239 ["state", "present", ["aep", "domain", "domain_type"]],
240 ],
241 required_together=[
242 ["domain", "domain_type"],
243 ],
244 )
245
246 aep = module.params.get("aep")
247 domain = module.params.get("domain")
248 domain_type = module.params.get("domain_type")
249 vm_provider = module.params.get("vm_provider")
250 state = module.params.get("state")
251
252 # Report when vm_provider is set when type is not virtual
253 if domain_type != "vmm" and vm_provider is not None:
254 module.fail_json(msg="Domain type '{0}' cannot have a 'vm_provider'".format(domain_type))
255
256 # Compile the full domain for URL building
257 if domain_type == "fc":
258 domain_mo = "uni/fc-{0}".format(domain)
259 elif domain_type == "l2dom":
260 domain_mo = "uni/l2dom-{0}".format(domain)
261 elif domain_type == "l3dom":
262 domain_mo = "uni/l3dom-{0}".format(domain)
263 elif domain_type == "phys":
264 domain_mo = "uni/phys-{0}".format(domain)
265 elif domain_type == "vmm":
266 domain_mo = "uni/vmmp-{0}/dom-{1}".format(VM_PROVIDER_MAPPING[vm_provider], domain)
267 else:
268 domain_mo = None
269
270 aci = ACIModule(module)
271 aci.construct_url(
272 root_class=dict(
273 aci_class="infraAttEntityP",
274 aci_rn="infra/attentp-{0}".format(aep),
275 module_object=aep,
276 target_filter={"name": aep},
277 ),
278 subclass_1=dict(
279 aci_class="infraRsDomP",
280 aci_rn="rsdomP-[{0}]".format(domain_mo),
281 module_object=domain_mo,
282 target_filter={"tDn": domain_mo},
283 ),
284 )
285
286 aci.get_existing()
287
288 if state == "present":
289 aci.payload(
290 aci_class="infraRsDomP",
291 class_config=dict(tDn=domain_mo),
292 )
293
294 aci.get_diff(aci_class="infraRsDomP")
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()