feature: add --reboot flag for remote operations (except for "reboot")
All checks were successful
/ ruff (push) Successful in 25s
/ black (push) Successful in 26s

Also make the "reboot" operation basically an alias for "boot --reboot"
then and simplify the code of the operations.run function, since it
doesn't need to convert between operation and actual_operation anymore.
This commit is contained in:
June 2024-06-09 00:26:04 +02:00
parent 4afbebcf4a
commit fd9ad17d79
Signed by: june
SSH key fingerprint: SHA256:o9EAq4Y9N9K0pBQeBTqhSDrND5E7oB+60ZNx0U1yPe0
2 changed files with 16 additions and 18 deletions

View file

@ -2,6 +2,8 @@ import click
from infra_rebuild import operations from infra_rebuild import operations
reboot_option_help_text = "Reboot the target hosts after running the operation."
@click.group(context_settings={"help_option_names": ["-h", "--help"]}, invoke_without_command=True) @click.group(context_settings={"help_option_names": ["-h", "--help"]}, invoke_without_command=True)
@click.version_option(prog_name="infra-rebuild") @click.version_option(prog_name="infra-rebuild")
@ -28,24 +30,27 @@ def build_vm_with_bootloader(hosts):
@infra_rebuild.command() @infra_rebuild.command()
@click.option("--reboot", is_flag=True, help=reboot_option_help_text)
@click.argument("hosts", nargs=-1) @click.argument("hosts", nargs=-1)
def switch(hosts): def switch(hosts, reboot):
operations.run("switch", hosts) operations.run("switch", hosts, reboot)
@infra_rebuild.command() @infra_rebuild.command()
@click.option("--reboot", is_flag=True, help=reboot_option_help_text)
@click.argument("hosts", nargs=-1) @click.argument("hosts", nargs=-1)
def boot(hosts): def boot(hosts, reboot):
operations.run("boot", hosts) operations.run("boot", hosts, reboot)
@infra_rebuild.command() @infra_rebuild.command()
@click.option("--reboot", is_flag=True, help=reboot_option_help_text)
@click.argument("hosts", nargs=-1) @click.argument("hosts", nargs=-1)
def test(hosts): def test(hosts, reboot):
operations.run("test", hosts) operations.run("test", hosts, reboot)
@infra_rebuild.command() @infra_rebuild.command()
@click.argument("hosts", nargs=-1) @click.argument("hosts", nargs=-1)
def reboot(hosts): def reboot(hosts):
operations.run("reboot", hosts) operations.run("boot", hosts, True)

View file

@ -6,19 +6,12 @@ import sys
from infra_rebuild import msg from infra_rebuild import msg
def run(operation, hosts): def run(operation, hosts, reboot=False): # noqa: FBT002 - having reboot as a Boolean positional argument is fine I think # fmt: skip
act_remotely = False
reboot = False
match operation: match operation:
case "build" | "build-vm" | "build-vm-with-bootloader": case "build" | "build-vm" | "build-vm-with-bootloader":
actual_operation = operation act_remotely = False
case "switch" | "boot" | "test": case "switch" | "boot" | "test":
act_remotely = True act_remotely = True
actual_operation = operation
case "reboot":
act_remotely = True
actual_operation = "boot"
reboot = True
case _: case _:
msg.error("Internal Error: The given operation isn't valid.") msg.error("Internal Error: The given operation isn't valid.")
sys.exit(1) sys.exit(1)
@ -29,9 +22,9 @@ def run(operation, hosts):
continue continue
if act_remotely: if act_remotely:
remote(actual_operation, host, reboot) remote(operation, host, reboot)
else: else:
local(actual_operation, host) local(operation, host)
def local(operation, host): def local(operation, host):