Debian Codegraph @

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

raw
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 # Copyright: (c) 2023, Gaspard Micol (@gmicol) <[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": "community"}
12
13 DOCUMENTATION = r"""
14 ---
15 module: aci_netflow_monitor_policy
16 short_description: Manage Netflow Monitor Policy (netflow:MonitorPol)
17 description:
18 - Manage Netflow Monitor Policies for tenants on Cisco ACI fabrics.
19 options:
20 tenant:
21 description:
22 - The name of an existing tenant.
23 type: str
24 aliases: [ tenant_name ]
25 netflow_monitor_policy:
26 description:
27 - The name of the Netflow Monitor Policy.
28 type: str
29 aliases: [ netflow_monitor, netflow_monitor_name, name ]
30 netflow_record_policy:
31 description:
32 - The name of the Netflow Record Policy.
33 - To remove the current Netflow Record Policy, pass an empty string.
34 type: str
35 aliases: [ netflow_record, netflow_record_name ]
36 description:
37 description:
38 - The description for the Netflow Monitor Policy.
39 type: str
40 aliases: [ descr ]
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 - cisco.aci.owner
52
53 notes:
54 - The I(tenant) must exist before using this module in your playbook.
55 The M(cisco.aci.aci_tenant) can be used for this.
56 - If the I(netflow_record_policy) is used, it must exist before using this module in your playbook.
57 The M(cisco.aci.aci_netflow_record_policy) can be used for this.
58 seealso:
59 - module: cisco.aci.aci_tenant
60 - module: cisco.aci.aci_netflow_record_policy
61 - name: APIC Management Information Model reference
62 description: More information about the internal APIC class B(netflow:MonitorPol).
63 link: https://developer.cisco.com/docs/apic-mim-ref/
64 author:
65 - Gaspard Micol (@gmicol)
66 """
67
68 EXAMPLES = r"""
69 - name: Add a new Netflow Monitor Policy
70 cisco.aci.aci_netflow_monitor_policy:
71 host: apic
72 username: admin
73 password: SomeSecretPassword
74 tenant: my_tenant
75 netflow_monitor_policy: my_netflow_monitor_policy
76 netflow_record_policy: my_netflow_record_policy
77 state: present
78 delegate_to: localhost
79
80 - name: Query a Netflow Monitor Policy
81 cisco.aci.aci_netflow_monitor_policy:
82 host: apic
83 username: admin
84 password: SomeSecretPassword
85 tenant: my_tenant
86 netflow_monitor_policy: my_netflow_monitor_policy
87 state: query
88 delegate_to: localhost
89
90 - name: Query all Netflow Monitor Policies in my_tenant
91 cisco.aci.aci_netflow_monitor_policy:
92 host: apic
93 username: admin
94 password: SomeSecretPassword
95 tenant: my_tenant
96 state: query
97 delegate_to: localhost
98
99 - name: Query all Netflow Monitor Policies
100 cisco.aci.aci_netflow_monitor_policy:
101 host: apic
102 username: admin
103 password: SomeSecretPassword
104 state: query
105 delegate_to: localhost
106
107 - name: Delete a Netflow Monitor Policy
108 cisco.aci.aci_netflow_monitor_policy:
109 host: apic
110 username: admin
111 password: SomeSecretPassword
112 tenant: my_tenant
113 netflow_monitor_policy: my_netflow_monitor_policy
114 state: absent
115 delegate_to: localhost
116 """
117
118 RETURN = r"""
119 current:
120 description: The existing configuration from the APIC after the module has finished
121 returned: success
122 type: list
123 sample:
124 [
125 {
126 "fvTenant": {
127 "attributes": {
128 "descr": "Production environment",
129 "dn": "uni/tn-production",
130 "name": "production",
131 "nameAlias": "",
132 "ownerKey": "",
133 "ownerTag": ""
134 }
135 }
136 }
137 ]
138 error:
139 description: The error information as returned from the APIC
140 returned: failure
141 type: dict
142 sample:
143 {
144 "code": "122",
145 "text": "unknown managed object class foo"
146 }
147 raw:
148 description: The raw output returned by the APIC REST API (xml or json)
149 returned: parse error
150 type: str
151 sample: '<?xml version="1.0" encoding="UTF-8"?><imdata totalCount="1"><error code="122" text="unknown managed object class foo"/></imdata>'
152 sent:
153 description: The actual/minimal configuration pushed to the APIC
154 returned: info
155 type: list
156 sample:
157 {
158 "fvTenant": {
159 "attributes": {
160 "descr": "Production environment"
161 }
162 }
163 }
164 previous:
165 description: The original configuration from the APIC before the module has started
166 returned: info
167 type: list
168 sample:
169 [
170 {
171 "fvTenant": {
172 "attributes": {
173 "descr": "Production",
174 "dn": "uni/tn-production",
175 "name": "production",
176 "nameAlias": "",
177 "ownerKey": "",
178 "ownerTag": ""
179 }
180 }
181 }
182 ]
183 proposed:
184 description: The assembled configuration from the user-provided parameters
185 returned: info
186 type: dict
187 sample:
188 {
189 "fvTenant": {
190 "attributes": {
191 "descr": "Production environment",
192 "name": "production"
193 }
194 }
195 }
196 filter_string:
197 description: The filter string used for the request
198 returned: failure or debug
199 type: str
200 sample: ?rsp-prop-include=config-only
201 method:
202 description: The HTTP method used for the request to the APIC
203 returned: failure or debug
204 type: str
205 sample: POST
206 response:
207 description: The HTTP response from the APIC
208 returned: failure or debug
209 type: str
210 sample: OK (30 bytes)
211 status:
212 description: The HTTP status from the APIC
213 returned: failure or debug
214 type: int
215 sample: 200
216 url:
217 description: The HTTP url used for the request to the APIC
218 returned: failure or debug
219 type: str
220 sample: https://10.11.12.13/api/mo/uni/tn-production.json
221 """
222
223
224 from ansible.module_utils.basic import AnsibleModule
225 from ansible_collections.cisco.aci.plugins.module_utils.aci import ACIModule, aci_argument_spec, aci_annotation_spec, aci_owner_spec
226
227
228 def main():
229 argument_spec = aci_argument_spec()
230 argument_spec.update(aci_annotation_spec())
231 argument_spec.update(aci_owner_spec())
232 argument_spec.update(
233 tenant=dict(type="str", aliases=["tenant_name"]),
234 netflow_monitor_policy=dict(type="str", aliases=["netflow_monitor", "netflow_monitor_name", "name"]),
235 netflow_record_policy=dict(type="str", aliases=["netflow_record", "netflow_record_name"]),
236 description=dict(type="str", aliases=["descr"]),
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", ["tenant", "netflow_monitor_policy"]],
245 ["state", "present", ["tenant", "netflow_monitor_policy"]],
246 ],
247 )
248
249 tenant = module.params.get("tenant")
250 description = module.params.get("description")
251 netflow_monitor_policy = module.params.get("netflow_monitor_policy")
252 netflow_record_policy = module.params.get("netflow_record_policy")
253 state = module.params.get("state")
254
255 aci = ACIModule(module)
256
257 child_classes = ["netflowRsMonitorToRecord"]
258
259 aci.construct_url(
260 root_class=dict(
261 aci_class="fvTenant",
262 aci_rn="tn-{0}".format(tenant),
263 module_object=tenant,
264 target_filter={"name": tenant},
265 ),
266 subclass_1=dict(
267 aci_class="netflowMonitorPol",
268 aci_rn="monitorpol-{0}".format(netflow_monitor_policy),
269 module_object=netflow_monitor_policy,
270 target_filter={"name": netflow_monitor_policy},
271 ),
272 child_classes=child_classes,
273 )
274
275 aci.get_existing()
276
277 if state == "present":
278 child_configs = []
279 child_configs.append(dict(netflowRsMonitorToRecord=dict(attributes=dict(tnNetflowRecordPolName=netflow_record_policy))))
280 aci.payload(
281 aci_class="netflowMonitorPol",
282 class_config=dict(
283 name=netflow_monitor_policy,
284 descr=description,
285 ),
286 child_configs=child_configs,
287 )
288
289 aci.get_diff(aci_class="netflowMonitorPol")
290
291 aci.post_config()
292
293 elif state == "absent":
294 aci.delete_config()
295
296 aci.exit_json()
297
298
299 if __name__ == "__main__":
300 main()