# Buggy code
def get_route_to(self, destination="", protocol="", longer=False):
    routes = {}

    # Placeholder for vrf arg
    vrf = ""

    # Right not iterating through vrfs is necessary
    # show ipv6 route doesn't support vrf 'all'
    if vrf == "":
        vrfs = sorted(self._get_vrfs())
    else:
        vrfs = [vrf]

    if protocol.lower() == "direct":
        protocol = "connected"

    ipv = ""
    if IPNetwork(destination).version == 6:
        ipv = "v6"

    commands = []
    for _vrf in vrfs:
        commands.append(
            "show ip{ipv} route vrf {_vrf} {destination} {longer} {protocol} detail".format(
                ipv=ipv,
                _vrf=_vrf,
                destination=destination,
                longer="longer-prefixes" if longer else "",
                protocol=protocol,
            )
        )

    commands_output = self.device.run_commands(commands)
    vrf_cache = {}

    for _vrf, command_output in zip(vrfs, commands_output):
        if ipv == "v6":
            routes_out = command_output.get("routes", {})
        else:
            routes_out = command_output.get("vrfs", {}).get(_vrf, {}).get("routes", {})

        for prefix, route_details in routes_out.items():
            if prefix not in routes.keys():
                routes[prefix] = []
            route_protocol = route_details.get("routeType")
            preference = route_details.get("preference", 0)

            route = {
                "current_active": True,
                "last_active": True,
                "age": 0,
                "next_hop": "",
                "protocol": route_protocol,
                "outgoing_interface": "",
                "preference": preference,
                "inactive_reason": "",
                "routing_table": _vrf,
                "selected_next_hop": True,
                "protocol_attributes": {},
            }
            if protocol == "bgp" or route_protocol.lower() in ("ebgp", "ibgp"):
                nexthop_interface_map = {}
                for next_hop in route_details.get("vias"):
                    nexthop_ip = napalm.base.helpers.ip(next_hop.get("nexthopAddr"))
                    nexthop_interface_map[nexthop_ip] = next_hop.get("interface")
                metric = route_details.get("metric")
                if _vrf not in vrf_cache.keys():
                    try:
                        command = (
                            "show ip{ipv} bgp {dest} {longer} detail vrf {_vrf}".format(
                                ipv=ipv,
                                dest=destination,
                                longer="longer-prefixes" if longer else "",
                                _vrf=_vrf,
                            )
                        )
                        vrf_cache.update(
                            {
                                _vrf: self.device.run_commands([command])[0]
                                .get("vrfs", {})
                                .get(_vrf, {})
                            }
                        )
                    except CommandError:
                        # Newer EOS can't mix longer-prefix and detail
                        command = "show ip{ipv} bgp {dest} {longer} vrf {_vrf}".format(
                            ipv=ipv,
                            dest=destination,
                            longer="longer-prefixes" if longer else "",
                            _vrf=_vrf,
                        )
                        vrf_cache.update(
                            {
                                _vrf: self.device.run_commands([command])[0]
                                .get("vrfs", {})
                                .get(_vrf, {})
                            }
                        )

                vrf_details = vrf_cache.get(_vrf)
                local_as = napalm.base.helpers.as_number(vrf_details.get("asn"))
                bgp_routes = (
                    vrf_details.get("bgpRouteEntries", {})
                    .get(prefix, {})
                    .get("bgpRoutePaths", [])
                )
                for bgp_route_details in bgp_routes:
                    bgp_route = route.copy()
                    as_path = bgp_route_details.get("asPathEntry", {}).get("asPath", "")
                    as_path_type = bgp_route_details.get("asPathEntry", {}).get(
                        "asPathType", ""
                    )
                    if as_path_type in ["Internal", "Local"]:
                        remote_as = local_as
                    else:
                        remote_as = napalm.base.helpers.as_number(
                            as_path.strip("()").split()[-1]
                        )
                    remote_address = napalm.base.helpers.ip(
                        bgp_route_details.get("routeDetail", {})
                        .get("peerEntry", {})
                        .get("peerAddr", "")
                    )
                    local_preference = bgp_route_details.get("localPreference")
                    next_hop = napalm.base.helpers.ip(bgp_route_details.get("nextHop"))
                    active_route = bgp_route_details.get("routeType", {}).get(
                        "active", False
                    )
                    last_active = active_route  # should find smth better
                    communities = bgp_route_details.get("routeDetail", {}).get(
                        "communityList", []
                    )
                    preference2 = bgp_route_details.get("weight")
                    inactive_reason = bgp_route_details.get("reasonNotBestpath", "")
                    bgp_route.update(
                        {
                            "current_active": active_route,
                            "inactive_reason": inactive_reason,
                            "last_active": last_active,
                            "next_hop": next_hop,
                            "outgoing_interface": nexthop_interface_map.get(next_hop),
                            "selected_next_hop": active_route,
                            "protocol_attributes": {
                                "metric": metric,
                                "as_path": as_path,
                                "local_preference": local_preference,
                                "local_as": local_as,
                                "remote_as": remote_as,
                                "remote_address": remote_address,
                                "preference2": preference2,
                                "communities": communities,
                            },
                        }
                    )
                    routes[prefix].append(bgp_route)
            else:
                if route_details.get("routeAction") in ("drop",):
                    route["next_hop"] = "NULL"
                if route_details.get("routingDisabled") is True:
                    route["last_active"] = False
                    route["current_active"] = False
                for next_hop in route_details.get("vias"):
                    route_next_hop = route.copy()
                    if next_hop.get("nexthopAddr") is None:
                        route_next_hop.update(
                            {
                                "next_hop": "",
                                "outgoing_interface": next_hop.get("interface"),
                            }
                        )
                    else:
                        route_next_hop.update(
                            {
                                "next_hop": napalm.base.helpers.ip(
                                    next_hop.get("nexthopAddr")
                                ),
                                "outgoing_interface": next_hop.get("interface"),
                            }
                        )
                    routes[prefix].append(route_next_hop)
                if route_details.get("vias") == []:  # empty list
                    routes[prefix].append(route)
    return routes


# Traceback (netaddr.core.AddrFormatError)
Traceback (most recent call last):
File "eos2.py", line 7, in <module>
dev_info = dev.get_route_to(u'3.3.3.3/32')
File "/usr/local/lib/python2.7/dist-packages/napalm/eos/eos.py", line 1258, in get_route_to
.get("peerAddr", "")
File "/usr/local/lib/python2.7/dist-packages/napalm/base/helpers.py", line 330, in ip
addr_obj = IPAddress(addr)
File "/usr/local/lib/python2.7/dist-packages/netaddr/ip/__init__.py", line 306, in __init__
'address from %r' % addr)
netaddr.core.AddrFormatError: failed to detect a valid IP address from u''

# Fixed code
def get_route_to(self, destination="", protocol="", longer=False):
    routes = {}

    # Placeholder for vrf arg
    vrf = ""

    # Right not iterating through vrfs is necessary
    # show ipv6 route doesn't support vrf 'all'
    if vrf == "":
        vrfs = sorted(self._get_vrfs())
    else:
        vrfs = [vrf]

    if protocol.lower() == "direct":
        protocol = "connected"

    ipv = ""
    if IPNetwork(destination).version == 6:
        ipv = "v6"

    commands = []
    for _vrf in vrfs:
        commands.append(
            "show ip{ipv} route vrf {_vrf} {destination} {longer} {protocol} detail".format(
                ipv=ipv,
                _vrf=_vrf,
                destination=destination,
                longer="longer-prefixes" if longer else "",
                protocol=protocol,
            )
        )

    commands_output = self.device.run_commands(commands)
    vrf_cache = {}

    for _vrf, command_output in zip(vrfs, commands_output):
        if ipv == "v6":
            routes_out = command_output.get("routes", {})
        else:
            routes_out = command_output.get("vrfs", {}).get(_vrf, {}).get("routes", {})

        for prefix, route_details in routes_out.items():
            if prefix not in routes.keys():
                routes[prefix] = []
            route_protocol = route_details.get("routeType")
            preference = route_details.get("preference", 0)

            route = {
                "current_active": True,
                "last_active": True,
                "age": 0,
                "next_hop": "",
                "protocol": route_protocol,
                "outgoing_interface": "",
                "preference": preference,
                "inactive_reason": "",
                "routing_table": _vrf,
                "selected_next_hop": True,
                "protocol_attributes": {},
            }
            if protocol == "bgp" or route_protocol.lower() in ("ebgp", "ibgp"):
                nexthop_interface_map = {}
                for next_hop in route_details.get("vias"):
                    nexthop_ip = napalm.base.helpers.ip(next_hop.get("nexthopAddr"))
                    nexthop_interface_map[nexthop_ip] = next_hop.get("interface")
                metric = route_details.get("metric")
                if _vrf not in vrf_cache.keys():
                    try:
                        command = (
                            "show ip{ipv} bgp {dest} {longer} detail vrf {_vrf}".format(
                                ipv=ipv,
                                dest=destination,
                                longer="longer-prefixes" if longer else "",
                                _vrf=_vrf,
                            )
                        )
                        vrf_cache.update(
                            {
                                _vrf: self.device.run_commands([command])[0]
                                .get("vrfs", {})
                                .get(_vrf, {})
                            }
                        )
                    except CommandError:
                        # Newer EOS can't mix longer-prefix and detail
                        command = "show ip{ipv} bgp {dest} {longer} vrf {_vrf}".format(
                            ipv=ipv,
                            dest=destination,
                            longer="longer-prefixes" if longer else "",
                            _vrf=_vrf,
                        )
                        vrf_cache.update(
                            {
                                _vrf: self.device.run_commands([command])[0]
                                .get("vrfs", {})
                                .get(_vrf, {})
                            }
                        )

                vrf_details = vrf_cache.get(_vrf)
                local_as = napalm.base.helpers.as_number(vrf_details.get("asn"))
                bgp_routes = (
                    vrf_details.get("bgpRouteEntries", {})
                    .get(prefix, {})
                    .get("bgpRoutePaths", [])
                )
                for bgp_route_details in bgp_routes:
                    bgp_route = route.copy()
                    as_path = bgp_route_details.get("asPathEntry", {}).get("asPath", "")
                    as_path_type = bgp_route_details.get("asPathEntry", {}).get(
                        "asPathType", ""
                    )
                    if as_path_type in ["Internal", "Local"]:
                        remote_as = local_as
                    else:
                        remote_as = napalm.base.helpers.as_number(
                            as_path.strip("()").split()[-1]
                        )
                    try:
                        remote_address = napalm.base.helpers.ip(
                            bgp_route_details.get("routeDetail", {})
                            .get("peerEntry", {})
                            .get("peerAddr", "")
                        )
                    except AddrFormatError:
                        remote_address = napalm.base.helpers.ip(
                            bgp_route_details.get("peerEntry", {}).get("peerAddr", "")
                        )
                    local_preference = bgp_route_details.get("localPreference")
                    next_hop = napalm.base.helpers.ip(bgp_route_details.get("nextHop"))
                    active_route = bgp_route_details.get("routeType", {}).get(
                        "active", False
                    )
                    last_active = active_route  # should find smth better
                    communities = bgp_route_details.get("routeDetail", {}).get(
                        "communityList", []
                    )
                    preference2 = bgp_route_details.get("weight")
                    inactive_reason = bgp_route_details.get("reasonNotBestpath", "")
                    bgp_route.update(
                        {
                            "current_active": active_route,
                            "inactive_reason": inactive_reason,
                            "last_active": last_active,
                            "next_hop": next_hop,
                            "outgoing_interface": nexthop_interface_map.get(next_hop),
                            "selected_next_hop": active_route,
                            "protocol_attributes": {
                                "metric": metric,
                                "as_path": as_path,
                                "local_preference": local_preference,
                                "local_as": local_as,
                                "remote_as": remote_as,
                                "remote_address": remote_address,
                                "preference2": preference2,
                                "communities": communities,
                            },
                        }
                    )
                    routes[prefix].append(bgp_route)
            else:
                if route_details.get("routeAction") in ("drop",):
                    route["next_hop"] = "NULL"
                if route_details.get("routingDisabled") is True:
                    route["last_active"] = False
                    route["current_active"] = False
                for next_hop in route_details.get("vias"):
                    route_next_hop = route.copy()
                    if next_hop.get("nexthopAddr") is None:
                        route_next_hop.update(
                            {
                                "next_hop": "",
                                "outgoing_interface": next_hop.get("interface"),
                            }
                        )
                    else:
                        route_next_hop.update(
                            {
                                "next_hop": napalm.base.helpers.ip(
                                    next_hop.get("nexthopAddr")
                                ),
                                "outgoing_interface": next_hop.get("interface"),
                            }
                        )
                    routes[prefix].append(route_next_hop)
                if route_details.get("vias") == []:  # empty list
                    routes[prefix].append(route)
    return routes