From 21f0e1cbfc7a7cd7dd8c64e8e9fd7e059c3e56d1 Mon Sep 17 00:00:00 2001 From: Tom Date: Thu, 10 Aug 2017 11:12:09 +0200 Subject: [PATCH 1/5] Add: get_ntp_peers Also updated get_ntp_servers() to return the VRF with the NTP server. --- napalm_ios/ios.py | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/napalm_ios/ios.py b/napalm_ios/ios.py index 0224fb2..dc3811d 100644 --- a/napalm_ios/ios.py +++ b/napalm_ios/ios.py @@ -1672,7 +1672,8 @@ def get_ntp_servers(self): 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. + #Inner dictionaries do not have yet any available keys. + Currently the only available key for the inner dictionaries is 'vrf' in case the NTP server was defined inside a VRF. Example:: { '192.168.0.1': {}, @@ -1688,12 +1689,39 @@ def get_ntp_servers(self): for line in output.splitlines(): split_line = line.split() if "vrf" == split_line[2]: - ntp_servers[split_line[4]] = {} + ntp_servers[split_line[4]] = {'vrf' : split_line[3]} else: ntp_servers[split_line[2]] = {} return ntp_servers + def get_ntp_peers(self): + """Implementation of get_ntp_peers for IOS. + + Returns the NTP peers configuration as dictionary. + The keys of the dictionary represent the IP Addresses of the peers. + Currently the only available key for the inner dictionaries is 'vrf' in case the NTP server was defined inside a VRF. + Example:: + { + '192.168.0.1': {}, + '17.72.148.53': { 'vrf' : 'INTERNET'}, + '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]] = {'vrf' : split_line[3]} + else: + ntp_peers[split_line[2]] = {} + + return ntp_peers + def get_ntp_stats(self): """Implementation of get_ntp_stats for IOS.""" ntp_stats = [] From c4f22df0c9ef519037c93b91a770baf3bc393ef7 Mon Sep 17 00:00:00 2001 From: Tom Marcoen Date: Thu, 10 Aug 2017 11:53:58 +0200 Subject: [PATCH 2/5] PEP8 + test files --- napalm_ios/ios.py | 11 ++++++----- .../test_get_ntp_peers/normal/expected_result.json | 8 ++++++++ .../normal/show_run___include_ntp_peer.txt | 4 ++++ .../test_get_ntp_servers/normal/expected_result.json | 4 +++- 4 files changed, 21 insertions(+), 6 deletions(-) create mode 100644 test/unit/mocked_data/test_get_ntp_peers/normal/expected_result.json create mode 100644 test/unit/mocked_data/test_get_ntp_peers/normal/show_run___include_ntp_peer.txt diff --git a/napalm_ios/ios.py b/napalm_ios/ios.py index dc3811d..8b50d06 100644 --- a/napalm_ios/ios.py +++ b/napalm_ios/ios.py @@ -1672,8 +1672,8 @@ def get_ntp_servers(self): 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. - Currently the only available key for the inner dictionaries is 'vrf' in case the NTP server was defined inside a VRF. + Currently the only available key for the inner dictionaries is 'vrf' in case the NTP + server was defined inside a VRF. Example:: { '192.168.0.1': {}, @@ -1689,7 +1689,7 @@ def get_ntp_servers(self): for line in output.splitlines(): split_line = line.split() if "vrf" == split_line[2]: - ntp_servers[split_line[4]] = {'vrf' : split_line[3]} + ntp_servers[split_line[4]] = {'vrf': split_line[3]} else: ntp_servers[split_line[2]] = {} @@ -1700,7 +1700,8 @@ def get_ntp_peers(self): Returns the NTP peers configuration as dictionary. The keys of the dictionary represent the IP Addresses of the peers. - Currently the only available key for the inner dictionaries is 'vrf' in case the NTP server was defined inside a VRF. + Currently the only available key for the inner dictionaries is 'vrf' in case the NTP + peer was defined inside a VRF. Example:: { '192.168.0.1': {}, @@ -1716,7 +1717,7 @@ def get_ntp_peers(self): for line in output.splitlines(): split_line = line.split() if "vrf" == split_line[2]: - ntp_peers[split_line[4]] = {'vrf' : split_line[3]} + ntp_peers[split_line[4]] = {'vrf': split_line[3]} else: ntp_peers[split_line[2]] = {} 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..8cbc2b1 --- /dev/null +++ b/test/unit/mocked_data/test_get_ntp_peers/normal/expected_result.json @@ -0,0 +1,8 @@ +{ + "2001:DB8:0:0:8:800:200C:417A": {}, + "17.72.148.53": {}, + "192.168.0.1": {}, + "37.187.56.220": [{ + "vrf": "NAPALM" + }] +} 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..8cbc2b1 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 @@ -2,5 +2,7 @@ "2001:DB8:0:0:8:800:200C:417A": {}, "17.72.148.53": {}, "192.168.0.1": {}, - "37.187.56.220": {} + "37.187.56.220": [{ + "vrf": "NAPALM" + }] } From b9322fd414b3fa152867cc39bafb4e13b8a9a9fc Mon Sep 17 00:00:00 2001 From: Tom Marcoen Date: Thu, 10 Aug 2017 14:43:43 +0200 Subject: [PATCH 3/5] Remove VRF support from the model to remain consistent with other drivers. --- napalm_ios/ios.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/napalm_ios/ios.py b/napalm_ios/ios.py index 8b50d06..b29972a 100644 --- a/napalm_ios/ios.py +++ b/napalm_ios/ios.py @@ -1672,8 +1672,7 @@ def get_ntp_servers(self): Returns the NTP servers configuration as dictionary. The keys of the dictionary represent the IP Addresses of the servers. - Currently the only available key for the inner dictionaries is 'vrf' in case the NTP - server was defined inside a VRF. + Inner dictionaries do not have yet any available keys. Example:: { '192.168.0.1': {}, @@ -1689,7 +1688,7 @@ def get_ntp_servers(self): for line in output.splitlines(): split_line = line.split() if "vrf" == split_line[2]: - ntp_servers[split_line[4]] = {'vrf': split_line[3]} + ntp_servers[split_line[4]] = {} else: ntp_servers[split_line[2]] = {} @@ -1698,14 +1697,13 @@ def get_ntp_servers(self): def get_ntp_peers(self): """Implementation of get_ntp_peers for IOS. - Returns the NTP peers configuration as dictionary. - The keys of the dictionary represent the IP Addresses of the peers. - Currently the only available key for the inner dictionaries is 'vrf' in case the NTP - peer was defined inside a VRF. + 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': { 'vrf' : 'INTERNET'}, + '17.72.148.53': {}, '37.187.56.220': {}, '162.158.20.18': {} } @@ -1717,7 +1715,7 @@ def get_ntp_peers(self): for line in output.splitlines(): split_line = line.split() if "vrf" == split_line[2]: - ntp_peers[split_line[4]] = {'vrf': split_line[3]} + ntp_peers[split_line[4]] = {} else: ntp_peers[split_line[2]] = {} From 62faeb436e94290be2405a1a3ecbe15255647f26 Mon Sep 17 00:00:00 2001 From: Mircea Ulinic Date: Mon, 4 Sep 2017 11:12:12 +0100 Subject: [PATCH 4/5] Revert mocked data for get_ntp_peers --- .../test_get_ntp_peers/normal/expected_result.json | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) 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 index 8cbc2b1..32ba098 100644 --- 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 @@ -1,8 +1,6 @@ { - "2001:DB8:0:0:8:800:200C:417A": {}, - "17.72.148.53": {}, - "192.168.0.1": {}, - "37.187.56.220": [{ - "vrf": "NAPALM" - }] + "2001:DB8:0:0:8:800:200C:417A": {}, + "17.72.148.53": {}, + "192.168.0.1": {}, + "37.187.56.220": {} } From 1a4640c352f12020276e308e26ee866d603e4e08 Mon Sep 17 00:00:00 2001 From: Mircea Ulinic Date: Mon, 4 Sep 2017 11:12:53 +0100 Subject: [PATCH 5/5] Revert mocked data for get_ntp_servers --- .../test_get_ntp_servers/normal/expected_result.json | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) 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 8cbc2b1..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,8 +1,6 @@ { - "2001:DB8:0:0:8:800:200C:417A": {}, - "17.72.148.53": {}, - "192.168.0.1": {}, - "37.187.56.220": [{ - "vrf": "NAPALM" - }] + "2001:DB8:0:0:8:800:200C:417A": {}, + "17.72.148.53": {}, + "192.168.0.1": {}, + "37.187.56.220": {} }