Fixing nxos_ntp when no config exists (#19678)
This commit is contained in:
parent
962a592628
commit
c58278b1c2
1 changed files with 38 additions and 36 deletions
|
@ -400,49 +400,51 @@ def get_ntp_peer(module):
|
||||||
command = 'show run | inc ntp.(server|peer)'
|
command = 'show run | inc ntp.(server|peer)'
|
||||||
ntp_peer_list = []
|
ntp_peer_list = []
|
||||||
ntp = execute_show_command(
|
ntp = execute_show_command(
|
||||||
command, module, command_type='cli_show_ascii')[0]
|
command, module, command_type='cli_show_ascii')
|
||||||
|
if ntp:
|
||||||
|
ntp = ntp[0]
|
||||||
|
|
||||||
ntp_regex = (
|
ntp_regex = (
|
||||||
".*ntp\s(server\s(?P<address>\S+)|peer\s(?P<peer_address>\S+))"
|
".*ntp\s(server\s(?P<address>\S+)|peer\s(?P<peer_address>\S+))"
|
||||||
"\s*((?P<prefer>prefer)\s*)?(use-vrf\s(?P<vrf_name>\S+)\s*)?"
|
"\s*((?P<prefer>prefer)\s*)?(use-vrf\s(?P<vrf_name>\S+)\s*)?"
|
||||||
"(key\s(?P<key_id>\d+))?.*"
|
"(key\s(?P<key_id>\d+))?.*"
|
||||||
)
|
)
|
||||||
|
|
||||||
split_ntp = ntp.splitlines()
|
split_ntp = ntp.splitlines()
|
||||||
for peer_line in split_ntp:
|
for peer_line in split_ntp:
|
||||||
ntp_peer = {}
|
ntp_peer = {}
|
||||||
try:
|
try:
|
||||||
peer_address = None
|
peer_address = None
|
||||||
vrf_name = None
|
vrf_name = None
|
||||||
prefer = None
|
prefer = None
|
||||||
key_id = None
|
key_id = None
|
||||||
match_ntp = re.match(ntp_regex, peer_line, re.DOTALL)
|
match_ntp = re.match(ntp_regex, peer_line, re.DOTALL)
|
||||||
group_ntp = match_ntp.groupdict()
|
group_ntp = match_ntp.groupdict()
|
||||||
|
|
||||||
address = group_ntp["address"]
|
address = group_ntp["address"]
|
||||||
peer_address = group_ntp['peer_address']
|
peer_address = group_ntp['peer_address']
|
||||||
prefer = group_ntp['prefer']
|
prefer = group_ntp['prefer']
|
||||||
vrf_name = group_ntp['vrf_name']
|
vrf_name = group_ntp['vrf_name']
|
||||||
key_id = group_ntp['key_id']
|
key_id = group_ntp['key_id']
|
||||||
|
|
||||||
if prefer is not None:
|
if prefer is not None:
|
||||||
prefer = 'enabled'
|
prefer = 'enabled'
|
||||||
else:
|
else:
|
||||||
prefer = 'disabled'
|
prefer = 'disabled'
|
||||||
|
|
||||||
if address is not None:
|
if address is not None:
|
||||||
peer_type = 'server'
|
peer_type = 'server'
|
||||||
elif peer_address is not None:
|
elif peer_address is not None:
|
||||||
peer_type = 'peer'
|
peer_type = 'peer'
|
||||||
address = peer_address
|
address = peer_address
|
||||||
|
|
||||||
args = dict(peer_type=peer_type, address=address, prefer=prefer,
|
args = dict(peer_type=peer_type, address=address, prefer=prefer,
|
||||||
vrf_name=vrf_name, key_id=key_id)
|
vrf_name=vrf_name, key_id=key_id)
|
||||||
|
|
||||||
ntp_peer = dict((k, v) for k, v in args.items())
|
ntp_peer = dict((k, v) for k, v in args.items())
|
||||||
ntp_peer_list.append(ntp_peer)
|
ntp_peer_list.append(ntp_peer)
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
ntp_peer_list = []
|
ntp_peer_list = []
|
||||||
|
|
||||||
return ntp_peer_list
|
return ntp_peer_list
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue