API: init install machine
This commit is contained in:
@@ -3,10 +3,12 @@ import importlib
|
|||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass, field
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from tempfile import TemporaryDirectory
|
from tempfile import TemporaryDirectory
|
||||||
|
|
||||||
|
from clan_cli.api import API
|
||||||
|
|
||||||
from ..clan_uri import FlakeId
|
from ..clan_uri import FlakeId
|
||||||
from ..cmd import Log, run
|
from ..cmd import Log, run
|
||||||
from ..completions import add_dynamic_completer, complete_machines
|
from ..completions import add_dynamic_completer, complete_machines
|
||||||
@@ -91,15 +93,30 @@ def install_nixos(
|
|||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class InstallOptions:
|
class InstallOptions:
|
||||||
|
# flake to install
|
||||||
flake: FlakeId
|
flake: FlakeId
|
||||||
machine: str
|
machine: str
|
||||||
target_host: str
|
target_host: str
|
||||||
kexec: str | None
|
kexec: str | None = None
|
||||||
confirm: bool
|
debug: bool = False
|
||||||
debug: bool
|
no_reboot: bool = False
|
||||||
no_reboot: bool
|
json_ssh_deploy: dict[str, str] | None = None
|
||||||
json_ssh_deploy: dict[str, str] | None
|
nix_options: list[str] = field(default_factory=list)
|
||||||
nix_options: list[str]
|
|
||||||
|
|
||||||
|
@API.register
|
||||||
|
def install_machine(opts: InstallOptions, password: str | None) -> None:
|
||||||
|
machine = Machine(opts.machine, flake=opts.flake)
|
||||||
|
machine.target_host_address = opts.target_host
|
||||||
|
|
||||||
|
install_nixos(
|
||||||
|
machine,
|
||||||
|
kexec=opts.kexec,
|
||||||
|
debug=opts.debug,
|
||||||
|
password=password,
|
||||||
|
no_reboot=opts.no_reboot,
|
||||||
|
extra_args=opts.nix_options,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def install_command(args: argparse.Namespace) -> None:
|
def install_command(args: argparse.Namespace) -> None:
|
||||||
@@ -123,32 +140,23 @@ def install_command(args: argparse.Namespace) -> None:
|
|||||||
target_host = args.target_host
|
target_host = args.target_host
|
||||||
password = None
|
password = None
|
||||||
|
|
||||||
opts = InstallOptions(
|
if not args.yes:
|
||||||
flake=args.flake,
|
ask = input(f"Install {args.machine} to {target_host}? [y/N] ")
|
||||||
machine=args.machine,
|
|
||||||
target_host=target_host,
|
|
||||||
kexec=args.kexec,
|
|
||||||
confirm=not args.yes,
|
|
||||||
debug=args.debug,
|
|
||||||
no_reboot=args.no_reboot,
|
|
||||||
json_ssh_deploy=json_ssh_deploy,
|
|
||||||
nix_options=args.option,
|
|
||||||
)
|
|
||||||
machine = Machine(opts.machine, flake=opts.flake)
|
|
||||||
machine.target_host_address = opts.target_host
|
|
||||||
|
|
||||||
if opts.confirm:
|
|
||||||
ask = input(f"Install {machine.name} to {opts.target_host}? [y/N] ")
|
|
||||||
if ask != "y":
|
if ask != "y":
|
||||||
return
|
return
|
||||||
|
|
||||||
install_nixos(
|
return install_machine(
|
||||||
machine,
|
InstallOptions(
|
||||||
kexec=opts.kexec,
|
flake=args.flake,
|
||||||
debug=opts.debug,
|
machine=args.machine,
|
||||||
password=password,
|
target_host=target_host,
|
||||||
no_reboot=opts.no_reboot,
|
kexec=args.kexec,
|
||||||
extra_args=opts.nix_options,
|
debug=args.debug,
|
||||||
|
no_reboot=args.no_reboot,
|
||||||
|
json_ssh_deploy=json_ssh_deploy,
|
||||||
|
nix_options=args.option,
|
||||||
|
),
|
||||||
|
password,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user