Debian Codegraph @

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

raw
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 # Copyright: (c) 2021, 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 DOCUMENTATION = r"""
12 ---
13 module: aci_cloud_aws_provider
14 short_description: Manage Cloud AWS Provider (cloud:AwsProvider)
15 description:
16 - Manage AWS provider on Cisco Cloud ACI.
17 author:
18 - Shreyas Srish (@shrsr)
19 options:
20 access_key_id:
21 description:
22 - Cloud Access Key ID.
23 type: str
24 account_id:
25 description:
26 - AWS Account ID.
27 type: str
28 is_account_in_org:
29 description:
30 - Is Account in Organization.
31 type: bool
32 is_trusted:
33 description:
34 - Trusted Tenant
35 type: bool
36 secret_access_key:
37 description:
38 - Cloud Secret Access Key.
39 - Providing this option will always result in a change because it is a secure property that cannot be retrieved from APIC.
40 type: str
41 tenant:
42 description:
43 - Name of tenant.
44 type: str
45 state:
46 description:
47 - Use C(present) or C(absent) for adding or removing.
48 - Use C(query) for listing an object or multiple objects.
49 type: str
50 choices: [ absent, present, query ]
51 default: present
52 extends_documentation_fragment:
53 - cisco.aci.aci
54 - cisco.aci.annotation
55 - cisco.aci.owner
56
57 notes:
58 - More information about the internal APIC class B(cloud:AwsProvider) from
59 - L(the APIC Management Information Model reference,https://developer.cisco.com/docs/apic-mim-ref/).
60 """
61
62 EXAMPLES = r"""
63 - name: Create aws provider again after deletion as not trusted
64 cisco.aci.aci_cloud_aws_provider:
65 host: apic
66 username: admin
67 password: SomeSecretePassword
68 tenant: ansible_test
69 account_id: 111111111111
70 is_trusted: true
71 state: present
72 delegate_to: localhost
73
74 - name: Delete aws provider
75 cisco.aci.aci_cloud_aws_provider:
76 host: apic
77 username: admin
78 password: SomeSecretePassword
79 tenant: ansible_test
80 account_id: 111111111111
81 is_trusted: true
82 state: absent
83 delegate_to: localhost
84
85 - name: Query aws provider
86 cisco.aci.aci_cloud_aws_provider:
87 host: apic
88 username: admin
89 password: SomeSecretePassword
90 state: query
91 delegate_to: localhost
92
93 - name: Query all aws provider
94 cisco.aci.aci_cloud_aws_provider:
95 host: apic
96 username: admin
97 password: SomeSecretePassword
98 state: query
99 delegate_to: localhost
100 """
101
102 RETURN = r"""
103 current:
104 description: The existing configuration from the APIC after the module has finished
105 returned: success
106 type: list
107 sample:
108 [
109 {
110 "fvTenant": {
111 "attributes": {
112 "descr": "Production environment",
113 "dn": "uni/tn-production",
114 "name": "production",
115 "nameAlias": "",
116 "ownerKey": "",
117 "ownerTag": ""
118 }
119 }
120 }
121 ]
122 error:
123 description: The error information as returned from the APIC
124 returned: failure
125 type: dict
126 sample:
127 {
128 "code": "122",
129 "text": "unknown managed object class foo"
130 }
131 raw:
132 description: The raw output returned by the APIC REST API (xml or json)
133 returned: parse error
134 type: str
135 sample: '<?xml version="1.0" encoding="UTF-8"?><imdata totalCount="1"><error code="122" text="unknown managed object class foo"/></imdata>'
136 sent:
137 description: The actual/minimal configuration pushed to the APIC
138 returned: info
139 type: list
140 sample:
141 {
142 "fvTenant": {
143 "attributes": {
144 "descr": "Production environment"
145 }
146 }
147 }
148 previous:
149 description: The original configuration from the APIC before the module has started
150 returned: info
151 type: list
152 sample:
153 [
154 {
155 "fvTenant": {
156 "attributes": {
157 "descr": "Production",
158 "dn": "uni/tn-production",
159 "name": "production",
160 "nameAlias": "",
161 "ownerKey": "",
162 "ownerTag": ""
163 }
164 }
165 }
166 ]
167 proposed:
168 description: The assembled configuration from the user-provided parameters
169 returned: info
170 type: dict
171 sample:
172 {
173 "fvTenant": {
174 "attributes": {
175 "descr": "Production environment",
176 "name": "production"
177 }
178 }
179 }
180 filter_string:
181 description: The filter string used for the request
182 returned: failure or debug
183 type: str
184 sample: ?rsp-prop-include=config-only
185 method:
186 description: The HTTP method used for the request to the APIC
187 returned: failure or debug
188 type: str
189 sample: POST
190 response:
191 description: The HTTP response from the APIC
192 returned: failure or debug
193 type: str
194 sample: OK (30 bytes)
195 status:
196 description: The HTTP status from the APIC
197 returned: failure or debug
198 type: int
199 sample: 200
200 url:
201 description: The HTTP url used for the request to the APIC
202 returned: failure or debug
203 type: str
204 sample: https://10.11.12.13/api/mo/uni/tn-production.json
205 """
206
207 from ansible_collections.cisco.aci.plugins.module_utils.aci import ACIModule, aci_argument_spec, aci_annotation_spec, aci_owner_spec
208 from ansible.module_utils.basic import AnsibleModule
209
210
211 def main():
212 argument_spec = aci_argument_spec()
213 argument_spec.update(aci_annotation_spec())
214 argument_spec.update(aci_owner_spec())
215 argument_spec.update(
216 {
217 "access_key_id": dict(type="str"),
218 "account_id": dict(type="str"),
219 "is_account_in_org": dict(type="bool"),
220 "is_trusted": dict(type="bool"),
221 "secret_access_key": dict(type="str", no_log=True),
222 "tenant": dict(type="str"),
223 "state": dict(type="str", default="present", choices=["absent", "present", "query"]),
224 }
225 )
226
227 module = AnsibleModule(
228 argument_spec=argument_spec,
229 supports_check_mode=True,
230 required_if=[
231 ["state", "absent", ["tenant"]],
232 ["state", "present", ["tenant"]],
233 ],
234 )
235
236 aci = ACIModule(module)
237
238 access_key_id = module.params.get("access_key_id")
239 account_id = module.params.get("account_id")
240 annotation = module.params.get("annotation")
241 is_account_in_org = aci.boolean(module.params.get("is_account_in_org"))
242 is_trusted = aci.boolean(module.params.get("is_trusted"))
243 secret_access_key = module.params.get("secret_access_key")
244 tenant = module.params.get("tenant")
245 state = module.params.get("state")
246 child_configs = []
247
248 aci.construct_url(
249 root_class={
250 "aci_class": "fvTenant",
251 "aci_rn": "tn-{0}".format(tenant),
252 "target_filter": 'eq(fvTenant.name, "{0}")'.format(tenant),
253 "module_object": tenant,
254 },
255 subclass_1={
256 "aci_class": "cloudAwsProvider",
257 "aci_rn": "awsprovider",
258 "target_filter": {"account_id": account_id},
259 "module_object": account_id,
260 },
261 child_classes=[],
262 )
263
264 aci.get_existing()
265
266 if state == "present":
267 aci.payload(
268 aci_class="cloudAwsProvider",
269 class_config={
270 "accessKeyId": access_key_id,
271 "accountId": account_id,
272 "annotation": annotation,
273 "isAccountInOrg": is_account_in_org,
274 "isTrusted": is_trusted,
275 "secretAccessKey": secret_access_key,
276 },
277 child_configs=child_configs,
278 )
279
280 aci.get_diff(aci_class="cloudAwsProvider")
281
282 aci.post_config()
283
284 elif state == "absent":
285 aci.delete_config()
286
287 aci.exit_json()
288
289
290 if __name__ == "__main__":
291 main()