Debian Codegraph @

ansible_collections/cisco/aci/plugins/modules/aci_interface_blacklist.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_interface_blacklist
15 short_description: Enabling or Disabling physical interfaces (fabric:RsOosPath)
16 description:
17 - Enables or Disables physical interfaces on Cisco ACI fabrics.
18 options:
19 pod_id:
20 description:
21 - The pod number.
22 - C(pod_id) is usually an integer below C(12)
23 type: int
24 aliases: [ pod, pod_number ]
25 node_id:
26 description:
27 - The switch ID that the C(interface) belongs to.
28 - The C(node_id) value is usually something like '101'.
29 type: int
30 aliases: [ leaf, spine, node ]
31 interface:
32 description:
33 - The name of the C(interface) that is targeted.
34 - Usually an interface name with the following format C(1/7).
35 type: str
36 fex_id:
37 description:
38 - The fex ID that the C(interface) belongs to.
39 - The C(fex_id) value is usually something like '123'.
40 type: int
41 state:
42 description:
43 - Use C(present) or C(absent) for adding or removing.
44 - Use C(query) for listing an object or multiple objects.
45 type: str
46 choices: [ absent, present, query ]
47 default: present
48 extends_documentation_fragment:
49 - cisco.aci.aci
50 - cisco.aci.annotation
51
52 seealso:
53 - name: APIC Management Information Model reference
54 description: More information about the internal APIC class B(fabric:RsOosPath).
55 link: https://developer.cisco.com/docs/apic-mim-ref/
56 author:
57 - Akini Ross (@akinross)
58 """
59
60 EXAMPLES = r"""
61 - name: Disable Interface
62 cisco.aci.aci_interface_blacklist:
63 host: "{{ inventory_hostname }}"
64 username: "{{ username }}"
65 password: "{{ password }}"
66 validate_certs: false
67 pod_id: 1
68 node_id: 105
69 interface: 1/49
70 state: present
71 delegate_to: localhost
72
73 - name: Enable Interface
74 cisco.aci.aci_interface_blacklist:
75 host: "{{ inventory_hostname }}"
76 username: "{{ username }}"
77 password: "{{ password }}"
78 validate_certs: false
79 pod_id: 1
80 node_id: 105
81 interface: 1/49
82 state: absent
83 delegate_to: localhost
84
85 - name: Disable Interface on Fex
86 cisco.aci.aci_interface_blacklist:
87 host: "{{ inventory_hostname }}"
88 username: "{{ username }}"
89 password: "{{ password }}"
90 validate_certs: false
91 pod_id: 1
92 node_id: 105
93 fex_id: 123
94 interface: 1/49
95 state: present
96 delegate_to: localhost
97
98 - name: Enable Interface on Fex
99 cisco.aci.aci_interface_blacklist:
100 host: "{{ inventory_hostname }}"
101 username: "{{ username }}"
102 password: "{{ password }}"
103 validate_certs: false
104 pod_id: 1
105 node_id: 105
106 fex_id: 123
107 interface: 1/49
108 state: absent
109 delegate_to: localhost
110
111 - name: Query Interface
112 cisco.aci.aci_interface_blacklist:
113 host: "{{ inventory_hostname }}"
114 username: "{{ username }}"
115 password: "{{ password }}"
116 validate_certs: false
117 pod_id: 1
118 node_id: 105
119 interface: 1/49
120 state: query
121 delegate_to: localhost
122
123 - name: Query All Interfaces
124 cisco.aci.aci_interface_blacklist:
125 host: "{{ inventory_hostname }}"
126 username: "{{ username }}"
127 password: "{{ password }}"
128 validate_certs: false
129 state: query
130 delegate_to: localhost
131 """
132
133 RETURN = r"""
134 current:
135 description: The existing configuration from the APIC after the module has finished
136 returned: success
137 type: list
138 sample:
139 [
140 {
141 "fvTenant": {
142 "attributes": {
143 "descr": "Production environment",
144 "dn": "uni/tn-production",
145 "name": "production",
146 "nameAlias": "",
147 "ownerKey": "",
148 "ownerTag": ""
149 }
150 }
151 }
152 ]
153 error:
154 description: The error information as returned from the APIC
155 returned: failure
156 type: dict
157 sample:
158 {
159 "code": "122",
160 "text": "unknown managed object class foo"
161 }
162 raw:
163 description: The raw output returned by the APIC REST API (xml or json)
164 returned: parse error
165 type: str
166 sample: '<?xml version="1.0" encoding="UTF-8"?><imdata totalCount="1"><error code="122" text="unknown managed object class foo"/></imdata>'
167 sent:
168 description: The actual/minimal configuration pushed to the APIC
169 returned: info
170 type: list
171 sample:
172 {
173 "fvTenant": {
174 "attributes": {
175 "descr": "Production environment"
176 }
177 }
178 }
179 previous:
180 description: The original configuration from the APIC before the module has started
181 returned: info
182 type: list
183 sample:
184 [
185 {
186 "fvTenant": {
187 "attributes": {
188 "descr": "Production",
189 "dn": "uni/tn-production",
190 "name": "production",
191 "nameAlias": "",
192 "ownerKey": "",
193 "ownerTag": ""
194 }
195 }
196 }
197 ]
198 proposed:
199 description: The assembled configuration from the user-provided parameters
200 returned: info
201 type: dict
202 sample:
203 {
204 "fvTenant": {
205 "attributes": {
206 "descr": "Production environment",
207 "name": "production"
208 }
209 }
210 }
211 filter_string:
212 description: The filter string used for the request
213 returned: failure or debug
214 type: str
215 sample: '?rsp-prop-include=config-only'
216 method:
217 description: The HTTP method used for the request to the APIC
218 returned: failure or debug
219 type: str
220 sample: POST
221 response:
222 description: The HTTP response from the APIC
223 returned: failure or debug
224 type: str
225 sample: OK (30 bytes)
226 status:
227 description: The HTTP status from the APIC
228 returned: failure or debug
229 type: int
230 sample: 200
231 url:
232 description: The HTTP url used for the request to the APIC
233 returned: failure or debug
234 type: str
235 sample: https://10.11.12.13/api/mo/uni/tn-production.json
236 """
237
238 from ansible.module_utils.basic import AnsibleModule
239 from ansible_collections.cisco.aci.plugins.module_utils.aci import ACIModule, aci_argument_spec, aci_annotation_spec
240
241
242 def main():
243 argument_spec = aci_argument_spec()
244 argument_spec.update(aci_annotation_spec())
245 argument_spec.update(
246 pod_id=dict(type="int", aliases=["pod", "pod_number"]),
247 node_id=dict(type="int", aliases=["leaf", "spine", "node"]),
248 fex_id=dict(type="int"),
249 interface=dict(type="str"),
250 state=dict(type="str", default="present", choices=["absent", "present", "query"]),
251 )
252
253 module = AnsibleModule(
254 argument_spec=argument_spec,
255 supports_check_mode=True,
256 required_if=[
257 ["state", "absent", ["pod_id", "node_id", "interface"]],
258 ["state", "present", ["pod_id", "node_id", "interface"]],
259 ],
260 )
261
262 aci = ACIModule(module)
263
264 pod_id = module.params.get("pod_id")
265 node_id = module.params.get("node_id")
266 interface = module.params.get("interface")
267 fex_id = module.params.get("fex_id")
268 state = module.params.get("state")
269
270 root_module_object = None
271 subclass_1_module_object = None
272 tdn = None
273 rn = None
274
275 if pod_id and node_id and interface:
276 root_module_object = "fabric"
277 subclass_1_module_object = "outofsvc"
278 if fex_id:
279 tdn = "topology/pod-{0}/paths-{1}/extpaths-{2}/pathep-[eth{3}]".format(pod_id, node_id, fex_id, interface)
280 else:
281 tdn = "topology/pod-{0}/paths-{1}/pathep-[eth{2}]".format(pod_id, node_id, interface)
282 rn = "rsoosPath-[{0}]".format(tdn)
283
284 aci.construct_url(
285 root_class=dict(
286 aci_class="fabricInst",
287 aci_rn="fabric",
288 module_object=root_module_object,
289 target_filter={"name": "fabric"},
290 ),
291 subclass_1=dict(
292 aci_class="fabricOOServicePol",
293 aci_rn="outofsvc",
294 module_object=subclass_1_module_object,
295 target_filter={"name": "default"},
296 ),
297 subclass_2=dict(
298 aci_class="fabricRsOosPath",
299 aci_rn=rn,
300 target_filter={"tDN": tdn},
301 ),
302 )
303 aci.get_existing()
304
305 if state == "present":
306 aci.payload(
307 aci_class="fabricRsOosPath",
308 class_config=dict(
309 lc="blacklist",
310 ),
311 )
312
313 aci.get_diff(aci_class="fabricRsOosPath")
314
315 aci.post_config()
316
317 elif state == "absent":
318 aci.delete_config()
319
320 aci.exit_json()
321
322
323 if __name__ == "__main__":
324 main()