Skip to content

Commit

Permalink
nixos-remote-pxe: add --pause-after-completion flag
Browse files Browse the repository at this point in the history
  • Loading branch information
pogobanane authored and Mic92 committed May 15, 2023
1 parent 7be8cf3 commit a913121
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion nixos-remote-pxe.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ class Options:
dhcp_subnet: int
dhcp_range: Tuple[IPAddress, IPAddress]
pixiecore_http_port: int
pause_after_completion: bool
nixos_anywhere_args: List[str]


Expand Down Expand Up @@ -259,6 +260,11 @@ def parse_args(args: list[str]) -> Options:
default=64172,
type=int,
)
parser.add_argument(
"--pause-after-completion",
help="Whether to wait for user confimation before tearing down the network setup once the installation completed",
action="store_true"
)

parsed, unknown_args = parser.parse_known_args(args)
try:
Expand Down Expand Up @@ -296,6 +302,7 @@ def parse_args(args: list[str]) -> Options:
dhcp_range=(start_ip, stop_ip),
dhcp_interface=parsed.dhcp_interface,
pixiecore_http_port=parsed.pixiecore_http_port,
pause_after_completion=parsed.pause_after_completion,
nixos_anywhere_args=unknown_args,
)

Expand Down Expand Up @@ -366,6 +373,9 @@ def build_pxe_image(netboot_image_flake: str) -> Path:
)
return Path(res.stdout.strip())

def pause():
print("")
input("Press [enter] to terminate this script and tear down the network to the server.")

def run_nixos_remote(options: Options):
pxe_image_store_path = build_pxe_image(options.netboot_image_flake)
Expand Down Expand Up @@ -402,8 +412,13 @@ def run_nixos_remote(options: Options):
)
print(f" ssh -i {ssh_key.private_key} root@{event.ip_addr}")
nixos_remote(event.ip_addr, options.flake, ssh_key.private_key, options.nixos_anywhere_args)
# to avoid having to reboot physical machines all the time because networking disappears:
if (options.pause_after_completion):
print("You can connect to the machine by doing:")
print(f" ssh -i {ssh_key.private_key} root@{event.ip_addr}")
pause()
return
print("after")
print("after") # i dont think this is ever printed, because the loop only exits by returning the entire function
except Exception as e:
print(e)
except KeyboardInterrupt:
Expand Down

0 comments on commit a913121

Please sign in to comment.