Skip to content

Commit 8d755b0

Browse files
authored
Add aci_syslog_source and aci_syslog_remote_dest modules and test files (#174)
1 parent df52f3e commit 8d755b0

File tree

7 files changed

+998
-0
lines changed

7 files changed

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

0 commit comments

Comments
 (0)