Skip to content

Commit

Permalink
blackified
Browse files Browse the repository at this point in the history
  • Loading branch information
wdesmedt committed Jan 16, 2024
1 parent a9a7d79 commit f9fe573
Showing 1 changed file with 27 additions and 10 deletions.
37 changes: 27 additions & 10 deletions nornir_srl/fsc.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +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() }
filter = {str(k).lower(): v for k, v in filter.items()}
if len(
{
k: v
for k, v in row.items()
if filter.get(str(k).lower()) and fnmatch.fnmatch(str(row[k]), str(filter[str(k).lower()]))
if filter.get(str(k).lower())
and fnmatch.fnmatch(str(row[k]), str(filter[str(k).lower()]))
}
) < len(filter):
return False
Expand Down Expand Up @@ -243,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",
Expand All @@ -267,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,
Expand Down Expand Up @@ -365,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(
Expand Down Expand Up @@ -412,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()
Expand Down

0 comments on commit f9fe573

Please sign in to comment.