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
This commit is contained in:
parent
b1f117ec99
commit
5dc65d0dfc
2 changed files with 17 additions and 2 deletions
|
@ -211,6 +211,8 @@ def get_hsrp_group(group, interface, module):
|
|||
try:
|
||||
body = run_commands(module, [command])[0]
|
||||
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):
|
||||
return {}
|
||||
|
||||
|
@ -239,6 +241,19 @@ def get_hsrp_group(group, interface, module):
|
|||
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):
|
||||
commands = ['interface {0}'.format(interface), 'no hsrp {0}'.format(group)]
|
||||
return commands
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
|
||||
- block:
|
||||
- name: "Enable feature hsrp"
|
||||
nxos_feature:
|
||||
nxos_feature:
|
||||
feature: hsrp
|
||||
provider: "{{ connection }}"
|
||||
state: enabled
|
||||
|
@ -155,7 +155,7 @@
|
|||
|
||||
always:
|
||||
- name: "Disable feature hsrp"
|
||||
nxos_feature:
|
||||
nxos_feature:
|
||||
feature: hsrp
|
||||
provider: "{{ connection }}"
|
||||
state: disabled
|
||||
|
|
Loading…
Reference in a new issue