Debian Codegraph @

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

raw
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 # Copyright: (c) 2023, Tim Cragg (@timcragg) <[email protected]>
5 # Copyright: (c) 2023, Akini Ross (@akinross) <[email protected]
6 # GNU General Public License v3.0+ (see LICENSE or https://www.gnu.org/licenses/gpl-3.0.txt)
7
8 from __future__ import absolute_import, division, print_function
9
10 __metaclass__ = type
11
12 ANSIBLE_METADATA = {"metadata_version": "1.1", "status": ["preview"], "supported_by": "certified"}
13
14 DOCUMENTATION = r"""
15 ---
16 module: aci_fabric_node_control
17 short_description: Manage Fabric Node Controls (fabric:NodeControl)
18 description:
19 - Manage Fabric Node Controls on ACI fabrics.
20 options:
21 name:
22 description:
23 - The name of the Fabric Node Control.
24 type: str
25 aliases: [ fabric_node_control ]
26 description:
27 description:
28 - The description of the Fabric Node Control.
29 type: str
30 enable_dom:
31 description:
32 - Whether to enable digital optical monitoring (DOM) for the fabric node control.
33 - The APIC defaults to C(false) when unset during creation.
34 type: bool
35 feature_selection:
36 description:
37 - The feature selection for the Node Control.
38 - The APIC defaults to C(telemetry) when unset during creation.
39 type: str
40 choices: [ analytics, netflow, telemetry ]
41 aliases: [ feature ]
42 state:
43 description:
44 - Use C(present) or C(absent) for adding or removing.
45 - Use C(query) for listing an object or multiple objects.
46 type: str
47 choices: [ absent, present, query ]
48 default: present
49 extends_documentation_fragment:
50 - cisco.aci.aci
51 - cisco.aci.annotation
52 - cisco.aci.owner
53
54 seealso:
55 - name: APIC Management Information Model reference
56 description: More information about the internal APIC class B(fabric:NodeControl).
57 link: https://developer.cisco.com/docs/apic-mim-ref/
58
59 author:
60 - Tim Cragg (@timcragg)
61 - Akini Ross (@akinross)
62 """
63
64 EXAMPLES = r"""
65 - name: Create Fabric Node Control
66 cisco.aci.aci_fabric_node_control:
67 host: apic
68 username: admin
69 password: SomeSecretPassword
70 name: ans_fab_node_control
71 enable_dom: true
72 feature_selection: netflow
73 state: present
74 delegate_to: localhost
75
76 - name: Delete Fabric Node Control
77 cisco.aci.aci_fabric_node_control:
78 host: apic
79 username: admin
80 password: SomeSecretPassword
81 name: ans_fab_node_control
82 state: absent
83 delegate_to: localhost
84
85 - name: Query Fabric Node Control
86 cisco.aci.aci_fabric_node_control:
87 host: apic
88 username: admin
89 password: SomeSecretPassword
90 name: ans_fab_node_control
91 state: query
92 delegate_to: localhost
93
94 - name: Query All Fabric Node Controls
95 cisco.aci.aci_fabric_node_control:
96 host: apic
97 username: admin
98 password: SomeSecretPassword
99 state: query
100 delegate_to: localhost
101 """
102
103 RETURN = r"""
104 current:
105 description: The existing configuration from the APIC after the module has finished
106 returned: success
107 type: list
108 sample:
109 [
110 {
111 "fvTenant": {
112 "attributes": {
113 "descr": "Production environment",
114 "dn": "uni/tn-production",
115 "name": "production",
116 "nameAlias": "",
117 "ownerKey": "",
118 "ownerTag": ""
119 }
120 }
121 }
122 ]
123 error:
124 description: The error information as returned from the APIC
125 returned: failure
126 type: dict
127 sample:
128 {
129 "code": "122",
130 "text": "unknown managed object class foo"
131 }
132 raw:
133 description: The raw output returned by the APIC REST API (xml or json)
134 returned: parse error
135 type: str
136 sample: '<?xml version="1.0" encoding="UTF-8"?><imdata totalCount="1"><error code="122" text="unknown managed object class foo"/></imdata>'
137 sent:
138 description: The actual/minimal configuration pushed to the APIC
139 returned: info
140 type: list
141 sample:
142 {
143 "fvTenant": {
144 "attributes": {
145 "descr": "Production environment"
146 }
147 }
148 }
149 previous:
150 description: The original configuration from the APIC before the module has started
151 returned: info
152 type: list
153 sample:
154 [
155 {
156 "fvTenant": {
157 "attributes": {
158 "descr": "Production",
159 "dn": "uni/tn-production",
160 "name": "production",
161 "nameAlias": "",
162 "ownerKey": "",
163 "ownerTag": ""
164 }
165 }
166 }
167 ]
168 proposed:
169 description: The assembled configuration from the user-provided parameters
170 returned: info
171 type: dict
172 sample:
173 {
174 "fvTenant": {
175 "attributes": {
176 "descr": "Production environment",
177 "name": "production"
178 }
179 }
180 }
181 filter_string:
182 description: The filter string used for the request
183 returned: failure or debug
184 type: str
185 sample: ?rsp-prop-include=config-only
186 method:
187 description: The HTTP method used for the request to the APIC
188 returned: failure or debug
189 type: str
190 sample: POST
191 response:
192 description: The HTTP response from the APIC
193 returned: failure or debug
194 type: str
195 sample: OK (30 bytes)
196 status:
197 description: The HTTP status from the APIC
198 returned: failure or debug
199 type: int
200 sample: 200
201 url:
202 description: The HTTP url used for the request to the APIC
203 returned: failure or debug
204 type: str
205 sample: https://10.11.12.13/api/mo/uni/tn-production.json
206 """
207
208 from ansible.module_utils.basic import AnsibleModule
209 from ansible_collections.cisco.aci.plugins.module_utils.aci import ACIModule, aci_argument_spec, aci_annotation_spec, aci_owner_spec
210
211
212 def main():
213 argument_spec = aci_argument_spec()
214 argument_spec.update(aci_annotation_spec())
215 argument_spec.update(aci_owner_spec())
216 argument_spec.update(
217 name=dict(type="str", aliases=["fabric_node_control"]),
218 description=dict(type="str"),
219 enable_dom=dict(type="bool"),
220 feature_selection=dict(type="str", choices=["analytics", "netflow", "telemetry"], aliases=["feature"]),
221 state=dict(type="str", default="present", choices=["absent", "present", "query"]),
222 )
223
224 module = AnsibleModule(
225 argument_spec=argument_spec,
226 supports_check_mode=True,
227 )
228 aci = ACIModule(module)
229
230 name = module.params.get("name")
231 description = module.params.get("description")
232 enable_dom = aci.boolean(module.params.get("enable_dom"), "Dom", "None")
233 feature_selection = module.params.get("feature_selection")
234 state = module.params.get("state")
235
236 aci.construct_url(
237 root_class=dict(
238 aci_class="fabricNodeControl",
239 aci_rn="fabric/nodecontrol-{0}".format(name),
240 module_object=name,
241 target_filter={"name": name},
242 ),
243 )
244 aci.get_existing()
245
246 if state == "present":
247 aci.payload(
248 aci_class="fabricNodeControl",
249 class_config=dict(
250 name=name,
251 descr=description,
252 control=enable_dom,
253 featureSel=feature_selection,
254 ),
255 )
256
257 aci.get_diff(aci_class="fabricNodeControl")
258
259 aci.post_config()
260
261 elif state == "absent":
262 aci.delete_config()
263
264 aci.exit_json()
265
266
267 if __name__ == "__main__":
268 main()