WiP
This commit is contained in:
parent
22e5ffb4b4
commit
be8f8fbbf9
1 changed files with 35 additions and 3 deletions
|
@ -18,6 +18,35 @@ def _validate_ip(ip: str) -> bool:
|
||||||
except ValueError:
|
except ValueError:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def _check_ssh_connection(ip: str) -> bool:
|
||||||
|
try:
|
||||||
|
check_output(['ssh', f'root@{ip}', 'echo', 'Connected'])
|
||||||
|
return True
|
||||||
|
except Exception:
|
||||||
|
return False
|
||||||
|
|
||||||
|
def bootstrap_machine(ip: str):
|
||||||
|
check_output(
|
||||||
|
[
|
||||||
|
'nix',
|
||||||
|
'run',
|
||||||
|
'github:nix-community/nixos-anywhere',
|
||||||
|
'--',
|
||||||
|
'--flake',
|
||||||
|
'".#bootstrap"',
|
||||||
|
'--target-host',
|
||||||
|
f'root@{ip}',
|
||||||
|
'--build-on-remote'
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def get_ssh_key(ip: str) -> str:
|
||||||
|
"""
|
||||||
|
This function uses machines ssh-keyscan to get the ssh key and then get the ed25519 key
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
def get_machine_config(machine_name: str) -> dict:
|
def get_machine_config(machine_name: str) -> dict:
|
||||||
output = check_output(['nix', 'eval', '--json', f'.#nixosConfigurations.{machine_name}.config.kropcloud'])
|
output = check_output(['nix', 'eval', '--json', f'.#nixosConfigurations.{machine_name}.config.kropcloud'])
|
||||||
return json.loads(output)
|
return json.loads(output)
|
||||||
|
@ -41,12 +70,15 @@ def main() -> int:
|
||||||
# We are bootstraping the machine first because we need their ssh keys
|
# We are bootstraping the machine first because we need their ssh keys
|
||||||
bootstrap_machine()
|
bootstrap_machine()
|
||||||
|
|
||||||
# while not check_ssh_connection():
|
while not _check_ssh_connection():
|
||||||
# time.sleep(5)
|
time.sleep(5)
|
||||||
|
|
||||||
# # connect and get ssh keys
|
# # connect and get ssh keys
|
||||||
|
|
||||||
# ssh_key = get_ssh_key()
|
ssh_key = get_ssh_key()
|
||||||
|
|
||||||
|
# Add the ssh key to keys in secrets/secrets.nix
|
||||||
|
# and rekey the secrets
|
||||||
|
|
||||||
# install_machine()
|
# install_machine()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue