forked from clan/clan-core
Merge pull request 'move checks if targetHost/buildHost is set to cli' (#815) from Mic92-target_host into main
This commit is contained in:
commit
71d14eb178
@ -14,7 +14,8 @@
|
|||||||
- user@machine2.example.com
|
- user@machine2.example.com
|
||||||
- root@example.com:2222&IdentityFile=/path/to/private/key
|
- root@example.com:2222&IdentityFile=/path/to/private/key
|
||||||
'';
|
'';
|
||||||
type = lib.types.str;
|
default = null;
|
||||||
|
type = lib.types.nullOr lib.types.str;
|
||||||
};
|
};
|
||||||
buildHost = lib.mkOption {
|
buildHost = lib.mkOption {
|
||||||
description = ''
|
description = ''
|
||||||
|
@ -20,13 +20,13 @@
|
|||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
deployment.buildHost = lib.mkOption {
|
deployment.buildHost = lib.mkOption {
|
||||||
type = lib.types.str;
|
type = lib.types.nullOr lib.types.str;
|
||||||
description = ''
|
description = ''
|
||||||
the hostname of the build host where nixos-rebuild is run
|
the hostname of the build host where nixos-rebuild is run
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
deployment.targetHost = lib.mkOption {
|
deployment.targetHost = lib.mkOption {
|
||||||
type = lib.types.str;
|
type = lib.types.nullOr lib.types.str;
|
||||||
description = ''
|
description = ''
|
||||||
the hostname of the target host to be deployed to
|
the hostname of the target host to be deployed to
|
||||||
'';
|
'';
|
||||||
|
@ -3,6 +3,7 @@ import logging
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from ..cmd import run
|
from ..cmd import run
|
||||||
|
from ..errors import ClanError
|
||||||
from ..nix import nix_build, nix_config, nix_eval, nix_metadata
|
from ..nix import nix_build, nix_config, nix_eval, nix_metadata
|
||||||
from ..ssh import Host, parse_deployment_address
|
from ..ssh import Host, parse_deployment_address
|
||||||
|
|
||||||
@ -48,10 +49,14 @@ class Machine:
|
|||||||
@property
|
@property
|
||||||
def target_host(self) -> str:
|
def target_host(self) -> str:
|
||||||
# deploymentAddress is deprecated.
|
# deploymentAddress is deprecated.
|
||||||
return (
|
val = (
|
||||||
self.deployment_info.get("targetHost")
|
self.deployment_info.get("targetHost")
|
||||||
or self.deployment_info["deploymentAddress"]
|
or self.deployment_info["deploymentAddress"]
|
||||||
)
|
)
|
||||||
|
if val is None:
|
||||||
|
msg = f"the 'clan.networking.targetHost' nixos option is not set for machine '{self.name}'"
|
||||||
|
raise ClanError(msg)
|
||||||
|
return val
|
||||||
|
|
||||||
@target_host.setter
|
@target_host.setter
|
||||||
def target_host(self, value: str) -> None:
|
def target_host(self, value: str) -> None:
|
||||||
|
@ -154,14 +154,11 @@ def get_all_machines(clan_dir: Path) -> HostGroup:
|
|||||||
hosts = []
|
hosts = []
|
||||||
for name, machine_data in machines.items():
|
for name, machine_data in machines.items():
|
||||||
# very hacky. would be better to do a MachinesGroup instead
|
# very hacky. would be better to do a MachinesGroup instead
|
||||||
|
machine = Machine(name=name, flake=clan_dir, deployment_info=machine_data)
|
||||||
host = parse_deployment_address(
|
host = parse_deployment_address(
|
||||||
name,
|
name,
|
||||||
machine_data.get("targetHost") or machine_data.get("deploymentAddress"),
|
host=machine.target_host,
|
||||||
meta={
|
meta={"machine": machine},
|
||||||
"machine": Machine(
|
|
||||||
name=name, flake=clan_dir, deployment_info=machine_data
|
|
||||||
)
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
hosts.append(host)
|
hosts.append(host)
|
||||||
return HostGroup(hosts)
|
return HostGroup(hosts)
|
||||||
|
Loading…
Reference in New Issue
Block a user