Skip to content

Commit

Permalink
add get_network_instances
Browse files Browse the repository at this point in the history
  • Loading branch information
afourmy committed Nov 7, 2017
1 parent 30cbfb4 commit 43c3c6e
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions napalm/ios/ios.py
Original file line number Diff line number Diff line change
Expand Up @@ -2146,6 +2146,27 @@ def traceroute(self, destination, source=C.TRACEROUTE_SOURCE,
traceroute_dict['success'] = results
return traceroute_dict

def get_network_instances(self):

instances = {}
command = 'show vrf detail'
output = self._send_command(command)

for vrf in output.split('\n\n'):
first_part = vrf.split('Address family')[0]
# retrieve the name of the VRF and the Route Distinguisher
name, RD = re.match(r'^VRF (\S+).*RD (.*);', first_part).groups()
# retrieve the list of interfaces of the VRF
if_regex = re.match(r'.*Interfaces:(.*)', first_part, re.DOTALL)
interfaces = '' if 'No interfaces' in first_part else if_regex.group(1)
instances[name] = {
'name': name,
'type': 'L3VRF',
'state': {'route_distinguisher': RD},
'interfaces': {int: {} for int in interfaces.split()}
}
return instances

def get_config(self, retrieve='all'):
"""Implementation of get_config for IOS.
Expand Down

0 comments on commit 43c3c6e

Please sign in to comment.