Merge pull request 'api/clan: rename 'show_clan_meta' -> 'get_clan_details'' (#4236) from api-cleanup into main
Reviewed-on: https://git.clan.lol/clan/clan-core/pulls/4236
This commit is contained in:
@@ -13,7 +13,7 @@ export const clanMetaQuery = (uri: string | undefined = undefined) =>
|
|||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
console.log("fetching clan meta", clanURI);
|
console.log("fetching clan meta", clanURI);
|
||||||
|
|
||||||
const result = await callApi("show_clan_meta", {
|
const result = await callApi("get_clan_details", {
|
||||||
flake: { identifier: clanURI! },
|
flake: { identifier: clanURI! },
|
||||||
}).promise;
|
}).promise;
|
||||||
|
|
||||||
|
|||||||
@@ -203,6 +203,6 @@ export const CreateClan = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
type Meta = Extract<
|
type Meta = Extract<
|
||||||
OperationResponse<"show_clan_meta">,
|
OperationResponse<"get_clan_details">,
|
||||||
{ status: "success" }
|
{ status: "success" }
|
||||||
>["data"];
|
>["data"];
|
||||||
|
|||||||
@@ -128,7 +128,7 @@ const EditClanForm = (props: EditClanFormProps) => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
type GeneralData = SuccessQuery<"show_clan_meta">["data"];
|
type GeneralData = SuccessQuery<"get_clan_details">["data"];
|
||||||
|
|
||||||
export const ClanDetails = () => {
|
export const ClanDetails = () => {
|
||||||
const params = useParams();
|
const params = useParams();
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ export const Flash = () => {
|
|||||||
const deviceQuery = createQuery(() => ({
|
const deviceQuery = createQuery(() => ({
|
||||||
queryKey: ["block_devices"],
|
queryKey: ["block_devices"],
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
const result = await callApi("show_block_devices", {}).promise;
|
const result = await callApi("list_block_devices", {}).promise;
|
||||||
if (result.status === "error") throw new Error("Failed to fetch data");
|
if (result.status === "error") throw new Error("Failed to fetch data");
|
||||||
return result.data;
|
return result.data;
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { Button } from "../../components/Button/Button";
|
|||||||
import Icon from "@/src/components/icon";
|
import Icon from "@/src/components/icon";
|
||||||
|
|
||||||
type ServiceModel = Extract<
|
type ServiceModel = Extract<
|
||||||
OperationResponse<"show_mdns">,
|
OperationResponse<"list_mdns_services">,
|
||||||
{ status: "success" }
|
{ status: "success" }
|
||||||
>["data"]["services"];
|
>["data"]["services"];
|
||||||
|
|
||||||
@@ -16,7 +16,7 @@ export const HostList: Component = () => {
|
|||||||
<div class="" data-tip="Refresh install targets">
|
<div class="" data-tip="Refresh install targets">
|
||||||
<Button
|
<Button
|
||||||
variant="light"
|
variant="light"
|
||||||
onClick={() => callApi("show_mdns", {})}
|
onClick={() => callApi("list_mdns_services", {})}
|
||||||
startIcon={<Icon icon="Update" />}
|
startIcon={<Icon icon="Update" />}
|
||||||
></Button>
|
></Button>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ export const HWStep = (props: StepProps<HardwareValues>) => {
|
|||||||
const hwReportQuery = useQuery(() => ({
|
const hwReportQuery = useQuery(() => ({
|
||||||
queryKey: [props.dir, props.machine_id, "hw_report"],
|
queryKey: [props.dir, props.machine_id, "hw_report"],
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
const result = await callApi("show_machine_hardware_config", {
|
const result = await callApi("describe_machine_hardware", {
|
||||||
machine: {
|
machine: {
|
||||||
flake: {
|
flake: {
|
||||||
identifier: props.dir,
|
identifier: props.dir,
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ export const clanMetaQuery = (uri: string | undefined = undefined) =>
|
|||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
console.log("fetching clan meta", clanURI);
|
console.log("fetching clan meta", clanURI);
|
||||||
|
|
||||||
const result = await callApi("show_clan_meta", {
|
const result = await callApi("get_clan_details", {
|
||||||
flake: { identifier: clanURI! },
|
flake: { identifier: clanURI! },
|
||||||
}).promise;
|
}).promise;
|
||||||
|
|
||||||
|
|||||||
@@ -202,6 +202,6 @@ export const CreateClan = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
type Meta = Extract<
|
type Meta = Extract<
|
||||||
OperationResponse<"show_clan_meta">,
|
OperationResponse<"get_clan_details">,
|
||||||
{ status: "success" }
|
{ status: "success" }
|
||||||
>["data"];
|
>["data"];
|
||||||
|
|||||||
@@ -128,7 +128,7 @@ const EditClanForm = (props: EditClanFormProps) => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
type GeneralData = SuccessQuery<"show_clan_meta">["data"];
|
type GeneralData = SuccessQuery<"get_clan_details">["data"];
|
||||||
|
|
||||||
export const ClanDetails = () => {
|
export const ClanDetails = () => {
|
||||||
const params = useParams();
|
const params = useParams();
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { Button } from "../../components/Button/Button";
|
|||||||
import Icon from "@/src/components/icon";
|
import Icon from "@/src/components/icon";
|
||||||
|
|
||||||
type ServiceModel = Extract<
|
type ServiceModel = Extract<
|
||||||
OperationResponse<"show_mdns">,
|
OperationResponse<"list_mdns_services">,
|
||||||
{ status: "success" }
|
{ status: "success" }
|
||||||
>["data"]["services"];
|
>["data"]["services"];
|
||||||
|
|
||||||
@@ -16,7 +16,7 @@ export const HostList: Component = () => {
|
|||||||
<div class="" data-tip="Refresh install targets">
|
<div class="" data-tip="Refresh install targets">
|
||||||
<Button
|
<Button
|
||||||
variant="light"
|
variant="light"
|
||||||
onClick={() => callApi("show_mdns", {})}
|
onClick={() => callApi("list_mdns_services", {})}
|
||||||
startIcon={<Icon icon="Update" />}
|
startIcon={<Icon icon="Update" />}
|
||||||
></Button>
|
></Button>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
import argparse
|
import argparse
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from clan_lib.clan.get import show_clan_meta
|
from clan_lib.clan.get import get_clan_details
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def show_command(args: argparse.Namespace) -> None:
|
def show_command(args: argparse.Namespace) -> None:
|
||||||
flake_path = args.flake.path
|
flake_path = args.flake.path
|
||||||
meta = show_clan_meta(flake_path)
|
meta = get_clan_details(flake_path)
|
||||||
|
|
||||||
print(f"Name: {meta.get('name')}")
|
print(f"Name: {meta.get('name')}")
|
||||||
print(f"Description: {meta.get('description', '-')}")
|
print(f"Description: {meta.get('description', '-')}")
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ class FlashOptions(TypedDict):
|
|||||||
|
|
||||||
|
|
||||||
@API.register
|
@API.register
|
||||||
def show_flash_options() -> FlashOptions:
|
def get_flash_options() -> FlashOptions:
|
||||||
return {"languages": list_languages(), "keymaps": list_keymaps()}
|
return {"languages": list_languages(), "keymaps": list_keymaps()}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -122,11 +122,12 @@ def blk_from_dict(data: dict) -> BlkInfo:
|
|||||||
|
|
||||||
|
|
||||||
@API.register
|
@API.register
|
||||||
def show_block_devices() -> Blockdevices:
|
def list_block_devices() -> Blockdevices:
|
||||||
"""
|
"""
|
||||||
Api method to show local block devices.
|
List local block devices by running `lsblk`.
|
||||||
|
|
||||||
It must return a list of block devices.
|
Returns:
|
||||||
|
A list of detected block devices with metadata like size, path, type, etc.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
cmd = nix_shell(
|
cmd = nix_shell(
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ def parse_avahi_output(output: str) -> DNSInfo:
|
|||||||
|
|
||||||
|
|
||||||
@API.register
|
@API.register
|
||||||
def show_mdns() -> DNSInfo:
|
def list_mdns_services() -> DNSInfo:
|
||||||
cmd = nix_shell(
|
cmd = nix_shell(
|
||||||
["avahi"],
|
["avahi"],
|
||||||
[
|
[
|
||||||
@@ -107,7 +107,7 @@ def show_mdns() -> DNSInfo:
|
|||||||
|
|
||||||
|
|
||||||
def mdns_command(args: argparse.Namespace) -> None:
|
def mdns_command(args: argparse.Namespace) -> None:
|
||||||
dns_info = show_mdns()
|
dns_info = list_mdns_services()
|
||||||
for name, info in dns_info.services.items():
|
for name, info in dns_info.services.items():
|
||||||
print(f"Hostname: {name} - ip: {info.ip}")
|
print(f"Hostname: {name} - ip: {info.ip}")
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
from clan_lib.api import API
|
from clan_lib.api import API
|
||||||
from clan_lib.errors import ClanError
|
from clan_lib.errors import ClanError
|
||||||
from clan_lib.flake import Flake
|
from clan_lib.flake import Flake
|
||||||
from clan_lib.nix_models.clan import InventoryMeta as Meta
|
from clan_lib.nix_models.clan import InventoryMeta
|
||||||
from clan_lib.persist.inventory_store import InventoryStore
|
from clan_lib.persist.inventory_store import InventoryStore
|
||||||
|
|
||||||
|
|
||||||
@API.register
|
@API.register
|
||||||
def show_clan_meta(flake: Flake) -> Meta:
|
def get_clan_details(flake: Flake) -> InventoryMeta:
|
||||||
if flake.is_local and not flake.path.exists():
|
if flake.is_local and not flake.path.exists():
|
||||||
msg = f"Path {flake} does not exist"
|
msg = f"Path {flake} does not exist"
|
||||||
raise ClanError(msg, description="clan directory does not exist")
|
raise ClanError(msg, description="clan directory does not exist")
|
||||||
|
|||||||
81
templates/clan/flake-parts/clan.nix
Normal file
81
templates/clan/flake-parts/clan.nix
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
{ self }:
|
||||||
|
{
|
||||||
|
meta.name = "__CHANGE_ME__"; # Ensure this is unique among all clans you want to use.
|
||||||
|
|
||||||
|
inherit self;
|
||||||
|
machines = {
|
||||||
|
# "jon" will be the hostname of the machine
|
||||||
|
jon =
|
||||||
|
{ pkgs, ... }:
|
||||||
|
{
|
||||||
|
imports = [
|
||||||
|
./modules/shared.nix
|
||||||
|
./modules/disko.nix
|
||||||
|
./machines/jon/configuration.nix
|
||||||
|
];
|
||||||
|
|
||||||
|
nixpkgs.hostPlatform = "x86_64-linux";
|
||||||
|
|
||||||
|
# Set this for clan commands use ssh i.e. `clan machines update`
|
||||||
|
# If you change the hostname, you need to update this line to root@<new-hostname>
|
||||||
|
# This only works however if you have avahi running on your admin machine else use IP
|
||||||
|
clan.core.networking.targetHost = pkgs.lib.mkDefault "root@jon";
|
||||||
|
|
||||||
|
# You can get your disk id by running the following command on the installer:
|
||||||
|
# Replace <IP> with the IP of the installer printed on the screen or by running the `ip addr` command.
|
||||||
|
# ssh root@<IP> lsblk --output NAME,ID-LINK,FSTYPE,SIZE,MOUNTPOINT
|
||||||
|
disko.devices.disk.main = {
|
||||||
|
device = "/dev/disk/by-id/__CHANGE_ME__";
|
||||||
|
};
|
||||||
|
|
||||||
|
# IMPORTANT! Add your SSH key here
|
||||||
|
# e.g. > cat ~/.ssh/id_ed25519.pub
|
||||||
|
users.users.root.openssh.authorizedKeys.keys = throw ''
|
||||||
|
Don't forget to add your SSH key here!
|
||||||
|
users.users.root.openssh.authorizedKeys.keys = [ "<YOUR SSH_KEY>" ]
|
||||||
|
'';
|
||||||
|
|
||||||
|
# Zerotier needs one controller to accept new nodes. Once accepted
|
||||||
|
# the controller can be offline and routing still works.
|
||||||
|
clan.core.networking.zerotier.controller.enable = true;
|
||||||
|
};
|
||||||
|
# "sara" will be the hostname of the machine
|
||||||
|
sara =
|
||||||
|
{ pkgs, ... }:
|
||||||
|
{
|
||||||
|
imports = [
|
||||||
|
./modules/shared.nix
|
||||||
|
./modules/disko.nix
|
||||||
|
./machines/sara/configuration.nix
|
||||||
|
];
|
||||||
|
|
||||||
|
nixpkgs.hostPlatform = "x86_64-linux";
|
||||||
|
|
||||||
|
# Set this for clan commands use ssh i.e. `clan machines update`
|
||||||
|
# If you change the hostname, you need to update this line to root@<new-hostname>
|
||||||
|
# This only works however if you have avahi running on your admin machine else use IP
|
||||||
|
clan.core.networking.targetHost = pkgs.lib.mkDefault "root@sara";
|
||||||
|
|
||||||
|
# You can get your disk id by running the following command on the installer:
|
||||||
|
# Replace <IP> with the IP of the installer printed on the screen or by running the `ip addr` command.
|
||||||
|
# ssh root@<IP> lsblk --output NAME,ID-LINK,FSTYPE,SIZE,MOUNTPOINT
|
||||||
|
disko.devices.disk.main = {
|
||||||
|
device = "/dev/disk/by-id/__CHANGE_ME__";
|
||||||
|
};
|
||||||
|
|
||||||
|
# IMPORTANT! Add your SSH key here
|
||||||
|
# e.g. > cat ~/.ssh/id_ed25519.pub
|
||||||
|
users.users.root.openssh.authorizedKeys.keys = throw ''
|
||||||
|
Don't forget to add your SSH key here!
|
||||||
|
users.users.root.openssh.authorizedKeys.keys = [ "<YOUR SSH_KEY>" ]
|
||||||
|
'';
|
||||||
|
|
||||||
|
/*
|
||||||
|
After jon is deployed, uncomment the following line
|
||||||
|
This will allow sara to share the VPN overlay network with jon
|
||||||
|
The networkId is generated by the first deployment of jon
|
||||||
|
*/
|
||||||
|
# clan.core.networking.zerotier.networkId = builtins.readFile ../../vars/per-machine/jon/zerotier/zerotier-network-id/value;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -17,88 +17,13 @@
|
|||||||
"x86_64-darwin"
|
"x86_64-darwin"
|
||||||
"aarch64-darwin"
|
"aarch64-darwin"
|
||||||
];
|
];
|
||||||
imports = [ inputs.clan-core.flakeModules.default ];
|
imports = [
|
||||||
|
inputs.clan-core.flakeModules.default
|
||||||
|
];
|
||||||
|
|
||||||
# https://docs.clan.lol/guides/getting-started/flake-parts/
|
# https://docs.clan.lol/guides/getting-started/flake-parts/
|
||||||
clan = {
|
clan = import ./clan.nix { inherit self; };
|
||||||
meta.name = "__CHANGE_ME__"; # Ensure this is unique among all clans you want to use.
|
|
||||||
|
|
||||||
inherit self;
|
|
||||||
machines = {
|
|
||||||
# "jon" will be the hostname of the machine
|
|
||||||
jon =
|
|
||||||
{ pkgs, ... }:
|
|
||||||
{
|
|
||||||
imports = [
|
|
||||||
./modules/shared.nix
|
|
||||||
./modules/disko.nix
|
|
||||||
./machines/jon/configuration.nix
|
|
||||||
];
|
|
||||||
|
|
||||||
nixpkgs.hostPlatform = "x86_64-linux";
|
|
||||||
|
|
||||||
# Set this for clan commands use ssh i.e. `clan machines update`
|
|
||||||
# If you change the hostname, you need to update this line to root@<new-hostname>
|
|
||||||
# This only works however if you have avahi running on your admin machine else use IP
|
|
||||||
clan.core.networking.targetHost = pkgs.lib.mkDefault "root@jon";
|
|
||||||
|
|
||||||
# You can get your disk id by running the following command on the installer:
|
|
||||||
# Replace <IP> with the IP of the installer printed on the screen or by running the `ip addr` command.
|
|
||||||
# ssh root@<IP> lsblk --output NAME,ID-LINK,FSTYPE,SIZE,MOUNTPOINT
|
|
||||||
disko.devices.disk.main = {
|
|
||||||
device = "/dev/disk/by-id/__CHANGE_ME__";
|
|
||||||
};
|
|
||||||
|
|
||||||
# IMPORTANT! Add your SSH key here
|
|
||||||
# e.g. > cat ~/.ssh/id_ed25519.pub
|
|
||||||
users.users.root.openssh.authorizedKeys.keys = throw ''
|
|
||||||
Don't forget to add your SSH key here!
|
|
||||||
users.users.root.openssh.authorizedKeys.keys = [ "<YOUR SSH_KEY>" ]
|
|
||||||
'';
|
|
||||||
|
|
||||||
# Zerotier needs one controller to accept new nodes. Once accepted
|
|
||||||
# the controller can be offline and routing still works.
|
|
||||||
clan.core.networking.zerotier.controller.enable = true;
|
|
||||||
};
|
|
||||||
# "sara" will be the hostname of the machine
|
|
||||||
sara =
|
|
||||||
{ pkgs, ... }:
|
|
||||||
{
|
|
||||||
imports = [
|
|
||||||
./modules/shared.nix
|
|
||||||
./modules/disko.nix
|
|
||||||
./machines/sara/configuration.nix
|
|
||||||
];
|
|
||||||
|
|
||||||
nixpkgs.hostPlatform = "x86_64-linux";
|
|
||||||
|
|
||||||
# Set this for clan commands use ssh i.e. `clan machines update`
|
|
||||||
# If you change the hostname, you need to update this line to root@<new-hostname>
|
|
||||||
# This only works however if you have avahi running on your admin machine else use IP
|
|
||||||
clan.core.networking.targetHost = pkgs.lib.mkDefault "root@sara";
|
|
||||||
|
|
||||||
# You can get your disk id by running the following command on the installer:
|
|
||||||
# Replace <IP> with the IP of the installer printed on the screen or by running the `ip addr` command.
|
|
||||||
# ssh root@<IP> lsblk --output NAME,ID-LINK,FSTYPE,SIZE,MOUNTPOINT
|
|
||||||
disko.devices.disk.main = {
|
|
||||||
device = "/dev/disk/by-id/__CHANGE_ME__";
|
|
||||||
};
|
|
||||||
|
|
||||||
# IMPORTANT! Add your SSH key here
|
|
||||||
# e.g. > cat ~/.ssh/id_ed25519.pub
|
|
||||||
users.users.root.openssh.authorizedKeys.keys = throw ''
|
|
||||||
Don't forget to add your SSH key here!
|
|
||||||
users.users.root.openssh.authorizedKeys.keys = [ "<YOUR SSH_KEY>" ]
|
|
||||||
'';
|
|
||||||
|
|
||||||
/*
|
|
||||||
After jon is deployed, uncomment the following line
|
|
||||||
This will allow sara to share the VPN overlay network with jon
|
|
||||||
The networkId is generated by the first deployment of jon
|
|
||||||
*/
|
|
||||||
# clan.core.networking.zerotier.networkId = builtins.readFile ../../vars/per-machine/jon/zerotier/zerotier-network-id/value;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
perSystem =
|
perSystem =
|
||||||
{ pkgs, inputs', ... }:
|
{ pkgs, inputs', ... }:
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user