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

Support multiple destinations in host_copy. #259

Merged
Merged
Changes from 1 commit
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
19 changes: 10 additions & 9 deletions mreg_cli/commands/policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ def host_add(args: argparse.Namespace) -> None:
short_desc="Copy roles between hosts",
flags=[
Flag("source", description="Source host", metavar="SOURCE"),
Flag("destination", description="Destination host", metavar="DESTINATION"),
Flag("destination", description="Destination host", nargs="+", metavar="DESTINATION"),
],
)
def host_copy(args: argparse.Namespace) -> None:
Expand All @@ -326,16 +326,17 @@ def host_copy(args: argparse.Namespace) -> None:
:param args: argparse.Namespace (source, destination)
"""
source_name: str = args.source
destination_name: str = args.destination

source = Host.get_by_any_means_or_raise(source_name)
destination = Host.get_by_any_means_or_raise(destination_name)

for role in source.roles():
role.add_host(destination.name.hostname)
OutputManager().add_line(
f"Copied role {role.name} from {source_name} to {destination_name}"
)
for destination_name in args.destination:
destination = Host.get_by_any_means_or_raise(destination_name)
OutputManager().add_line(f"Copying roles from from {source_name} to {destination_name}")
for role in source.roles():
if role in destination.roles():
OutputManager().add_line(f" + {role.name} (existing membership)")
else:
role.add_host(destination.name.hostname)
OutputManager().add_line(f" + {role.name}")


@command_registry.register_command(
Expand Down
Loading