Merge pull request 'pkgs/cli: Query target-host for machines install from configuration' (#2359) from kenji/clan-core:kenji-cli/2309/machines-install into main
This commit is contained in:
@@ -105,7 +105,7 @@
|
|||||||
client.succeed("test -f test-flake/machines/test-install-machine/hardware-configuration.nix")
|
client.succeed("test -f test-flake/machines/test-install-machine/hardware-configuration.nix")
|
||||||
client.succeed("clan machines update-hardware-config --backend nixos-facter --flake test-flake test-install-machine root@target>&2")
|
client.succeed("clan machines update-hardware-config --backend nixos-facter --flake test-flake test-install-machine root@target>&2")
|
||||||
client.succeed("test -f test-flake/machines/test-install-machine/facter.json")
|
client.succeed("test -f test-flake/machines/test-install-machine/facter.json")
|
||||||
client.succeed("clan machines install --debug --flake ${../..} --yes test-install-machine root@target >&2")
|
client.succeed("clan machines install --debug --flake ${../..} --yes test-install-machine --target-host root@target >&2")
|
||||||
try:
|
try:
|
||||||
target.shutdown()
|
target.shutdown()
|
||||||
except BrokenPipeError:
|
except BrokenPipeError:
|
||||||
|
|||||||
@@ -112,7 +112,7 @@ This process involves preparing a suitable hardware and disk partitioning config
|
|||||||
1. **SSH with Password Authentication**
|
1. **SSH with Password Authentication**
|
||||||
Run the following command to install using SSH:
|
Run the following command to install using SSH:
|
||||||
```bash
|
```bash
|
||||||
clan machines install [MACHINE] <IP>
|
clan machines install [MACHINE] --target-host <IP>
|
||||||
```
|
```
|
||||||
|
|
||||||
2. **Scanning a QR Code for Installation Details**
|
2. **Scanning a QR Code for Installation Details**
|
||||||
@@ -133,7 +133,7 @@ This process involves preparing a suitable hardware and disk partitioning config
|
|||||||
Replace `<target_host>` with the **target computers' ip address**:
|
Replace `<target_host>` with the **target computers' ip address**:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
clan machines install [MACHINE] <target_host>
|
clan machines install [MACHINE] --target-host <target_host>
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ blkdiscard /dev/disk/by-id/nvme-eui.002538b931b59865
|
|||||||
4. Run the `clan` machine installation with the following command:
|
4. Run the `clan` machine installation with the following command:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
clan machines install gchq-local root@nixos-installer --yes --no-reboot
|
clan machines install gchq-local --target-host root@nixos-installer --yes --no-reboot
|
||||||
```
|
```
|
||||||
|
|
||||||
### Step 2: ZFS Pool Import and System Installation
|
### Step 2: ZFS Pool Import and System Installation
|
||||||
|
|||||||
@@ -329,8 +329,10 @@ Examples:
|
|||||||
Will update the specified machine [MACHINE], if [MACHINE] is omitted, the command
|
Will update the specified machine [MACHINE], if [MACHINE] is omitted, the command
|
||||||
will attempt to update every configured machine.
|
will attempt to update every configured machine.
|
||||||
|
|
||||||
$ clan machines install [MACHINES] [TARGET_HOST]
|
$ clan machines install [MACHINE] --target-host [TARGET_HOST]
|
||||||
Will install the specified machine [MACHINE], to the specified [TARGET_HOST].
|
Will install the specified machine [MACHINE] to the specified [TARGET_HOST].
|
||||||
|
If the `--target-host` flag is omitted will try to find host information by
|
||||||
|
checking the deployment configuration inside the specified machine.
|
||||||
|
|
||||||
For more detailed information, visit: {help_hyperlink("deploy", "https://docs.clan.lol/deploy")}
|
For more detailed information, visit: {help_hyperlink("deploy", "https://docs.clan.lol/deploy")}
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -99,8 +99,10 @@ This subcommand provides an interface to install machines managed by clan.
|
|||||||
|
|
||||||
Examples:
|
Examples:
|
||||||
|
|
||||||
$ clan machines install [MACHINE] [TARGET_HOST]
|
$ clan machines install [MACHINE] --target-host [TARGET_HOST]
|
||||||
Will install the specified machine [MACHINE], to the specified [TARGET_HOST].
|
Will install the specified machine [MACHINE] to the specified [TARGET_HOST].
|
||||||
|
If the `--target-host` flag is omitted will try to find host information by
|
||||||
|
checking the deployment configuration inside the specified machine.
|
||||||
|
|
||||||
$ clan machines install [MACHINE] --json [JSON]
|
$ clan machines install [MACHINE] --json [JSON]
|
||||||
Will install the specified machine [MACHINE] to the host exposed by
|
Will install the specified machine [MACHINE] to the host exposed by
|
||||||
|
|||||||
@@ -135,16 +135,20 @@ def install_command(args: argparse.Namespace) -> None:
|
|||||||
elif args.png:
|
elif args.png:
|
||||||
json_ssh_deploy = json.loads(qrcode_scan(args.png))
|
json_ssh_deploy = json.loads(qrcode_scan(args.png))
|
||||||
|
|
||||||
if not json_ssh_deploy and not args.target_host:
|
|
||||||
msg = "No target host provided, please provide a target host."
|
|
||||||
raise ClanError(msg)
|
|
||||||
|
|
||||||
if json_ssh_deploy:
|
if json_ssh_deploy:
|
||||||
target_host = f"root@{find_reachable_host_from_deploy_json(json_ssh_deploy)}"
|
target_host = f"root@{find_reachable_host_from_deploy_json(json_ssh_deploy)}"
|
||||||
password = json_ssh_deploy["pass"]
|
password = json_ssh_deploy["pass"]
|
||||||
else:
|
elif args.target_host:
|
||||||
target_host = args.target_host
|
target_host = args.target_host
|
||||||
password = None
|
password = None
|
||||||
|
else:
|
||||||
|
machine = Machine(name=args.machine, flake=args.flake, nix_options=args.option)
|
||||||
|
target_host = str(machine.target_host)
|
||||||
|
password = None
|
||||||
|
|
||||||
|
if not target_host:
|
||||||
|
msg = "No target host provided, please provide a target host."
|
||||||
|
raise ClanError(msg)
|
||||||
|
|
||||||
if not args.yes:
|
if not args.yes:
|
||||||
ask = input(f"Install {args.machine} to {target_host}? [y/N] ")
|
ask = input(f"Install {args.machine} to {target_host}? [y/N] ")
|
||||||
@@ -223,18 +227,16 @@ def register_install_parser(parser: argparse.ArgumentParser) -> None:
|
|||||||
)
|
)
|
||||||
add_dynamic_completer(machines_parser, complete_machines)
|
add_dynamic_completer(machines_parser, complete_machines)
|
||||||
|
|
||||||
parser.add_argument(
|
|
||||||
"target_host",
|
|
||||||
type=str,
|
|
||||||
nargs="?",
|
|
||||||
help="ssh address to install to in the form of user@host:2222",
|
|
||||||
)
|
|
||||||
group = parser.add_mutually_exclusive_group(required=False)
|
group = parser.add_mutually_exclusive_group(required=False)
|
||||||
group.add_argument(
|
group.add_argument(
|
||||||
"-j",
|
"-j",
|
||||||
"--json",
|
"--json",
|
||||||
help="specify the json file for ssh data (generated by starting the clan installer)",
|
help="specify the json file for ssh data (generated by starting the clan installer)",
|
||||||
)
|
)
|
||||||
|
group.add_argument(
|
||||||
|
"--target-host",
|
||||||
|
help="ssh address to install to in the form of user@host:2222",
|
||||||
|
)
|
||||||
group.add_argument(
|
group.add_argument(
|
||||||
"-P",
|
"-P",
|
||||||
"--png",
|
"--png",
|
||||||
|
|||||||
Reference in New Issue
Block a user