feat(templates): add quick-deploy and CT template download

Per-template Deploy button opens a quick-deploy dialog (prefilled from the
quick-deploy endpoint defaults) that creates a VM via /templates/api/deploy.
New 'Download CT template' dialog browses the node's appliance repository
(available-lxc-templates) and pulls a template to a vztmpl storage.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-06-15 00:29:34 +05:00
parent 508be2423a
commit 5d6acd619e
6 changed files with 296 additions and 5 deletions

View File

@@ -1,4 +1,4 @@
import { useQuery, useMutation } from '@tanstack/react-query';
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
import { apiClient } from '@/lib/api-client';
import type { LXCTemplate, LXCDeployRequest } from '@/types';
@@ -42,3 +42,37 @@ export function useDeployLXC() {
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] });
},
});
}