1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

fix nxos_igmp_snooping (#31688)

Signed-off-by: Trishna Guha <trishnaguha17@gmail.com>
This commit is contained in:
Trishna Guha 2017-10-23 09:40:07 +05:30 committed by GitHub
parent 8e44cd5d10
commit 529b7a7b78

View file

@ -110,10 +110,10 @@ from ansible.module_utils.nxos import nxos_argument_spec, check_args
from ansible.module_utils.basic import AnsibleModule
def execute_show_command(command, module):
def execute_show_command(command, module, output='text'):
command = {
'command': command,
'output': 'text',
'output': output,
}
return run_commands(module, [command])
@ -130,11 +130,11 @@ def flatten_list(command_lists):
def get_group_timeout(config):
command = 'ip igmp snooping group-timeout'
REGEX = re.compile(r'(?:{0}\s)(?P<value>.*)$'.format(command), re.M)
match = re.search(r' Group timeout configured: (\S+)', config, re.M)
if match:
value = match.group(1)
else:
value = ''
if command in config:
value = REGEX.search(config).group('value')
return value
@ -150,33 +150,42 @@ def get_snooping(config):
def get_igmp_snooping(module):
command = 'show run all | include igmp.snooping'
command = 'show ip igmp snooping'
existing = {}
body = execute_show_command(command, module)[0]
try:
body = execute_show_command(command, module, output='json')[0]
except IndexError:
body = []
if body:
split_body = body.splitlines()
if 'no ip igmp snooping' in split_body:
existing['snooping'] = False
else:
snooping = str(body.get('enabled')).lower()
if snooping == 'true' or snooping == 'enabled':
existing['snooping'] = True
else:
existing['snooping'] = False
if 'no ip igmp snooping report-suppression' in split_body:
existing['report_supp'] = False
elif 'ip igmp snooping report-suppression' in split_body:
report_supp = str(body.get('grepsup')).lower()
if report_supp == 'true' or report_supp == 'enabled':
existing['report_supp'] = True
else:
existing['report_supp'] = False
if 'no ip igmp snooping link-local-groups-suppression' in split_body:
existing['link_local_grp_supp'] = False
elif 'ip igmp snooping link-local-groups-suppression' in split_body:
link_local_grp_supp = str(body.get('glinklocalgrpsup')).lower()
if link_local_grp_supp == 'true' or link_local_grp_supp == 'enabled':
existing['link_local_grp_supp'] = True
else:
existing['link_local_grp_supp'] = False
if 'ip igmp snooping v3-report-suppression' in split_body:
v3_report_supp = str(body.get('gv3repsup')).lower()
if v3_report_supp == 'true' or v3_report_supp == 'enabled':
existing['v3_report_supp'] = True
else:
existing['v3_report_supp'] = False
command = 'show ip igmp snooping'
body = execute_show_command(command, module)[0]
if body:
existing['group_timeout'] = get_group_timeout(body)
return existing
@ -260,7 +269,6 @@ def main():
if value is not None)
existing = get_igmp_snooping(module)
end_state = existing
commands = []
if state == 'present':