Debian Codegraph @

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

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