fix nxos_igmp_snooping (#31688)

Signed-off-by: Trishna Guha <trishnaguha17@gmail.com>
pull/31818/head
Trishna Guha 7 years ago committed by GitHub
parent 8e44cd5d10
commit 529b7a7b78

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

Loading…
Cancel
Save