Debian Codegraph @

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