Debian Codegraph @

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

raw
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 # Copyright: (c) 2023, Samita Bhattacharjee (@samitab) <[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 ANSIBLE_METADATA = {"metadata_version": "1.1", "status": ["preview"], "supported_by": "certified"}
12
13 DOCUMENTATION = r"""
14 ---
15 module: aci_fabric_pod_external_tep
16 short_description: Manage Fabric Pod External TEP (fabric:ExtRoutablePodSubnet)
17 description:
18 - Manage Fabric Pod External TEP Subnets.
19 options:
20 pod_id:
21 description:
22 - The Pod ID for the External TEP.
23 type: int
24 aliases: [ pod ]
25 description:
26 description:
27 - The description for the External TEP.
28 type: str
29 aliases: [ descr ]
30 name_alias:
31 description:
32 - The alias for the current object. This relates to the nameAlias field in ACI.
33 type: str
34 external_tep_pool:
35 description:
36 - The subnet IP address pool for the External TEP.
37 - Must be valid IPv4 and include the subnet mask.
38 - Example 192.168.1.0/24
39 type: str
40 aliases: [ ip, ip_address, tep_pool, pool ]
41 reserve_address_count:
42 description:
43 - Indicates the number of IP addresses that are reserved from the start of the subnet.
44 type: int
45 aliases: [ address_count ]
46 status:
47 description:
48 - State of the External TEP C(active) or C(inactive).
49 - An External TEP can only be deleted when the state is inactive.
50 - The APIC defaults to C(active) when unset during creation.
51 type: str
52 choices: [ active, inactive ]
53 state:
54 description:
55 - Use C(present) or C(absent) for adding or removing.
56 - Use C(query) for listing an object or multiple objects.
57 type: str
58 choices: [ absent, present, query ]
59 default: present
60 extends_documentation_fragment:
61 - cisco.aci.aci
62 - cisco.aci.annotation
63 - cisco.aci.owner
64
65 notes:
66 - The C(Fabric Pod Setup Policy) must exist before using this module in your playbook.
67 The M(cisco.aci.aci_fabric_pod) module can be used for this.
68 seealso:
69 - name: APIC Management Information Model reference
70 description: More information about the internal APIC class B(fabric:ExtRoutablePodSubnet).
71 link: https://developer.cisco.com/docs/apic-mim-ref/
72 author:
73 - Samita Bhattacharjee (@samitab)
74 """
75
76 EXAMPLES = r"""
77 - name: Add an External TEP to a fabric pod setup policy
78 cisco.aci.aci_fabric_pod_external_tep:
79 host: apic
80 username: admin
81 password: SomeSecretPassword
82 pod_id: 2
83 external_tep_pool: 10.6.1.0/24
84 reserve_address_count: 5
85 status: active
86 state: present
87 delegate_to: localhost
88
89 - name: Change an External TEP state on a fabric pod setup policy to inactive
90 cisco.aci.aci_fabric_pod_external_tep:
91 host: apic
92 username: admin
93 password: SomeSecretPassword
94 pod_id: 2
95 external_tep_pool: 10.6.1.0/24
96 status: inactive
97 state: present
98 delegate_to: localhost
99
100 - name: Query the External TEP on a fabric pod setup policy
101 cisco.aci.aci_fabric_pod_external_tep:
102 host: apic
103 username: admin
104 password: SomeSecretPassword
105 pod_id: 2
106 external_tep_pool: 10.6.1.0/24
107 state: query
108 delegate_to: localhost
109 register: query_result
110
111 - name: Query External TEPs on all fabric pod setup policies
112 cisco.aci.aci_fabric_pod_external_tep:
113 host: apic
114 username: admin
115 password: SomeSecretPassword
116 state: query
117 delegate_to: localhost
118 register: query_result
119
120 - name: Delete an External TEP on a fabric pod setup policy
121 cisco.aci.aci_fabric_pod_external_tep:
122 host: apic
123 username: admin
124 password: SomeSecretPassword
125 pod_id: 2
126 external_tep_pool: 10.6.1.0/24
127 state: absent
128 delegate_to: localhost
129 """
130
131 RETURN = r"""
132 current:
133 description: The existing configuration from the APIC after the module has finished
134 returned: success
135 type: list
136 sample:
137 [
138 {
139 "fvTenant": {
140 "attributes": {
141 "descr": "Production environment",
142 "dn": "uni/tn-production",
143 "name": "production",
144 "nameAlias": "",
145 "ownerKey": "",
146 "ownerTag": ""
147 }
148 }
149 }
150 ]
151 error:
152 description: The error information as returned from the APIC
153 returned: failure
154 type: dict
155 sample:
156 {
157 "code": "122",
158 "text": "unknown managed object class foo"
159 }
160 raw:
161 description: The raw output returned by the APIC REST API (xml or json)
162 returned: parse error
163 type: str
164 sample: '<?xml version="1.0" encoding="UTF-8"?><imdata totalCount="1"><error code="122" text="unknown managed object class foo"/></imdata>'
165 sent:
166 description: The actual/minimal configuration pushed to the APIC
167 returned: info
168 type: list
169 sample:
170 {
171 "fvTenant": {
172 "attributes": {
173 "descr": "Production environment"
174 }
175 }
176 }
177 previous:
178 description: The original configuration from the APIC before the module has started
179 returned: info
180 type: list
181 sample:
182 [
183 {
184 "fvTenant": {
185 "attributes": {
186 "descr": "Production",
187 "dn": "uni/tn-production",
188 "name": "production",
189 "nameAlias": "",
190 "ownerKey": "",
191 "ownerTag": ""
192 }
193 }
194 }
195 ]
196 proposed:
197 description: The assembled configuration from the user-provided parameters
198 returned: info
199 type: dict
200 sample:
201 {
202 "fvTenant": {
203 "attributes": {
204 "descr": "Production environment",
205 "name": "production"
206 }
207 }
208 }
209 filter_string:
210 description: The filter string used for the request
211 returned: failure or debug
212 type: str
213 sample: ?rsp-prop-include=config-only
214 method:
215 description: The HTTP method used for the request to the APIC
216 returned: failure or debug
217 type: str
218 sample: POST
219 response:
220 description: The HTTP response from the APIC
221 returned: failure or debug
222 type: str
223 sample: OK (30 bytes)
224 status:
225 description: The HTTP status from the APIC
226 returned: failure or debug
227 type: int
228 sample: 200
229 url:
230 description: The HTTP url used for the request to the APIC
231 returned: failure or debug
232 type: str
233 sample: https://10.11.12.13/api/mo/uni/tn-production.json
234 """
235
236 from ansible.module_utils.basic import AnsibleModule
237 from ansible_collections.cisco.aci.plugins.module_utils.aci import (
238 ACIModule,
239 aci_argument_spec,
240 aci_annotation_spec,
241 aci_owner_spec,
242 )
243
244
245 def main():
246 argument_spec = aci_argument_spec()
247 argument_spec.update(aci_annotation_spec())
248 argument_spec.update(aci_owner_spec())
249 argument_spec.update(
250 description=dict(type="str", aliases=["descr"]),
251 name_alias=dict(type="str"),
252 pod_id=dict(type="int", aliases=["pod"]),
253 external_tep_pool=dict(type="str", aliases=["ip", "ip_address", "tep_pool", "pool"]),
254 reserve_address_count=dict(type="int", aliases=["address_count"]),
255 status=dict(type="str", choices=["active", "inactive"]),
256 state=dict(type="str", default="present", choices=["absent", "present", "query"]),
257 )
258
259 module = AnsibleModule(
260 argument_spec=argument_spec,
261 supports_check_mode=True,
262 required_if=[
263 ["state", "absent", ["pod_id", "external_tep_pool"]],
264 ["state", "present", ["pod_id", "external_tep_pool"]],
265 ],
266 )
267
268 aci = ACIModule(module)
269
270 pod_id = module.params.get("pod_id")
271 descr = module.params.get("descr")
272 name_alias = module.params.get("name_alias")
273 external_tep_pool = module.params.get("external_tep_pool")
274 reserve_address_count = module.params.get("reserve_address_count")
275 status = module.params.get("status")
276 state = module.params.get("state")
277
278 if pod_id is not None and int(pod_id) not in range(1, 254):
279 aci.fail_json(msg="Pod ID: {0} is invalid; it must be in the range of 1 to 254.".format(pod_id))
280
281 aci.construct_url(
282 root_class=dict(
283 aci_class="fabricSetupP",
284 aci_rn="controller/setuppol/setupp-{0}".format(pod_id),
285 module_object=pod_id,
286 target_filter={"podId": pod_id},
287 ),
288 subclass_1=dict(
289 aci_class="fabricExtRoutablePodSubnet",
290 aci_rn="extrtpodsubnet-[{0}]".format(external_tep_pool),
291 module_object=external_tep_pool,
292 target_filter={"pool": external_tep_pool},
293 ),
294 )
295
296 aci.get_existing()
297
298 if state == "present":
299 aci.payload(
300 aci_class="fabricExtRoutablePodSubnet",
301 class_config=dict(
302 descr=descr,
303 nameAlias=name_alias,
304 pool=external_tep_pool,
305 reserveAddressCount=reserve_address_count,
306 state=status,
307 ),
308 )
309
310 aci.get_diff(aci_class="fabricExtRoutablePodSubnet")
311
312 aci.post_config()
313
314 elif state == "absent":
315 aci.delete_config()
316
317 aci.exit_json()
318
319
320 if __name__ == "__main__":
321 main()