Debian Codegraph @

ansible_collections/cisco/aci/plugins/modules/aci_syslog_remote_dest.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_syslog_remote_dest
15 short_description: Manage Syslog Remote Destinations (syslog:RemoteDest)
16 description:
17 - Manage remote destinations for syslog messages within an existing syslog group object.
18 options:
19 admin_state:
20 description:
21 - Administrative state of the syslog remote destination
22 type: str
23 choices: [ enabled, disabled ]
24 description:
25 description:
26 - Description of the remote destination
27 type: str
28 destination:
29 description:
30 - Hostname or IP address to send syslog messages to
31 type: str
32 format:
33 description:
34 - Format of the syslog messages
35 type: str
36 choices: [ aci, nxos ]
37 facility:
38 description:
39 - Forwarding facility for syslog messages
40 type: str
41 choices: [ local0, local1, local2, local3, local4, local5, local6, local7 ]
42 group:
43 description:
44 - Name of an existing syslog group
45 type: str
46 aliases: [ syslog_group, syslog_group_name ]
47 mgmt_epg:
48 description:
49 - Name of a management EPG to send syslog messages from
50 type: str
51 name:
52 description:
53 - Name of the syslog remote destination
54 type: str
55 aliases: [ remote_destination_name, remote_destination ]
56 severity:
57 description:
58 - Severity of messages to send to remote syslog
59 type: str
60 choices: [ alerts, critical, debugging, emergencies, error, information, notifications, warnings]
61 state:
62 description:
63 - Use C(present) or C(absent) for adding or removing.
64 - Use C(query) for listing an object or multiple objects.
65 type: str
66 choices: [ absent, present, query ]
67 default: present
68 syslog_port:
69 description:
70 - UDP port to send syslog messages to
71 type: int
72 extends_documentation_fragment:
73 - cisco.aci.aci
74 - cisco.aci.annotation
75
76 seealso:
77 - name: APIC Management Information Model reference
78 description: More information about the internal APIC classes B(syslog:RemoteDest).
79 link: https://developer.cisco.com/docs/apic-mim-ref/
80 author:
81 - Tim Cragg (@timcragg)
82 """
83
84 EXAMPLES = r"""
85 - name: Create a syslog remote destination
86 cisco.aci.aci_syslog_remote_dest:
87 host: apic
88 username: admin
89 password: SomeSecretPassword
90 group: my_syslog_group
91 facility: local7
92 destination: 10.20.30.40
93 syslog_port: 5678
94 mgmt_epg: oob-default
95 state: present
96 delegate_to: localhost
97
98 - name: Delete syslog remote destination
99 cisco.aci.aci_syslog_remote_dest:
100 host: apic
101 username: admin
102 password: SomeSecretPassword
103 group: my_syslog_group
104 destination: 10.20.30.40
105 state: absent
106 delegate_to: localhost
107
108 - name: Query a syslog remote destination
109 cisco.aci.aci_syslog_remote_dest:
110 host: apic
111 username: admin
112 password: SomeSecretPassword
113 group: my_syslog_group
114 destination: 10.20.30.40
115 state: query
116 delegate_to: localhost
117 register: query_result
118
119 - name: Query all syslog remote destinations
120 cisco.aci.aci_syslog_remote_dest:
121 host: apic
122 username: admin
123 password: SomeSecretPassword
124 state: query
125 delegate_to: localhost
126 register: query_result
127 """
128
129 RETURN = r"""
130 current:
131 description: The existing configuration from the APIC after the module has finished
132 returned: success
133 type: list
134 sample:
135 [
136 {
137 "fvTenant": {
138 "attributes": {
139 "descr": "Production environment",
140 "dn": "uni/tn-production",
141 "name": "production",
142 "nameAlias": "",
143 "ownerKey": "",
144 "ownerTag": ""
145 }
146 }
147 }
148 ]
149 error:
150 description: The error information as returned from the APIC
151 returned: failure
152 type: dict
153 sample:
154 {
155 "code": "122",
156 "text": "unknown managed object class foo"
157 }
158 raw:
159 description: The raw output returned by the APIC REST API (xml or json)
160 returned: parse error
161 type: str
162 sample: '<?xml version="1.0" encoding="UTF-8"?><imdata totalCount="1"><error code="122" text="unknown managed object class foo"/></imdata>'
163 sent:
164 description: The actual/minimal configuration pushed to the APIC
165 returned: info
166 type: list
167 sample:
168 {
169 "fvTenant": {
170 "attributes": {
171 "descr": "Production environment"
172 }
173 }
174 }
175 previous:
176 description: The original configuration from the APIC before the module has started
177 returned: info
178 type: list
179 sample:
180 [
181 {
182 "fvTenant": {
183 "attributes": {
184 "descr": "Production",
185 "dn": "uni/tn-production",
186 "name": "production",
187 "nameAlias": "",
188 "ownerKey": "",
189 "ownerTag": ""
190 }
191 }
192 }
193 ]
194 proposed:
195 description: The assembled configuration from the user-provided parameters
196 returned: info
197 type: dict
198 sample:
199 {
200 "fvTenant": {
201 "attributes": {
202 "descr": "Production environment",
203 "name": "production"
204 }
205 }
206 }
207 filter_string:
208 description: The filter string used for the request
209 returned: failure or debug
210 type: str
211 sample: ?rsp-prop-include=config-only
212 method:
213 description: The HTTP method used for the request to the APIC
214 returned: failure or debug
215 type: str
216 sample: POST
217 response:
218 description: The HTTP response from the APIC
219 returned: failure or debug
220 type: str
221 sample: OK (30 bytes)
222 status:
223 description: The HTTP status from the APIC
224 returned: failure or debug
225 type: int
226 sample: 200
227 url:
228 description: The HTTP url used for the request to the APIC
229 returned: failure or debug
230 type: str
231 sample: https://10.11.12.13/api/mo/uni/tn-production.json
232 """
233
234 from ansible_collections.cisco.aci.plugins.module_utils.aci import ACIModule, aci_argument_spec, aci_annotation_spec
235 from ansible.module_utils.basic import AnsibleModule
236
237
238 def main():
239 argument_spec = aci_argument_spec()
240 argument_spec.update(aci_annotation_spec())
241 argument_spec.update(
242 name=dict(type="str", aliases=["remote_destination_name", "remote_destination"]),
243 format=dict(type="str", choices=["aci", "nxos"]),
244 admin_state=dict(type="str", choices=["enabled", "disabled"]),
245 description=dict(type="str"),
246 destination=dict(type="str"),
247 facility=dict(type="str", choices=["local0", "local1", "local2", "local3", "local4", "local5", "local6", "local7"]),
248 group=dict(type="str", aliases=["syslog_group", "syslog_group_name"]),
249 mgmt_epg=dict(type="str"),
250 syslog_port=dict(type="int"),
251 severity=dict(type="str", choices=["alerts", "critical", "debugging", "emergencies", "error", "information", "notifications", "warnings"]),
252 state=dict(type="str", default="present", choices=["absent", "present", "query"]),
253 )
254
255 module = AnsibleModule(
256 argument_spec=argument_spec,
257 supports_check_mode=True,
258 required_if=[
259 ["state", "absent", ["group", "destination"]],
260 ["state", "present", ["group", "destination"]],
261 ],
262 )
263
264 aci = ACIModule(module)
265
266 name = module.params.get("name")
267 format = module.params.get("format")
268 admin_state = module.params.get("admin_state")
269 description = module.params.get("description")
270 destination = module.params.get("destination")
271 facility = module.params.get("facility")
272 group = module.params.get("group")
273 syslog_port = module.params.get("syslog_port")
274 severity = module.params.get("severity")
275 state = module.params.get("state")
276 mgmt_epg = module.params.get("mgmt_epg")
277
278 aci.construct_url(
279 root_class=dict(
280 aci_class="syslogGroup",
281 aci_rn="fabric/slgroup-{0}".format(group),
282 module_object=group,
283 target_filter={"name": group},
284 ),
285 subclass_1=dict(
286 aci_class="syslogRemoteDest",
287 aci_rn="rdst-{0}".format(destination),
288 module_object=destination,
289 target_filter={"host": destination},
290 ),
291 child_classes=["fileRsARemoteHostToEpg"],
292 )
293
294 aci.get_existing()
295
296 if state == "present":
297 child_configs = []
298 if mgmt_epg:
299 child_configs.append(
300 dict(
301 fileRsARemoteHostToEpg=dict(
302 attributes=dict(tDn=("uni/tn-mgmt/mgmtp-default/{0}".format(mgmt_epg))),
303 ),
304 )
305 )
306 aci.payload(
307 aci_class="syslogRemoteDest",
308 class_config=dict(
309 adminState=admin_state,
310 descr=description,
311 format=format,
312 forwardingFacility=facility,
313 host=destination,
314 name=name,
315 port=syslog_port,
316 severity=severity,
317 ),
318 child_configs=child_configs,
319 )
320
321 aci.get_diff(aci_class="syslogRemoteDest")
322
323 aci.post_config()
324
325 elif state == "absent":
326 aci.delete_config()
327
328 aci.exit_json()
329
330
331 if __name__ == "__main__":
332 main()