nxos_hsrp: fix 'sh_preempt': <unknown enum:> (#52858)
* nxos_hsrp: fix 'sh_preempt': <unknown enum:>
Some older nxos images fail to set this attr value. This fix checks for
unknown enum and issues a second (unstructured) call to the device to get
the data.
* add whitespace for pep8
(cherry picked from commit 5dc65d0dfc
)
This commit is contained in:
parent
0bb0729455
commit
ca5467b5f2
2 changed files with 17 additions and 2 deletions
|
@ -211,6 +211,8 @@ def get_hsrp_group(group, interface, module):
|
||||||
try:
|
try:
|
||||||
body = run_commands(module, [command])[0]
|
body = run_commands(module, [command])[0]
|
||||||
hsrp_table = body['TABLE_grp_detail']['ROW_grp_detail']
|
hsrp_table = body['TABLE_grp_detail']['ROW_grp_detail']
|
||||||
|
if 'unknown enum:' in str(hsrp_table):
|
||||||
|
hsrp_table = get_hsrp_group_unknown_enum(module, command, hsrp_table)
|
||||||
except (AttributeError, IndexError, TypeError, KeyError):
|
except (AttributeError, IndexError, TypeError, KeyError):
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
|
@ -239,6 +241,19 @@ def get_hsrp_group(group, interface, module):
|
||||||
return hsrp
|
return hsrp
|
||||||
|
|
||||||
|
|
||||||
|
def get_hsrp_group_unknown_enum(module, command, hsrp_table):
|
||||||
|
'''Some older NXOS images fail to set the attr values when using structured output and
|
||||||
|
instead set the values to <unknown enum>. This fallback method is a workaround that
|
||||||
|
uses an unstructured (text) request to query the device a second time.
|
||||||
|
'sh_preempt' is currently the only attr affected. Add checks for other attrs as needed.
|
||||||
|
'''
|
||||||
|
if 'unknown enum:' in hsrp_table['sh_preempt']:
|
||||||
|
cmd = {'output': 'text', 'command': command.split('|')[0]}
|
||||||
|
out = run_commands(module, cmd)[0]
|
||||||
|
hsrp_table['sh_preempt'] = 'enabled' if ('may preempt' in out) else 'disabled'
|
||||||
|
return hsrp_table
|
||||||
|
|
||||||
|
|
||||||
def get_commands_remove_hsrp(group, interface):
|
def get_commands_remove_hsrp(group, interface):
|
||||||
commands = ['interface {0}'.format(interface), 'no hsrp {0}'.format(group)]
|
commands = ['interface {0}'.format(interface), 'no hsrp {0}'.format(group)]
|
||||||
return commands
|
return commands
|
||||||
|
|
Loading…
Reference in a new issue