Skip to content

Commit

Permalink
eos: support using json version of show vrf
Browse files Browse the repository at this point in the history
If version of EOS is new enough (>= 4.23.0), use the JSON output of
"show vrf" to avoid issues with text parsing in 4.28+

Anecdotal evidence suggests that "default" was added to the text output
of "show vrf" in 4.23, so this also resolves the double route issue in
1919.

closes #1919
  • Loading branch information
bewing committed May 16, 2023
1 parent cdba45f commit db75a36
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 1 deletion.
22 changes: 21 additions & 1 deletion napalm/eos/eos.py
Original file line number Diff line number Diff line change
Expand Up @@ -2118,7 +2118,21 @@ def get_config(self, retrieve="all", full=False, sanitized=False):
else:
raise Exception("Wrong retrieve filter: {}".format(retrieve))

def _show_vrf(self):
def _show_vrf_json(self):
commands = ["show vrf"]

vrfs = self._run_commands(commands)[0]["vrfs"]
return [
{
"name": k,
"interfaces": [i for i in v["interfaces"]],
"route_distinguisher": v["routeDistinguisher"],
}
for k, v in vrfs.items()
]


def _show_vrf_text(self):
commands = ["show vrf"]

# This command has no JSON in EOS < 4.23
Expand Down Expand Up @@ -2153,6 +2167,12 @@ def _show_vrf(self):

return vrfs

def _show_vrf(self):
if self.cli_version == 2:
return self._show_vrf_json()
else:
return self._show_vrf_text()

def _get_vrfs(self):
output = self._show_vrf()

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"default": {
"name": "default",
"type": "DEFAULT_INSTANCE",
"state": { "route_distinguisher": "" },
"interfaces": {
"interface": {
"Ethernet1": {},
"Ethernet2": {},
"Loopback0": {},
"Management0": {}
}
}
},
"foo": {
"name": "foo",
"type": "L3VRF",
"state": { "route_distinguisher": "0:1" },
"interfaces": {
"interface": {}
}
},
"bar": {
"name": "bar",
"type": "L3VRF",
"state": { "route_distinguisher": "" },
"interfaces": {
"interface": {}
}
}
}
61 changes: 61 additions & 0 deletions test/eos/mocked_data/test_get_network_instances/vrf/show_vrf.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{
"vrfs": {
"foo": {
"routeDistinguisher": "0:1",
"protocols": {
"ipv4": {
"supported": true,
"protocolState": "up",
"routingState": "up"
},
"ipv6": {
"supported": true,
"protocolState": "up",
"routingState": "down"
}
},
"vrfState": "up",
"interfacesV4": [],
"interfacesV6": [],
"interfaces": []
},
"bar": {
"routeDistinguisher": "",
"protocols": {
"ipv4": {
"supported": true,
"protocolState": "up",
"routingState": "down"
},
"ipv6": {
"supported": true,
"protocolState": "up",
"routingState": "down"
}
},
"vrfState": "up",
"interfacesV4": [],
"interfacesV6": [],
"interfaces": []
},
"default": {
"routeDistinguisher": "",
"protocols": {
"ipv4": {
"supported": true,
"protocolState": "up",
"routingState": "up"
},
"ipv6": {
"supported": true,
"protocolState": "up",
"routingState": "down"
}
},
"vrfState": "up",
"interfacesV4": ["Ethernet1", "Ethernet2", "Loopback0", "Management0"],
"interfacesV6": ["Management0"],
"interfaces": ["Ethernet1", "Ethernet2", "Loopback0", "Management0"]
}
}
}

0 comments on commit db75a36

Please sign in to comment.