machines: minor refactor of update

This commit is contained in:
Michael Hoang
2025-04-13 18:13:24 +02:00
parent 26fc297598
commit 54e3414cef

View File

@@ -180,27 +180,20 @@ def deploy_machines(machines: list[Machine]) -> None:
if is_async_cancelled(): if is_async_cancelled():
return return
# if the machine is mobile, we retry to deploy with the mobile workaround method
is_mobile = machine.deployment.get("nixosMobileWorkaround", False)
if is_mobile and ret.returncode != 0:
machine.info(
"Mobile machine detected, applying workaround deployment method"
)
ret = host.run(
test_cmd,
RunOpts(msg_color=MsgColor(stderr=AnsiColor.DEFAULT)),
extra_env=env,
become_root=True,
)
# retry nixos-rebuild switch if the first attempt failed # retry nixos-rebuild switch if the first attempt failed
elif ret.returncode != 0: if ret.returncode != 0:
ret = host.run( is_mobile = machine.deployment.get("nixosMobileWorkaround", False)
switch_cmd, # if the machine is mobile, we retry to deploy with the mobile workaround method
RunOpts(msg_color=MsgColor(stderr=AnsiColor.DEFAULT)), if is_mobile:
extra_env=env, machine.info(
become_root=True, "Mobile machine detected, applying workaround deployment method"
) )
ret = host.run(
test_cmd if is_mobile else switch_cmd,
RunOpts(msg_color=MsgColor(stderr=AnsiColor.DEFAULT)),
extra_env=env,
become_root=True,
)
with AsyncRuntime() as runtime: with AsyncRuntime() as runtime:
for machine in machines: for machine in machines: