Debian Codegraph @

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

raw
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 # Copyright: (c) 2020, Cindy Zhao <[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_vpn_gateway
14 short_description: Manage cloudRouterP in Cloud Context Profile (cloud:RouterP)
15 description:
16 - Manage cloudRouterP objects on Cisco Cloud ACI.
17 notes:
18 - More information about the internal APIC class B(cloud:RouterP) from
19 L(the APIC Management Information Model reference,https://developer.cisco.com/docs/apic-mim-ref/).
20 author:
21 - Cindy Zhao (@cizhao)
22 options:
23 tenant:
24 description:
25 - The name of tenant.
26 type: str
27 required: true
28 cloud_context_profile:
29 description:
30 - The name of cloud context profile.
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: [ absent, present, query ]
38 type: str
39 default: query
40 extends_documentation_fragment:
41 - cisco.aci.aci
42 - cisco.aci.annotation
43 - cisco.aci.owner
44 """
45
46 EXAMPLES = r"""
47 - name: Enable VpnGateway
48 cisco.aci.aci_cloud_vpn_gateway:
49 host: apic_host
50 username: admin
51 password: SomeSecretPassword
52 tenant: ansible_test
53 cloud_context_profile: ctx_profile_1
54 state: present
55 delegate_to: localhost
56
57 - name: Disable VpnGateway
58 cisco.aci.aci_cloud_vpn_gateway:
59 host: apic_host
60 username: admin
61 password: SomeSecretPassword
62 tenant: ansible_test
63 cloud_context_profile: ctx_profile_1
64 state: absent
65 delegate_to: localhost
66
67 - name: Query VpnGateway
68 cisco.aci.aci_cloud_vpn_gateway:
69 host: apic_host
70 username: admin
71 password: SomeSecretPassword
72 tenant: ansible_test
73 cloud_context_profile: ctx_profile_1
74 delegate_to: localhost
75 """
76
77 RETURN = r"""
78 current:
79 description: The existing configuration from the APIC after the module has finished
80 returned: success
81 type: list
82 sample:
83 [
84 {
85 "fvTenant": {
86 "attributes": {
87 "descr": "Production environment",
88 "dn": "uni/tn-production",
89 "name": "production",
90 "nameAlias": "",
91 "ownerKey": "",
92 "ownerTag": ""
93 }
94 }
95 }
96 ]
97 error:
98 description: The error information as returned from the APIC
99 returned: failure
100 type: dict
101 sample:
102 {
103 "code": "122",
104 "text": "unknown managed object class foo"
105 }
106 raw:
107 description: The raw output returned by the APIC REST API (xml or json)
108 returned: parse error
109 type: str
110 sample: '<?xml version="1.0" encoding="UTF-8"?><imdata totalCount="1"><error code="122" text="unknown managed object class foo"/></imdata>'
111 sent:
112 description: The actual/minimal configuration pushed to the APIC
113 returned: info
114 type: list
115 sample:
116 {
117 "fvTenant": {
118 "attributes": {
119 "descr": "Production environment"
120 }
121 }
122 }
123 previous:
124 description: The original configuration from the APIC before the module has started
125 returned: info
126 type: list
127 sample:
128 [
129 {
130 "fvTenant": {
131 "attributes": {
132 "descr": "Production",
133 "dn": "uni/tn-production",
134 "name": "production",
135 "nameAlias": "",
136 "ownerKey": "",
137 "ownerTag": ""
138 }
139 }
140 }
141 ]
142 proposed:
143 description: The assembled configuration from the user-provided parameters
144 returned: info
145 type: dict
146 sample:
147 {
148 "fvTenant": {
149 "attributes": {
150 "descr": "Production environment",
151 "name": "production"
152 }
153 }
154 }
155 filter_string:
156 description: The filter string used for the request
157 returned: failure or debug
158 type: str
159 sample: ?rsp-prop-include=config-only
160 method:
161 description: The HTTP method used for the request to the APIC
162 returned: failure or debug
163 type: str
164 sample: POST
165 response:
166 description: The HTTP response from the APIC
167 returned: failure or debug
168 type: str
169 sample: OK (30 bytes)
170 status:
171 description: The HTTP status from the APIC
172 returned: failure or debug
173 type: int
174 sample: 200
175 url:
176 description: The HTTP url used for the request to the APIC
177 returned: failure or debug
178 type: str
179 sample: https://10.11.12.13/api/mo/uni/tn-production.json
180 """
181
182 from ansible_collections.cisco.aci.plugins.module_utils.aci import ACIModule, aci_argument_spec, aci_annotation_spec, aci_owner_spec
183 from ansible.module_utils.basic import AnsibleModule
184
185
186 def main():
187 argument_spec = aci_argument_spec()
188 argument_spec.update(aci_annotation_spec())
189 argument_spec.update(aci_owner_spec())
190 argument_spec.update(
191 tenant=dict(type="str", required=True),
192 cloud_context_profile=dict(type="str", required=True),
193 state=dict(type="str", default="query", choices=["absent", "present", "query"]),
194 )
195
196 module = AnsibleModule(
197 argument_spec=argument_spec,
198 supports_check_mode=True,
199 )
200
201 tenant = module.params.get("tenant")
202 cloud_context_profile = module.params.get("cloud_context_profile")
203 state = module.params.get("state")
204 child_configs = []
205
206 aci = ACIModule(module)
207 aci.construct_url(
208 root_class=dict(aci_class="fvTenant", aci_rn="tn-{0}".format(tenant), target_filter='eq(fvTenant.name, "{0}")'.format(tenant), module_object=tenant),
209 subclass_1=dict(
210 aci_class="cloudCtxProfile",
211 aci_rn="ctxprofile-{0}".format(cloud_context_profile),
212 target_filter='eq(cloudCtxProfile.name, "{0}")'.format(cloud_context_profile),
213 module_object=cloud_context_profile,
214 ),
215 subclass_2=dict(aci_class="cloudRouterP", aci_rn="routerp-default", target_filter='eq(cloudRouterP.name, "default")', module_object="default"),
216 child_classes=["cloudRsToVpnGwPol", "cloudRsToHostRouterPol", "cloudIntNetworkP"],
217 )
218
219 aci.get_existing()
220
221 if state == "present":
222 child_configs.append(dict(cloudIntNetworkP=dict(attributes=dict(name="default"))))
223 aci.payload(aci_class="cloudRouterP", class_config=dict(name="default"), child_configs=child_configs)
224
225 aci.get_diff(aci_class="cloudRouterP")
226 aci.post_config()
227
228 elif state == "absent":
229 aci.delete_config()
230
231 aci.exit_json()
232
233
234 if __name__ == "__main__":
235 main()