def build_routes(prefixes, nexthops): """ :param prefixes: List of prefixes in string representation :param nexthops: List of nexthops ip addresses in string presentation :returns: list network_types.UnicastRoute (structured routes) :rtype: list """ prefixes = [ipnetwork.ip_str_to_prefix(p) for p in prefixes] nhs = [] for nh_iface in nexthops: iface, addr = None, None # Nexthop may or may not be link-local. Handle it here well if "@" in nh_iface: addr, iface = nh_iface.split("@") elif "%" in nh_iface: addr, iface = nh_iface.split("%") else: addr = nh_iface nexthop = ipnetwork.ip_str_to_addr(addr) nexthop.ifName = iface nhs.append(nexthop) return [ network_types.UnicastRoute( dest=p, deprecatedNexthops=nhs, nextHops=[network_types.NextHopThrift(address=nh) for nh in nhs], ) for p in prefixes ]
def build_routes(prefixes, nexthops): ''' :param prefixes: List of prefixes in string representation :param nexthops: List of nexthops ip addresses in string presentation :returns: list ip_types.UnicastRoute (structured routes) :rtype: list ''' prefixes = [ipnetwork.ip_str_to_prefix(p) for p in prefixes] nhs = [] for nh_iface in nexthops: iface, addr = None, None # Nexthop may or may not be link-local. Handle it here well if '@' in nh_iface: addr, iface = nh_iface.split('@') elif '%' in nh_iface: addr, iface = nh_iface.split('%') else: addr = nh_iface nexthop = ipnetwork.ip_str_to_addr(addr) nexthop.ifName = iface nhs.append(nexthop) return [ip_types.UnicastRoute(dest=p, nexthops=nhs) for p in prefixes]