diff --git a/napalm_ios/ios.py b/napalm_ios/ios.py index 0224fb2..b29972a 100644 --- a/napalm_ios/ios.py +++ b/napalm_ios/ios.py @@ -1694,6 +1694,33 @@ def get_ntp_servers(self): return ntp_servers + def get_ntp_peers(self): + """Implementation of get_ntp_peers for IOS. + + Returns the NTP servers configuration as dictionary. + The keys of the dictionary represent the IP Addresses of the servers. + Inner dictionaries do not have yet any available keys. + Example:: + { + '192.168.0.1': {}, + '17.72.148.53': {}, + '37.187.56.220': {}, + '162.158.20.18': {} + } + """ + ntp_peers = {} + command = 'show run | include ntp peer' + output = self._send_command(command) + + for line in output.splitlines(): + split_line = line.split() + if "vrf" == split_line[2]: + ntp_peers[split_line[4]] = {} + else: + ntp_peers[split_line[2]] = {} + + return ntp_peers + def get_ntp_stats(self): """Implementation of get_ntp_stats for IOS.""" ntp_stats = [] diff --git a/test/unit/mocked_data/test_get_ntp_peers/normal/expected_result.json b/test/unit/mocked_data/test_get_ntp_peers/normal/expected_result.json new file mode 100644 index 0000000..32ba098 --- /dev/null +++ b/test/unit/mocked_data/test_get_ntp_peers/normal/expected_result.json @@ -0,0 +1,6 @@ +{ + "2001:DB8:0:0:8:800:200C:417A": {}, + "17.72.148.53": {}, + "192.168.0.1": {}, + "37.187.56.220": {} +} diff --git a/test/unit/mocked_data/test_get_ntp_peers/normal/show_run___include_ntp_peer.txt b/test/unit/mocked_data/test_get_ntp_peers/normal/show_run___include_ntp_peer.txt new file mode 100644 index 0000000..0b6b5a2 --- /dev/null +++ b/test/unit/mocked_data/test_get_ntp_peers/normal/show_run___include_ntp_peer.txt @@ -0,0 +1,4 @@ +ntp peer 192.168.0.1 prefer +ntp peer 17.72.148.53 +ntp peer vrf NAPALM 37.187.56.220 +ntp peer 2001:DB8:0:0:8:800:200C:417A version 4 diff --git a/test/unit/mocked_data/test_get_ntp_servers/normal/expected_result.json b/test/unit/mocked_data/test_get_ntp_servers/normal/expected_result.json index e66f88e..32ba098 100644 --- a/test/unit/mocked_data/test_get_ntp_servers/normal/expected_result.json +++ b/test/unit/mocked_data/test_get_ntp_servers/normal/expected_result.json @@ -1,6 +1,6 @@ { - "2001:DB8:0:0:8:800:200C:417A": {}, - "17.72.148.53": {}, - "192.168.0.1": {}, - "37.187.56.220": {} + "2001:DB8:0:0:8:800:200C:417A": {}, + "17.72.148.53": {}, + "192.168.0.1": {}, + "37.187.56.220": {} }