feat(instances): add VM/LXC migration, autostart/boot order, protection
- 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
This commit is contained in:
@@ -24,6 +24,52 @@ export function useProxmoxBackupJobs(serverId: number) {
|
||||
});
|
||||
}
|
||||
|
||||
export type ProxmoxJobInput = {
|
||||
id?: string;
|
||||
schedule: string;
|
||||
storage: string;
|
||||
mode?: string;
|
||||
compress?: string;
|
||||
enabled?: boolean;
|
||||
selection_mode?: 'all' | 'vmid' | 'pool';
|
||||
vmid?: string;
|
||||
pool?: string;
|
||||
node?: string;
|
||||
keep_last?: number;
|
||||
keep_daily?: number;
|
||||
keep_weekly?: number;
|
||||
keep_monthly?: number;
|
||||
comment?: string;
|
||||
mailto?: string;
|
||||
};
|
||||
|
||||
export function useCreateProxmoxJob(serverId: number) {
|
||||
const qc = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: (data: ProxmoxJobInput) =>
|
||||
apiClient.post<{ success: boolean }>(`/proxmox/api/backups/proxmox-jobs/${serverId}`, data),
|
||||
onSuccess: () => qc.invalidateQueries({ queryKey: backupKeys.proxmoxJobs(serverId) }),
|
||||
});
|
||||
}
|
||||
|
||||
export function useUpdateProxmoxJob(serverId: number) {
|
||||
const qc = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: ({ id, data }: { id: string; data: ProxmoxJobInput }) =>
|
||||
apiClient.put<{ success: boolean }>(`/proxmox/api/backups/proxmox-jobs/${serverId}/${id}`, data),
|
||||
onSuccess: () => qc.invalidateQueries({ queryKey: backupKeys.proxmoxJobs(serverId) }),
|
||||
});
|
||||
}
|
||||
|
||||
export function useDeleteProxmoxJob(serverId: number) {
|
||||
const qc = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: (jobId: string) =>
|
||||
apiClient.delete<{ success: boolean }>(`/proxmox/api/backups/proxmox-jobs/${serverId}/${jobId}`),
|
||||
onSuccess: () => qc.invalidateQueries({ queryKey: backupKeys.proxmoxJobs(serverId) }),
|
||||
});
|
||||
}
|
||||
|
||||
export function useCreateStorage(serverId: number) {
|
||||
const qc = useQueryClient();
|
||||
return useMutation({
|
||||
|
||||
@@ -75,6 +75,7 @@ export interface ImageDownloadRequest {
|
||||
checksum_algorithm?: string;
|
||||
// Авто-конвертация qcow2 → VM-шаблон
|
||||
to_template?: boolean;
|
||||
vmid?: number;
|
||||
disk_storage?: string;
|
||||
cores?: number;
|
||||
memory?: number;
|
||||
|
||||
@@ -604,6 +604,21 @@ export function useReinstallInstance(serverId: number, vmid: number, node: strin
|
||||
});
|
||||
}
|
||||
|
||||
// ==================== Migrate ====================
|
||||
export interface MigrateRequest {
|
||||
target_node: string;
|
||||
target_storage?: string;
|
||||
online?: boolean;
|
||||
}
|
||||
|
||||
export function useMigrateInstance(serverId: number, vmid: number, type: string, node: string) {
|
||||
const prefix = type === 'lxc' ? 'container' : 'vm';
|
||||
return useMutation<AsyncTaskResponse, Error, MigrateRequest>({
|
||||
mutationFn: (body) =>
|
||||
apiClient.post(`/proxmox/api/${serverId}/${prefix}/${vmid}/migrate?node=${node}`, body),
|
||||
});
|
||||
}
|
||||
|
||||
// ==================== Change Password ====================
|
||||
export function useChangePassword(serverId: number, vmid: number, type: string, node: string) {
|
||||
const prefix = type === 'lxc' ? 'container' : 'vm';
|
||||
|
||||
@@ -4,7 +4,8 @@ import type { LXCTemplate, LXCDeployRequest } from '@/types';
|
||||
|
||||
export const lxcKeys = {
|
||||
templates: (serverId: number) => ['lxc-templates', serverId] as const,
|
||||
storages: (serverId: number, node?: string) => ['lxc-storages', serverId, node] as const,
|
||||
storages: (serverId: number, node?: string, content?: string) =>
|
||||
['lxc-storages', serverId, node, content] as const,
|
||||
};
|
||||
|
||||
// CT templates change rarely — cache for 5 minutes
|
||||
@@ -20,11 +21,15 @@ export function useLXCTemplates(serverId?: number) {
|
||||
});
|
||||
}
|
||||
|
||||
// Storage list changes rarely — cache for 5 minutes
|
||||
export function useLXCStorages(serverId?: number, node?: string) {
|
||||
const params = node ? `?node=${encodeURIComponent(node)}` : '';
|
||||
// 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),
|
||||
queryKey: lxcKeys.storages(serverId!, node, content),
|
||||
queryFn: () =>
|
||||
apiClient
|
||||
.get<{ storages: { storage: string; type: string; avail: number; total: number }[] }>(
|
||||
|
||||
@@ -13,6 +13,14 @@ export function useTemplateGroups() {
|
||||
return useQuery({
|
||||
queryKey: templateKeys.groups,
|
||||
queryFn: () => apiClient.get<OSTemplateGroup[]>('/templates/api/groups'),
|
||||
// Список групп ОС — по алфавиту; «Other» (корзина «прочее») всегда в конце.
|
||||
select: (groups) =>
|
||||
[...groups].sort((a, b) => {
|
||||
const aOther = a.name.toLowerCase() === 'other';
|
||||
const bOther = b.name.toLowerCase() === 'other';
|
||||
if (aOther !== bOther) return aOther ? 1 : -1;
|
||||
return a.name.localeCompare(b.name, undefined, { sensitivity: 'base' });
|
||||
}),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -25,6 +33,11 @@ export function useTemplates(groupId?: number, serverId?: number, vmType?: strin
|
||||
return useQuery({
|
||||
queryKey: templateKeys.templates(groupId, serverId, vmType),
|
||||
queryFn: () => apiClient.get<OSTemplate[]>(`/templates/api/templates${qs ? `?${qs}` : ''}`),
|
||||
// Шаблоны — по имени, по алфавиту (с числовой сортировкой: Debian-9 < Debian-11).
|
||||
select: (templates) =>
|
||||
[...templates].sort((a, b) =>
|
||||
a.name.localeCompare(b.name, undefined, { numeric: true, sensitivity: 'base' }),
|
||||
),
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user