Debian Codegraph @

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

raw
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 # GNU General Public License v3.0+ (see LICENSE or https://www.gnu.org/licenses/gpl-3.0.txt)
5
6 from __future__ import absolute_import, division, print_function
7
8 __metaclass__ = type
9
10 ANSIBLE_METADATA = {"metadata_version": "1.1", "status": ["preview"], "supported_by": "certified"}
11
12 DOCUMENTATION = r"""
13 ---
14 module: aci_fabric_switch_block
15 short_description: Manage switch blocks (fabric:NodeBlk)
16 description:
17 - Manage fabric node blocks within switch associations (fabric:SpineS and
18 fabric:LeafS) contained within fabric switch profiles (fabric:SpineP and fabric:LeafP)
19 options:
20 name:
21 description:
22 - Name of the block
23 type: str
24 aliases: [ block_name ]
25 switch_type:
26 description:
27 - Type of switch profile, leaf or spine
28 type: str
29 choices: [ leaf, spine ]
30 required: true
31 profile:
32 description:
33 - Name of an existing fabric spine or leaf switch profile
34 type: str
35 aliases: [ profile_name, switch_profile ]
36 association:
37 description:
38 - Name of an existing switch association
39 type: str
40 aliases: [ association_name, switch_association ]
41 description:
42 description:
43 - Description of the Node Block
44 type: str
45 aliases: [ descr ]
46 from_node:
47 description:
48 - First Node ID of the block
49 type: int
50 aliases: [ from, from_ ]
51 to_node:
52 description:
53 - Last Node ID of the block
54 type: int
55 aliases: [ to, to_ ]
56 state:
57 description:
58 - Use C(present) or C(absent) for adding or removing.
59 - Use C(query) for listing an object or multiple objects.
60 type: str
61 choices: [ absent, present, query ]
62 default: present
63 extends_documentation_fragment:
64 - cisco.aci.aci
65 - cisco.aci.annotation
66
67 seealso:
68 - name: APIC Management Information Model reference
69 description: More information about the internal APIC class B(fabricNodeBlk)
70 link: https://developer.cisco.com/docs/apic-mim-ref/
71 author:
72 - Tim Cragg (@timcragg)
73 """
74
75 EXAMPLES = r"""
76 - name: Create a spine switch association block
77 cisco.aci.aci_fabric_switch_block:
78 host: apic
79 username: admin
80 password: SomeSecretPassword
81 switch_type: spine
82 profile: my_spine_profile
83 association: my_spine_switch_assoc
84 name: my_spine_block
85 from_node: 101
86 to_node: 101
87 state: present
88 delegate_to: localhost
89
90 - name: Remove a spine switch profile association
91 cisco.aci.aci_fabric_switch_block:
92 host: apic
93 username: admin
94 password: SomeSecretPassword
95 switch_type: spine
96 profile: my_spine_profile
97 association: my_spine_switch_assoc
98 name: my_spine_block
99 state: absent
100 delegate_to: localhost
101
102 - name: Query a spine profile association
103 cisco.aci.aci_fabric_switch_block:
104 host: apic
105 username: admin
106 password: SomeSecretPassword
107 switch_type: spine
108 profile: my_spine_profile
109 association: my_spine_switch_assoc
110 name: my_spine_block
111 state: query
112 delegate_to: localhost
113 register: query_result
114 """
115
116 RETURN = r"""
117 current:
118 description: The existing configuration from the APIC after the module has finished
119 returned: success
120 type: list
121 sample:
122 [
123 {
124 "fvTenant": {
125 "attributes": {
126 "descr": "Production environment",
127 "dn": "uni/tn-production",
128 "name": "production",
129 "nameAlias": "",
130 "ownerKey": "",
131 "ownerTag": ""
132 }
133 }
134 }
135 ]
136 error:
137 description: The error information as returned from the APIC
138 returned: failure
139 type: dict
140 sample:
141 {
142 "code": "122",
143 "text": "unknown managed object class foo"
144 }
145 raw:
146 description: The raw output returned by the APIC REST API (xml or json)
147 returned: parse error
148 type: str
149 sample: '<?xml version="1.0" encoding="UTF-8"?><imdata totalCount="1"><error code="122" text="unknown managed object class foo"/></imdata>'
150 sent:
151 description: The actual/minimal configuration pushed to the APIC
152 returned: info
153 type: list
154 sample:
155 {
156 "fvTenant": {
157 "attributes": {
158 "descr": "Production environment"
159 }
160 }
161 }
162 previous:
163 description: The original configuration from the APIC before the module has started
164 returned: info
165 type: list
166 sample:
167 [
168 {
169 "fvTenant": {
170 "attributes": {
171 "descr": "Production",
172 "dn": "uni/tn-production",
173 "name": "production",
174 "nameAlias": "",
175 "ownerKey": "",
176 "ownerTag": ""
177 }
178 }
179 }
180 ]
181 proposed:
182 description: The assembled configuration from the user-provided parameters
183 returned: info
184 type: dict
185 sample:
186 {
187 "fvTenant": {
188 "attributes": {
189 "descr": "Production environment",
190 "name": "production"
191 }
192 }
193 }
194 filter_string:
195 description: The filter string used for the request
196 returned: failure or debug
197 type: str
198 sample: ?rsp-prop-include=config-only
199 method:
200 description: The HTTP method used for the request to the APIC
201 returned: failure or debug
202 type: str
203 sample: POST
204 response:
205 description: The HTTP response from the APIC
206 returned: failure or debug
207 type: str
208 sample: OK (30 bytes)
209 status:
210 description: The HTTP status from the APIC
211 returned: failure or debug
212 type: int
213 sample: 200
214 url:
215 description: The HTTP url used for the request to the APIC
216 returned: failure or debug
217 type: str
218 sample: https://10.11.12.13/api/mo/uni/tn-production.json
219 """
220
221
222 from ansible_collections.cisco.aci.plugins.module_utils.aci import ACIModule, aci_argument_spec, aci_annotation_spec
223 from ansible.module_utils.basic import AnsibleModule
224
225
226 def main():
227 argument_spec = aci_argument_spec()
228 argument_spec.update(aci_annotation_spec())
229 argument_spec.update(
230 name=dict(type="str", aliases=["block_name"]),
231 switch_type=dict(type="str", choices=["leaf", "spine"], required=True),
232 profile=dict(type="str", aliases=["profile_name", "switch_profile"]),
233 association=dict(type="str", aliases=["association_name", "switch_association"]),
234 description=dict(type="str", aliases=["descr"]),
235 from_node=dict(type="int", aliases=["from", "from_"]),
236 to_node=dict(type="int", aliases=["to", "to_"]),
237 state=dict(type="str", default="present", choices=["absent", "present", "query"]),
238 )
239
240 module = AnsibleModule(
241 argument_spec=argument_spec,
242 supports_check_mode=True,
243 required_if=[
244 ["state", "absent", ["profile", "association", "name"]],
245 ["state", "present", ["profile", "association", "name"]],
246 ],
247 )
248
249 aci = ACIModule(module)
250
251 name = module.params.get("name")
252 profile = module.params.get("profile")
253 switch_type = module.params.get("switch_type")
254 association = module.params.get("association")
255 descr = module.params.get("descr")
256 from_node = module.params.get("from_node")
257 to_node = module.params.get("to_node")
258 state = module.params.get("state")
259
260 if switch_type == "spine":
261 aci_root_class = "fabricSpineP"
262 aci_root_rn = "fabric/spprof-{0}".format(profile)
263 aci_subclass1_class = "fabricSpineS"
264 aci_subclass1_rn = "spines-{0}-typ-range".format(association)
265 elif switch_type == "leaf":
266 aci_root_class = "fabricLeafP"
267 aci_root_rn = "fabric/leprof-{0}".format(profile)
268 aci_subclass1_class = "fabricLeafS"
269 aci_subclass1_rn = "leaves-{0}-typ-range".format(association)
270
271 aci.construct_url(
272 root_class=dict(
273 aci_class=aci_root_class,
274 aci_rn=aci_root_rn,
275 module_object=profile,
276 target_filter={"name": profile},
277 ),
278 subclass_1=dict(
279 aci_class=aci_subclass1_class,
280 aci_rn=aci_subclass1_rn,
281 module_object=association,
282 target_filter={"name": association},
283 ),
284 subclass_2=dict(
285 aci_class="fabricNodeBlk",
286 aci_rn="nodeblk-{0}".format(name),
287 module_object=name,
288 target_filter={"name": name},
289 ),
290 )
291
292 aci.get_existing()
293
294 if state == "present":
295 aci.payload(
296 aci_class="fabricNodeBlk",
297 class_config=dict(name=name, descr=descr, from_=from_node, to_=to_node),
298 )
299
300 aci.get_diff(aci_class="fabricNodeBlk")
301
302 aci.post_config()
303
304 elif state == "absent":
305 aci.delete_config()
306
307 aci.exit_json()
308
309
310 if __name__ == "__main__":
311 main()