init: Set/get single disk
This commit is contained in:
@@ -5,12 +5,12 @@ from pathlib import Path
|
|||||||
from types import ModuleType
|
from types import ModuleType
|
||||||
|
|
||||||
# These imports are unused, but necessary for @API.register to run once.
|
# These imports are unused, but necessary for @API.register to run once.
|
||||||
from clan_cli.api import directory, mdns_discovery, modules
|
from clan_cli.api import directory, disk, mdns_discovery, modules
|
||||||
from clan_cli.arg_actions import AppendOptionAction
|
from clan_cli.arg_actions import AppendOptionAction
|
||||||
from clan_cli.clan import show, update
|
from clan_cli.clan import show, update
|
||||||
|
|
||||||
# API endpoints that are not used in the cli.
|
# API endpoints that are not used in the cli.
|
||||||
__all__ = ["directory", "mdns_discovery", "modules", "update"]
|
__all__ = ["directory", "mdns_discovery", "modules", "update", "disk"]
|
||||||
|
|
||||||
from . import (
|
from . import (
|
||||||
backups,
|
backups,
|
||||||
|
|||||||
65
pkgs/clan-cli/clan_cli/api/disk.py
Normal file
65
pkgs/clan-cli/clan_cli/api/disk.py
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
from clan_cli.api import API
|
||||||
|
from clan_cli.inventory import (
|
||||||
|
ServiceMeta,
|
||||||
|
ServiceSingleDisk,
|
||||||
|
ServiceSingleDiskRole,
|
||||||
|
ServiceSingleDiskRoleDefault,
|
||||||
|
SingleDiskConfig,
|
||||||
|
load_inventory_eval,
|
||||||
|
load_inventory_json,
|
||||||
|
save_inventory,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def get_instance_name(machine_name: str) -> str:
|
||||||
|
return f"{machine_name}-single-disk"
|
||||||
|
|
||||||
|
|
||||||
|
@API.register
|
||||||
|
def set_single_disk_uuid(
|
||||||
|
base_path: str,
|
||||||
|
machine_name: str,
|
||||||
|
disk_uuid: str,
|
||||||
|
) -> None:
|
||||||
|
"""
|
||||||
|
Set the disk UUID of single disk machine
|
||||||
|
"""
|
||||||
|
inventory = load_inventory_json(base_path)
|
||||||
|
|
||||||
|
instance_name = get_instance_name(machine_name)
|
||||||
|
|
||||||
|
single_disk_config: ServiceSingleDisk = ServiceSingleDisk(
|
||||||
|
meta=ServiceMeta(name=instance_name),
|
||||||
|
roles=ServiceSingleDiskRole(
|
||||||
|
default=ServiceSingleDiskRoleDefault(
|
||||||
|
config=SingleDiskConfig(device=disk_uuid)
|
||||||
|
)
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
inventory.services.single_disk[instance_name] = single_disk_config
|
||||||
|
|
||||||
|
save_inventory(
|
||||||
|
inventory,
|
||||||
|
base_path,
|
||||||
|
f"Set disk UUID: '{disk_uuid}' on machine: '{machine_name}'",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@API.register
|
||||||
|
def get_single_disk_uuid(
|
||||||
|
base_path: str,
|
||||||
|
machine_name: str,
|
||||||
|
) -> str | None:
|
||||||
|
"""
|
||||||
|
Get the disk UUID of single disk machine
|
||||||
|
"""
|
||||||
|
inventory = load_inventory_eval(base_path)
|
||||||
|
|
||||||
|
instance_name = get_instance_name(machine_name)
|
||||||
|
|
||||||
|
single_disk_config: ServiceSingleDisk = inventory.services.single_disk[
|
||||||
|
instance_name
|
||||||
|
]
|
||||||
|
|
||||||
|
return single_disk_config.roles.default.config.device
|
||||||
@@ -32,6 +32,10 @@ from .classes import (
|
|||||||
ServiceBorgbackupRoleClient,
|
ServiceBorgbackupRoleClient,
|
||||||
ServiceBorgbackupRoleServer,
|
ServiceBorgbackupRoleServer,
|
||||||
ServiceMeta,
|
ServiceMeta,
|
||||||
|
ServiceSingleDisk,
|
||||||
|
ServiceSingleDiskRole,
|
||||||
|
ServiceSingleDiskRoleDefault,
|
||||||
|
SingleDiskConfig,
|
||||||
)
|
)
|
||||||
|
|
||||||
# Re export classes here
|
# Re export classes here
|
||||||
@@ -49,6 +53,11 @@ __all__ = [
|
|||||||
"ServiceBorgbackupRole",
|
"ServiceBorgbackupRole",
|
||||||
"ServiceBorgbackupRoleClient",
|
"ServiceBorgbackupRoleClient",
|
||||||
"ServiceBorgbackupRoleServer",
|
"ServiceBorgbackupRoleServer",
|
||||||
|
# Single Disk service
|
||||||
|
"ServiceSingleDisk",
|
||||||
|
"ServiceSingleDiskRole",
|
||||||
|
"ServiceSingleDiskRoleDefault",
|
||||||
|
"SingleDiskConfig",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
@@ -82,6 +91,7 @@ def load_inventory_eval(flake_dir: str | Path) -> Inventory:
|
|||||||
"--json",
|
"--json",
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
proc = run_no_stdout(cmd)
|
proc = run_no_stdout(cmd)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|||||||
@@ -38,6 +38,18 @@ export const MachineDetails = () => {
|
|||||||
|
|
||||||
const [formStore, { Form, Field }] = createForm<InstallForm>({});
|
const [formStore, { Form, Field }] = createForm<InstallForm>({});
|
||||||
const handleSubmit = async (values: InstallForm) => {
|
const handleSubmit = async (values: InstallForm) => {
|
||||||
|
const curr_uri = activeURI();
|
||||||
|
if (!curr_uri) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log("Setting disk", values.disk);
|
||||||
|
const r = await callApi("set_single_disk_uuid", {
|
||||||
|
base_path: curr_uri,
|
||||||
|
machine_name: params.id,
|
||||||
|
disk_uuid: values.disk,
|
||||||
|
});
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -151,7 +163,7 @@ export const MachineDetails = () => {
|
|||||||
machine_name: params.id,
|
machine_name: params.id,
|
||||||
clan_dir: curr_uri,
|
clan_dir: curr_uri,
|
||||||
hostname: query.data.machine.deploy.targetHost,
|
hostname: query.data.machine.deploy.targetHost,
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
toast.dismiss(lt);
|
toast.dismiss(lt);
|
||||||
|
|
||||||
@@ -160,7 +172,7 @@ export const MachineDetails = () => {
|
|||||||
}
|
}
|
||||||
if (response.status === "error") {
|
if (response.status === "error") {
|
||||||
toast.error(
|
toast.error(
|
||||||
"Failed to generate. " + response.errors[0].message
|
"Failed to generate. " + response.errors[0].message,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
query.refetch();
|
query.refetch();
|
||||||
@@ -201,7 +213,7 @@ export const MachineDetails = () => {
|
|||||||
{"bytes @"}
|
{"bytes @"}
|
||||||
{
|
{
|
||||||
query.data?.machine.deploy.targetHost?.split(
|
query.data?.machine.deploy.targetHost?.split(
|
||||||
"@"
|
"@",
|
||||||
)?.[1]
|
)?.[1]
|
||||||
}
|
}
|
||||||
</option>
|
</option>
|
||||||
@@ -214,6 +226,9 @@ export const MachineDetails = () => {
|
|||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</Field>
|
</Field>
|
||||||
|
<button class="btn btn-primary" type="submit">
|
||||||
|
Set disk
|
||||||
|
</button>
|
||||||
</Form>
|
</Form>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|||||||
Reference in New Issue
Block a user