- Migrate VMs/LXCs between cluster nodes with live progress tracking - Configure autostart, boot order, startup/shutdown delays, and delete protection from the instance settings tab - Group OS templates by detected OS (Ubuntu, AlmaLinux, etc.) instead of a single "Cloud Images" bucket - Expand native Proxmox backup job management (schedule, compression, retention, guest selection, notifications) - Add ru/en translations for the above
84 lines
2.9 KiB
TypeScript
84 lines
2.9 KiB
TypeScript
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
|
|
import { apiClient } from '@/lib/api-client';
|
|
import type { LXCTemplate, LXCDeployRequest } from '@/types';
|
|
|
|
export const lxcKeys = {
|
|
templates: (serverId: number) => ['lxc-templates', serverId] as const,
|
|
storages: (serverId: number, node?: string, content?: string) =>
|
|
['lxc-storages', serverId, node, content] as const,
|
|
};
|
|
|
|
// CT templates change rarely — cache for 5 minutes
|
|
export function useLXCTemplates(serverId?: number) {
|
|
return useQuery({
|
|
queryKey: lxcKeys.templates(serverId!),
|
|
queryFn: () =>
|
|
apiClient
|
|
.get<{ server_id: number; templates: LXCTemplate[] }>(`/proxmox/api/lxc-templates/${serverId}`)
|
|
.then((r) => r.templates),
|
|
enabled: !!serverId,
|
|
staleTime: 5 * 60 * 1000,
|
|
});
|
|
}
|
|
|
|
// Storage list changes rarely — cache for 5 minutes.
|
|
// content: 'rootdir' (LXC rootfs) | 'images' (VM disk) | undefined (both)
|
|
export function useLXCStorages(serverId?: number, node?: string, content?: string) {
|
|
const qs = new URLSearchParams();
|
|
if (node) qs.set('node', node);
|
|
if (content) qs.set('content', content);
|
|
const params = qs.toString() ? `?${qs.toString()}` : '';
|
|
return useQuery({
|
|
queryKey: lxcKeys.storages(serverId!, node, content),
|
|
queryFn: () =>
|
|
apiClient
|
|
.get<{ storages: { storage: string; type: string; avail: number; total: number }[] }>(
|
|
`/proxmox/api/lxc-storages/${serverId}${params}`,
|
|
)
|
|
.then((r) => r.storages),
|
|
enabled: !!serverId,
|
|
staleTime: 5 * 60 * 1000,
|
|
});
|
|
}
|
|
|
|
export function useDeployLXC() {
|
|
return useMutation({
|
|
mutationFn: (data: LXCDeployRequest) =>
|
|
apiClient.post<{ task_id: number; status: string; name: string }>('/proxmox/api/lxc/deploy', data),
|
|
});
|
|
}
|
|
|
|
export interface AvailableLXCTemplate {
|
|
template: string;
|
|
type?: string;
|
|
os?: string;
|
|
version?: string;
|
|
headline?: string;
|
|
section?: string;
|
|
package?: string;
|
|
[k: string]: unknown;
|
|
}
|
|
|
|
// Templates available to download from the PVE appliance repository for a node.
|
|
export function useAvailableLXCTemplates(serverId?: number, node?: string) {
|
|
return useQuery({
|
|
queryKey: ['available-lxc-templates', serverId, node],
|
|
queryFn: () =>
|
|
apiClient.get<AvailableLXCTemplate[]>(`/proxmox/api/${serverId}/available-lxc-templates?node=${encodeURIComponent(node!)}`),
|
|
enabled: !!serverId && !!node,
|
|
staleTime: 5 * 60 * 1000,
|
|
});
|
|
}
|
|
|
|
export function useDownloadLXCTemplate(serverId: number) {
|
|
const qc = useQueryClient();
|
|
return useMutation({
|
|
mutationFn: (data: { node: string; storage: string; template: string }) =>
|
|
apiClient.post<{ success?: boolean; upid?: string; task_id?: number }>(`/proxmox/api/${serverId}/download-lxc-template`, data),
|
|
onSuccess: () => {
|
|
qc.invalidateQueries({ queryKey: ['all-tasks'] });
|
|
qc.invalidateQueries({ queryKey: ['lxc-templates', serverId] });
|
|
},
|
|
});
|
|
}
|