Skip to content

Commit

Permalink
fix nxos_igmp_snooping (ansible#31688)
Browse files Browse the repository at this point in the history
Signed-off-by: Trishna Guha <trishnaguha17@gmail.com>
  • Loading branch information
trishnaguha committed Oct 23, 2017
1 parent 8e44cd5 commit 529b7a7
Showing 1 changed file with 30 additions and 22 deletions.
52 changes: 30 additions & 22 deletions lib/ansible/modules/network/nxos/nxos_igmp_snooping.py
Expand Up @@ -110,10 +110,10 @@
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])
Expand All @@ -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)
value = ''
if command in config:
value = REGEX.search(config).group('value')
match = re.search(r' Group timeout configured: (\S+)', config, re.M)
if match:
value = match.group(1)
else:
value = ''
return value


Expand All @@ -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]

if body:
split_body = body.splitlines()
try:
body = execute_show_command(command, module, output='json')[0]
except IndexError:
body = []

if 'no ip igmp snooping' in split_body:
existing['snooping'] = False
else:
if body:
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
Expand Down Expand Up @@ -260,7 +269,6 @@ def main():
if value is not None)

existing = get_igmp_snooping(module)
end_state = existing

commands = []
if state == 'present':
Expand Down

0 comments on commit 529b7a7

Please sign in to comment.