Debian Codegraph @

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