Skip to content

Commit

Permalink
Print hostname when not printing an AggregatedResult (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
brasswood authored Oct 27, 2020
1 parent fd9e8e8 commit 3ce6a1a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
22 changes: 18 additions & 4 deletions nornir_utils/plugins/functions/print_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def _print_individual_result(
failed: bool,
severity_level: int,
task_group: bool = False,
print_host: bool = False,
) -> None:
if result.severity_level < severity_level:
return
Expand All @@ -50,7 +51,12 @@ def _print_individual_result(
)
level_name = logging.getLevelName(result.severity_level)
symbol = "v" if task_group else "-"
msg = "{} {}{}".format(symbol * 4, result.name, subtitle)
host = (
f"{result.host.name}: "
if (print_host and result.host and result.host.name)
else ""
)
msg = "{} {}{}{}".format(symbol * 4, host, result.name, subtitle)
print(
"{}{}{}{} {}".format(
Style.BRIGHT, color, msg, symbol * (80 - len(msg)), level_name
Expand All @@ -75,6 +81,7 @@ def _print_result(
attrs: List[str] = None,
failed: bool = False,
severity_level: int = logging.INFO,
print_host: bool = False,
) -> None:
attrs = attrs or ["diff", "result", "stdout"]
if isinstance(attrs, str):
Expand All @@ -96,15 +103,22 @@ def _print_result(
_print_result(host_data, attrs, failed, severity_level)
elif isinstance(result, MultiResult):
_print_individual_result(
result[0], attrs, failed, severity_level, task_group=True
result[0],
attrs,
failed,
severity_level,
task_group=True,
print_host=print_host,
)
for r in result[1:]:
_print_result(r, attrs, failed, severity_level)
color = _get_color(result[0], failed)
msg = "^^^^ END {} ".format(result[0].name)
print("{}{}{}{}".format(Style.BRIGHT, color, msg, "^" * (80 - len(msg))))
elif isinstance(result, Result):
_print_individual_result(result, attrs, failed, severity_level)
_print_individual_result(
result, attrs, failed, severity_level, print_host=print_host
)


def print_result(
Expand All @@ -124,6 +138,6 @@ def print_result(
"""
LOCK.acquire()
try:
_print_result(result, vars, failed, severity_level)
_print_result(result, vars, failed, severity_level, print_host=True)
finally:
LOCK.release()
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_utils"
version = "0.1.0"
version = "0.1.1"
description = "Collection of plugins and functions for nornir that don't require external dependencies"
authors = ["David Barroso <[email protected]>"]
license = "Apache-2.0"
Expand Down

0 comments on commit 3ce6a1a

Please sign in to comment.