From e0929283ba44e23bd0e3457dc3a44401a7d081e9 Mon Sep 17 00:00:00 2001 From: pshemk Date: Tue, 30 May 2017 08:44:20 +1200 Subject: [PATCH 1/3] Add ability to view routes in particular table --- napalm_junos/junos.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/napalm_junos/junos.py b/napalm_junos/junos.py index e0ceafa..d853437 100644 --- a/napalm_junos/junos.py +++ b/napalm_junos/junos.py @@ -1101,8 +1101,8 @@ def get_mac_address_table(self): return mac_address_table - def get_route_to(self, destination='', protocol=''): - """Return route details to a specific destination, learned from a certain protocol.""" + def get_route_to(self, destination='', protocol='', table=''): + """Return route details to a specific destination, learned from a certain protocol, visible in a particular table.""" routes = {} if not isinstance(destination, py23_compat.string_types): @@ -1114,6 +1114,9 @@ def get_route_to(self, destination='', protocol=''): if protocol == 'connected': protocol = 'direct' # this is how is called on JunOS + if table and not isinstance(table, py23_compat.string_types): + raise TypeError('Please specify a valid table!') + _COMMON_PROTOCOL_FIELDS_ = [ 'destination', 'prefix_length', @@ -1162,6 +1165,9 @@ def get_route_to(self, destination='', protocol=''): if protocol and isinstance(destination, py23_compat.string_types): rt_kargs['protocol'] = protocol + if table: + rt_kargs['table'] = table + try: routes_table.get(**rt_kargs) except RpcTimeoutError: From 5318cbe5edc659177955a8bba7e0bf0066f25b54 Mon Sep 17 00:00:00 2001 From: pshemk Date: Wed, 31 May 2017 07:29:18 +1200 Subject: [PATCH 2/3] rename table to vrf --- napalm_junos/junos.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/napalm_junos/junos.py b/napalm_junos/junos.py index d853437..4b29961 100644 --- a/napalm_junos/junos.py +++ b/napalm_junos/junos.py @@ -1101,8 +1101,8 @@ def get_mac_address_table(self): return mac_address_table - def get_route_to(self, destination='', protocol='', table=''): - """Return route details to a specific destination, learned from a certain protocol, visible in a particular table.""" + def get_route_to(self, destination='', protocol='', vrf=''): + """Return route details to a specific destination, learned from a certain protocol, visible in a particular vrf (table).""" routes = {} if not isinstance(destination, py23_compat.string_types): @@ -1114,8 +1114,8 @@ def get_route_to(self, destination='', protocol='', table=''): if protocol == 'connected': protocol = 'direct' # this is how is called on JunOS - if table and not isinstance(table, py23_compat.string_types): - raise TypeError('Please specify a valid table!') + if vrf and not isinstance(vrf, py23_compat.string_types): + raise TypeError('Please specify a valid vrf!') _COMMON_PROTOCOL_FIELDS_ = [ 'destination', @@ -1165,8 +1165,8 @@ def get_route_to(self, destination='', protocol='', table=''): if protocol and isinstance(destination, py23_compat.string_types): rt_kargs['protocol'] = protocol - if table: - rt_kargs['table'] = table + if vrf: + rt_kargs['vrf'] = vrf try: routes_table.get(**rt_kargs) From ae983bb3b92823d5bfdcf9dc6b53af1020808161 Mon Sep 17 00:00:00 2001 From: pshemk Date: Wed, 31 May 2017 08:04:41 +1200 Subject: [PATCH 3/3] junos uses 'table' not 'vrf' --- napalm_junos/junos.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/napalm_junos/junos.py b/napalm_junos/junos.py index 4b29961..1b3cb5e 100644 --- a/napalm_junos/junos.py +++ b/napalm_junos/junos.py @@ -1165,8 +1165,9 @@ def get_route_to(self, destination='', protocol='', vrf=''): if protocol and isinstance(destination, py23_compat.string_types): rt_kargs['protocol'] = protocol + #table is (almost) a vrf if vrf: - rt_kargs['vrf'] = vrf + rt_kargs['table'] = vrf try: routes_table.get(**rt_kargs)