Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small fixes #16

Merged
merged 5 commits into from
Jan 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 21 additions & 13 deletions nornir_srl/connections/srlinux.py
Original file line number Diff line number Diff line change
@@ -267,7 +267,8 @@ def augment_routes(d, attribs): # augment routes with attributes
"RIB_IP_JMESPATH": '"network-instance"[].{NI:name, Rib:"bgp-rib"."afi-safi"[]."'
+ ROUTE_FAMILY[route_fam]
+ '"."local-rib"."routes"[]'
+ '.{neighbor:neighbor, "0_st":"_r_state", "Pfx":prefix, "lpref":"local-pref", med:med, "next-hop":"next-hop","as-path":"as-path".segment[0].member, "communities":communities.community}}',
+ '.{neighbor:neighbor, "0_st":"_r_state", "Pfx":prefix, "lpref":"local-pref", med:med, "next-hop":"next-hop","as-path":"as-path".segment[0].member,\
"communities":[communities.community, communities."large-community"][]|join(\',\',@)}}',
},
3: {
"RIB_IP_PATH": (
@@ -277,7 +278,8 @@ def augment_routes(d, attribs): # augment routes with attributes
"RIB_IP_JMESPATH": '"network-instance"[].{NI:name, Rib:"bgp-rib"."afi-safi"[]."'
+ ROUTE_FAMILY[route_fam]
+ '"."local-rib"."route"[]'
+ '.{neighbor:neighbor, "0_st":"_r_state", "Pfx":prefix, "lpref":"local-pref", med:med, "next-hop":"next-hop","as-path":"as-path".segment[0].member, "communities":communities.community}}',
+ '.{neighbor:neighbor, "0_st":"_r_state", "Pfx":prefix, "lpref":"local-pref", med:med, "next-hop":"next-hop","as-path":"as-path".segment[0].member,\
"communities":[communities.community, communities."large-community"][]|join(\',\',@)}}',
},
}

@@ -452,7 +454,7 @@ def get_rib_ipv4(
path_spec = {
"path": f"/network-instance[name={network_instance}]/route-table/ipv4-unicast",
"jmespath": '"network-instance"[?_hasrib].{NI:name, Rib:"route-table"."ipv4-unicast".route[].{"Prefix":"ipv4-prefix",\
"next-hop":"_next-hop",type:"route-type", Act:active, metric:metric, pref:preference, itf:"_nh_itf"}}',
"next-hop":"_next-hop",type:"route-type", Act:active, "orig-vrf":"_orig_vrf",metric:metric, pref:preference, itf:"_nh_itf"}}',
"datatype": "state",
}

@@ -504,7 +506,7 @@ def get_rib_ipv4(
# tmp_map[nhgroup["index"]] = [ nh["next-hop"] for nh in nhgroup["next-hop"] ]
nh_map[nhgroup["index"]] = [
nh_mapping[network_instance][nh.get("next-hop")]
for nh in nhgroup["next-hop"]
for nh in nhgroup.get("next-hop", [])
]
nhgroup_mapping.update({ni["name"]: nh_map})

@@ -540,32 +542,38 @@ def get_rib_ipv4(
else:
route["active"] = "No"
if "next-hop-group" in route:
leaked = False
if "origin-network-instance" in route:
nh_ni = route["origin-network-instance"]
if nh_ni != ni["name"]:
leaked = True
route["_orig_vrf"] = nh_ni
else:
nh_ni = ni["name"]
route["_next-hop"] = [
nh.get("ip-address")
for nh in nhgroup_mapping[ni["name"]][
route["next-hop-group"]
]
for nh in nhgroup_mapping[nh_ni][route["next-hop-group"]]
]

route["_nh_itf"] = [
nh.get("subinterface")
for nh in nhgroup_mapping[ni["name"]][
route["next-hop-group"]
]
nh.get("subinterface") + f"@vrf:{nh_ni}"
if leaked
else nh.get("subinterface")
for nh in nhgroup_mapping[nh_ni][route["next-hop-group"]]
if nh.get("subinterface")
]
if len(route["_nh_itf"]) == 0:
route["_nh_itf"] = [
nh.get("tunnel")
for nh in nhgroup_mapping[ni["name"]][
for nh in nhgroup_mapping[nh_ni][
route["next-hop-group"]
]
if nh.get("tunnel")
]
if len(route["_nh_itf"]) == 0:
resolving_routes = [
nh.get("resolving-route", {})
for nh in nhgroup_mapping[ni["name"]][
for nh in nhgroup_mapping[nh_ni][
route["next-hop-group"]
]
if nh.get("resolving-route")
36 changes: 27 additions & 9 deletions nornir_srl/fsc.py
Original file line number Diff line number Diff line change
@@ -128,11 +128,13 @@ def get_fields(b, depth=0):
def pass_filter(row, filter):
if filter == None:
return True
filter = {str(k).lower(): v for k, v in filter.items()}
if len(
{
k: v
for k, v in row.items()
if filter.get(k) and fnmatch.fnmatch(str(row[k]), str(filter[k]))
if filter.get(str(k).lower())
and fnmatch.fnmatch(str(row[k]), str(filter[str(k).lower()]))
}
) < len(filter):
return False
@@ -242,6 +244,14 @@ def pass_filter(row, filter):
multiple=True,
help="inventory filter, e.g. -i site=lab -i role=leaf. Possible filter-fields are defined in inventory. Multiple filters are ANDed",
)
# @click.option(
# "--format",
# "-f",
# multiple=False,
# type=click.Choice(["table", "json", "yaml"]),
# default="table",
# help="Output format",
# )
@click.option(
"--box-type",
"-b",
@@ -266,6 +276,7 @@ def pass_filter(row, filter):
def cli(
ctx: Context,
cfg: str,
format: Optional[str] = None,
inv_filter: Optional[List] = None,
# field_filter: Optional[List] = None,
box_type: Optional[str] = None,
@@ -364,6 +375,7 @@ def cli(
if box_type:
box_type = box_type.upper()
ctx.obj["box_type"] = box_type
ctx.obj["format"] = format


def print_report(
@@ -411,14 +423,20 @@ def _bgp_peers(task: Task) -> Result:
result = ctx.obj["target"].run(
task=_bgp_peers, name="bgp_peers", raise_on_error=False
)
print_report(
result=result,
name="BGP Peers",
failed_hosts=result.failed_hosts,
box_type=ctx.obj["box_type"],
f_filter=f_filter,
i_filter=ctx.obj["i_filter"],
)
if ctx.obj["format"] == "json":
print_result(result)
elif ctx.obj["format"] == "yaml":
yaml = YAML(typ="safe")
yaml.dump(result, sys.stdout)
else:
print_report(
result=result,
name="BGP Peers",
failed_hosts=result.failed_hosts,
box_type=ctx.obj["box_type"],
f_filter=f_filter,
i_filter=ctx.obj["i_filter"],
)


@cli.command()
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "nornir-srl"
version = "0.2.5"
version = "0.2.6"
description = "Nornir connection plugin for SRLinux"
authors = ["Walter De Smedt <walter.de.smedt@gmail.com>"]
readme = "README.md"