Debian Codegraph @

ansible_collections/cisco/aci/plugins/modules/aci_cloud_region.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_region
15 short_description: Manage Cloud Providers Region (cloud:Region)
16 description:
17 - Manage Cloud Providers Region on Cisco Cloud ACI.
18 author:
19 - Nirav (@nirav)
20 - Cindy Zhao (@cizhao)
21 options:
22 region:
23 description:
24 - The name of the cloud provider's region.
25 aliases: [ name ]
26 type: str
27 cloud:
28 description:
29 - The vendor of the controller
30 choices: [ aws, azure ]
31 type: str
32 required: true
33 state:
34 description:
35 - Use C(present) or C(absent) for adding or removing.
36 - Use C(query) for listing an object or multiple objects.
37 choices: [ query ]
38 default: query
39 type: str
40
41 notes:
42 - More information about the internal APIC class B(cloud:Region) from
43 L(the APIC Management Information Model reference,https://developer.cisco.com/docs/apic-mim-ref/).
44 - This module is used to query Cloud Providers Region.
45 extends_documentation_fragment:
46 - cisco.aci.aci
47 - cisco.aci.annotation
48 """
49
50 EXAMPLES = r"""
51 - name: Query all regions
52 cisco.aci.aci_cloud_region:
53 host: apic
54 username: userName
55 password: somePassword
56 validate_certs: false
57 cloud: 'aws'
58 state: query
59 delegate_to: localhost
60
61 - name: Query a specific region
62 cisco.aci.aci_cloud_region:
63 host: apic
64 username: userName
65 password: somePassword
66 validate_certs: false
67 cloud: 'aws'
68 region: eu-west-2
69 state: query
70 delegate_to: localhost
71 """
72
73 RETURN = r"""
74 current:
75 description: The existing configuration from the APIC after the module has finished
76 returned: success
77 type: list
78 sample:
79 [
80 {
81 "fvTenant": {
82 "attributes": {
83 "descr": "Production environment",
84 "dn": "uni/tn-production",
85 "name": "production",
86 "nameAlias": "",
87 "ownerKey": "",
88 "ownerTag": ""
89 }
90 }
91 }
92 ]
93 error:
94 description: The error information as returned from the APIC
95 returned: failure
96 type: dict
97 sample:
98 {
99 "code": "122",
100 "text": "unknown managed object class foo"
101 }
102 raw:
103 description: The raw output returned by the APIC REST API (xml or json)
104 returned: parse error
105 type: str
106 sample: '<?xml version="1.0" encoding="UTF-8"?><imdata totalCount="1"><error code="122" text="unknown managed object class foo"/></imdata>'
107 sent:
108 description: The actual/minimal configuration pushed to the APIC
109 returned: info
110 type: list
111 sample:
112 {
113 "fvTenant": {
114 "attributes": {
115 "descr": "Production environment"
116 }
117 }
118 }
119 previous:
120 description: The original configuration from the APIC before the module has started
121 returned: info
122 type: list
123 sample:
124 [
125 {
126 "fvTenant": {
127 "attributes": {
128 "descr": "Production",
129 "dn": "uni/tn-production",
130 "name": "production",
131 "nameAlias": "",
132 "ownerKey": "",
133 "ownerTag": ""
134 }
135 }
136 }
137 ]
138 proposed:
139 description: The assembled configuration from the user-provided parameters
140 returned: info
141 type: dict
142 sample:
143 {
144 "fvTenant": {
145 "attributes": {
146 "descr": "Production environment",
147 "name": "production"
148 }
149 }
150 }
151 filter_string:
152 description: The filter string used for the request
153 returned: failure or debug
154 type: str
155 sample: ?rsp-prop-include=config-only
156 method:
157 description: The HTTP method used for the request to the APIC
158 returned: failure or debug
159 type: str
160 sample: POST
161 response:
162 description: The HTTP response from the APIC
163 returned: failure or debug
164 type: str
165 sample: OK (30 bytes)
166 status:
167 description: The HTTP status from the APIC
168 returned: failure or debug
169 type: int
170 sample: 200
171 url:
172 description: The HTTP url used for the request to the APIC
173 returned: failure or debug
174 type: str
175 sample: https://10.11.12.13/api/mo/uni/tn-production.json
176 """
177
178 from ansible_collections.cisco.aci.plugins.module_utils.aci import ACIModule, aci_argument_spec, aci_annotation_spec
179 from ansible.module_utils.basic import AnsibleModule
180
181
182 def main():
183 argument_spec = aci_argument_spec()
184 argument_spec.update(aci_annotation_spec())
185 argument_spec.update(
186 region=dict(type="str", aliases=["name"]),
187 cloud=dict(type="str", choices=["aws", "azure"], required=True),
188 state=dict(type="str", default="query", choices=["query"]),
189 )
190
191 module = AnsibleModule(
192 argument_spec=argument_spec,
193 supports_check_mode=True,
194 )
195
196 region = module.params.get("region")
197 cloud = module.params.get("cloud")
198
199 aci = ACIModule(module)
200 aci.construct_url(
201 root_class=dict(
202 aci_class="cloudProvP", aci_rn="clouddomp/provp-{0}".format(cloud), target_filter='eq(cloudProvP.vendor, "{0}")'.format(cloud), module_object=cloud
203 ),
204 subclass_1=dict(
205 aci_class="cloudRegion", aci_rn="region-{0}".format(region), target_filter='eq(cloudRegion.name, "{0}")'.format(region), module_object=region
206 ),
207 child_classes=[],
208 )
209
210 aci.get_existing()
211
212 aci.exit_json()
213
214
215 if __name__ == "__main__":
216 main()