Skip to content

Commit

Permalink
Set proper types for get_route_to dict fields
Browse files Browse the repository at this point in the history
  • Loading branch information
XioNoX authored and GGabriele committed Jan 27, 2017
1 parent d4267ad commit 857a835
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 14 deletions.
37 changes: 25 additions & 12 deletions napalm_panos/panos.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,9 @@ def get_lldp_neighbors(self):
def get_route_to(self, destination='', protocol=''):
"""Return route details to a specific destination, learned from a certain protocol."""

# Note, it should be possible to query the FIB:
# "<show><routing><fib></fib></routing></show>"
# To add informations to this getter
routes = {}

if destination:
Expand All @@ -437,7 +440,19 @@ def get_route_to(self, destination='', protocol=''):
routes_table = single_item_list

for route in routes_table:
d = {}
d = {
'current_active': False,
'last_active': False,
'age': -1,
'next_hop': u'',
'protocol': u'',
'outgoing_interface': u'',
'preference': -1,
'inactive_reason': u'',
'routing_table': u'default',
'selected_next_hop': False,
'protocol_attributes': {}
}
destination = route['destination']
flags = route['flags']

Expand All @@ -457,18 +472,16 @@ def get_route_to(self, destination='', protocol=''):
d['protocol'] = "ospf"
if 'B' in flags:
d['protocol'] = "bgp"
d['age'] = route['age']
d['next_hop'] = route['nexthop']
d['outgoing_interface'] = route['interface']
if route['metric'] == None:
d['preference'] = 0
else:
if route['age'] is not None:
d['age'] = route['age']
if route['nexthop'] is not None:
d['next_hop'] = route['nexthop']
if route['interface'] is not None:
d['outgoing_interface'] = route['interface']
if route['metric'] is not None:
d['preference'] = route['metric']
d['routing_table'] = route['virtual-router']
d['protocol_attributes'] = {}
d['inactive_reason'] = ""
d['last_active'] = None
d['selected_next_hop'] = None
if route['virtual-router'] is not None:
d['routing_table'] = route['virtual-router']

if destination not in routes.keys():
routes[destination] = []
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"10.22.0.0/16": [{"protocol": "bgp", "current_active": true, "age": "2832970", "routing_table": "default", "next_hop": "10.0.0.1", "outgoing_interface": null, "preference": null, "protocol_attributes": {}, "inactive_reason": "", "last_active": null, "selected_next_hop": null }]}
{"10.22.0.0/16": [{"protocol": "bgp", "last_active": false, "next_hop": "10.0.0.1", "outgoing_interface": "", "preference": -1, "inactive_reason": "", "current_active": true, "age": "2878517", "routing_table": "default", "selected_next_hop": false, "protocol_attributes": {}}]
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"10.0.0.128/30": [{"protocol": "connect","current_active": true,"age": null,"routing_table": "default","next_hop": "10.0.0.1","outgoing_interface": "tunnel.34","preference": "0", "protocol_attributes": {}, "inactive_reason": "", "last_active": null, "selected_next_hop": null }], "192.168.1.1/32": [{"current_active": true,"age": null,"routing_table": "default","next_hop": "0.0.0.0","outgoing_interface": null,"preference": "0", "protocol_attributes": {}, "inactive_reason": "", "last_active": null, "selected_next_hop": null }], "10.0.0.132/30": [{"protocol": "connect","current_active": true,"age": null,"routing_table": "default","next_hop": "10.0.0.2","outgoing_interface": "tunnel.35","preference": "0", "protocol_attributes": {}, "inactive_reason": "", "last_active": null, "selected_next_hop": null }]}
{"10.0.0.128/30": [{"protocol": "connect","current_active": true,"age": -1,"routing_table": "default","next_hop": "10.0.0.1","outgoing_interface": "tunnel.34","preference": "0", "protocol_attributes": {}, "inactive_reason": "", "last_active": false, "selected_next_hop": false }], "192.168.1.1/32": [{"current_active": true,"age": -1,"routing_table": "default","next_hop": "0.0.0.0","outgoing_interface": "","preference": "0", "protocol_attributes": {}, "inactive_reason": "", "last_active": false, "selected_next_hop": false }], "10.0.0.132/30": [{"protocol": "connect","current_active": true,"age": -1,"routing_table": "default","next_hop": "10.0.0.2","outgoing_interface": "tunnel.35","preference": "0", "protocol_attributes": {}, "inactive_reason": "", "last_active": false, "selected_next_hop": false }]}

0 comments on commit 857a835

Please sign in to comment.