Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add source interface parameter to ios_logging #49766

Closed
wants to merge 5 commits into from
Closed
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 26 additions & 2 deletions lib/ansible/modules/network/ios/ios_logging.py
Expand Up @@ -55,6 +55,10 @@
level:
description:
- Set logging severity levels.
source:
description:
- Set logging source interface.
version_added: "2.8"
aggregate:
description: List of logging definitions.
state:
Expand All @@ -70,6 +74,7 @@
ios_logging:
dest: host
name: 172.16.0.1
source: Loopback0
state: present

- name: remove host logging configuration
Expand Down Expand Up @@ -147,6 +152,7 @@ def map_obj_to_commands(updates, module, os_version):
facility = w['facility']
level = w['level']
state = w['state']
source = w['source']
del w['state']

if facility:
Expand All @@ -159,7 +165,6 @@ def map_obj_to_commands(updates, module, os_version):
commands.append('no logging {0}'.format(name))
else:
commands.append('no logging host {0}'.format(name))

elif dest in dest_group:
commands.append('no logging {0}'.format(dest))

Expand All @@ -169,6 +174,9 @@ def map_obj_to_commands(updates, module, os_version):
if facility:
commands.append('no logging facility {0}'.format(facility))

if source:
commands.append('no logging source-interface {0}'.format(source))

if state == 'present' and w not in have:
if facility:
present = False
Expand All @@ -180,6 +188,9 @@ def map_obj_to_commands(updates, module, os_version):
if not present:
commands.append('logging facility {0}'.format(facility))

if source:
commands.append('logging source-interface {0}'.format(source))

if dest == 'host':
if '12.' in os_version:
commands.append('logging {0}'.format(name))
Expand Down Expand Up @@ -267,9 +278,18 @@ def parse_level(line, dest):
return level


def parse_source(line, dest):
if dest == 'source-interface':
match = re.search(r'(source-interface )(\S+)', line, re.M)
if match:
source = match.group(2)

return source


def map_config_to_obj(module):
obj = []
dest_group = ('console', 'host', 'monitor', 'buffered', 'on', 'facility')
dest_group = ('console', 'host', 'monitor', 'buffered', 'on', 'facility', 'source-interface')

data = get_config(module, flags=['| include logging'])

Expand All @@ -284,6 +304,7 @@ def map_config_to_obj(module):
'name': parse_name(line, dest),
'size': parse_size(line, dest),
'facility': parse_facility(line, dest),
'source': parse_source(line, dest),
'level': parse_level(line, dest)
})
elif validate_ip_address(match.group(1)):
Expand Down Expand Up @@ -353,6 +374,7 @@ def map_params_to_obj(module, required_if=None):
'size': module.params['size'],
'facility': module.params['facility'],
'level': module.params['level'],
'source': module.params['source'],
'state': module.params['state']
})

Expand All @@ -363,6 +385,7 @@ def map_params_to_obj(module, required_if=None):
'size': str(validate_size(module.params['size'], module)),
'facility': module.params['facility'],
'level': module.params['level'],
'source': module.params['source'],
'state': module.params['state']
})
return obj
Expand All @@ -375,6 +398,7 @@ def main():
dest=dict(type='str', choices=['on', 'host', 'console', 'monitor', 'buffered']),
name=dict(type='str'),
size=dict(type='int'),
source=dict(type='str'),
facility=dict(type='str'),
level=dict(type='str', default='debugging'),
state=dict(default='present', choices=['present', 'absent']),
Expand Down