Debian Codegraph @

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