2023-08-24 14:58:22 +00:00
|
|
|
import argparse
|
2023-10-13 17:56:10 +00:00
|
|
|
import logging
|
2024-05-26 13:57:10 +00:00
|
|
|
from dataclasses import dataclass
|
|
|
|
from pathlib import Path
|
2024-06-09 09:38:19 +00:00
|
|
|
from typing import Any
|
2023-08-24 14:58:22 +00:00
|
|
|
|
2024-05-26 13:57:10 +00:00
|
|
|
from clan_cli.api import API
|
2023-11-13 13:25:52 +00:00
|
|
|
from clan_cli.config.machine import set_config_for_machine
|
2023-08-24 14:58:22 +00:00
|
|
|
|
2023-10-13 17:56:10 +00:00
|
|
|
log = logging.getLogger(__name__)
|
2023-08-24 14:58:22 +00:00
|
|
|
|
2023-10-24 14:54:10 +00:00
|
|
|
|
2024-05-26 13:57:10 +00:00
|
|
|
@dataclass
|
|
|
|
class MachineCreateRequest:
|
|
|
|
name: str
|
2024-06-09 09:38:19 +00:00
|
|
|
config: dict[str, Any]
|
2024-05-26 13:57:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
@API.register
|
|
|
|
def create_machine(flake_dir: str | Path, machine: MachineCreateRequest) -> None:
|
|
|
|
set_config_for_machine(Path(flake_dir), machine.name, machine.config)
|
|
|
|
|
|
|
|
|
2023-08-24 17:16:44 +00:00
|
|
|
def create_command(args: argparse.Namespace) -> None:
|
2024-05-26 13:57:10 +00:00
|
|
|
create_machine(args.flake, MachineCreateRequest(args.machine, dict()))
|
2023-08-24 17:16:44 +00:00
|
|
|
|
|
|
|
|
2023-08-24 14:58:22 +00:00
|
|
|
def register_create_parser(parser: argparse.ArgumentParser) -> None:
|
2023-10-24 14:54:10 +00:00
|
|
|
parser.add_argument("machine", type=str)
|
2023-08-24 14:58:22 +00:00
|
|
|
parser.set_defaults(func=create_command)
|