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:
@@ -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] });
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
@@ -79,3 +79,38 @@ export function useDeleteTemplate() {
|
||||
onSuccess: () => qc.invalidateQueries({ queryKey: ['templates'] }),
|
||||
});
|
||||
}
|
||||
|
||||
export interface QuickDeployInfo {
|
||||
template: { id: number; name: string; vmid?: number; node?: string; description?: string;
|
||||
default_cores: number; default_memory: number; default_disk: number;
|
||||
min_cores: number; min_memory: number; min_disk: number };
|
||||
group: { name?: string; icon?: string };
|
||||
server: { id?: number; name?: string };
|
||||
}
|
||||
|
||||
export function useQuickDeployInfo(templateId: number | null) {
|
||||
return useQuery({
|
||||
queryKey: ['quick-deploy', templateId],
|
||||
queryFn: () => apiClient.get<QuickDeployInfo>(`/templates/api/quick-deploy/${templateId}`),
|
||||
enabled: !!templateId,
|
||||
});
|
||||
}
|
||||
|
||||
export interface DeployVMArgs {
|
||||
template_id: number; name: string;
|
||||
cores?: number; memory?: number; disk?: number;
|
||||
target_node?: string; target_storage?: string;
|
||||
start_after_create?: boolean; onboot?: boolean;
|
||||
}
|
||||
|
||||
export function useDeployVM() {
|
||||
const qc = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: (data: DeployVMArgs) =>
|
||||
apiClient.post<{ task_id: number; status: string; name?: string }>('/templates/api/deploy', data),
|
||||
onSuccess: () => {
|
||||
qc.invalidateQueries({ queryKey: ['all-tasks'] });
|
||||
qc.invalidateQueries({ queryKey: ['virtual-machines'] });
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user