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

Print hostname when not printing an AggregatedResult #8

Merged
merged 2 commits into from
Oct 27, 2020
Merged
Show file tree
Hide file tree
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
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 <dbarrosop@dravetech.com>"]
license = "Apache-2.0"
Expand Down