feat(quotas): per-user resource limits for VM/LXC deployment
Add per-user quotas (max instances, vCPU, RAM, disk) enforced at deploy time and surfaced to users self-service. Backend: - UserQuota model (one-to-one, NULL = unlimited) + migration #28 - quota_service: usage from vm_instances cache, check_quota raises 429 - enforce in VM (templates.py) and LXC (lxc.py) deploy paths - RBAC quota:view / quota:manage, granted to admin - admin API GET/PUT /admin/api/users/{id}/quota - self-service GET /settings/api/quota - tighten VM list isolation via can_view_all_instances Frontend: - admin quota dialog in UsersPage with usage bars - quota card on Settings page (own limits) - remaining-quota hint in CreateInstanceWizard config step - useUserQuota/useSetUserQuota, useMyQuota hooks; RU/EN locales Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -3,6 +3,7 @@ import { apiClient } from '@/lib/api-client';
|
||||
|
||||
export const settingsKeys = {
|
||||
profile: ['settings-profile'] as const,
|
||||
quota: ['settings-quota'] as const,
|
||||
panel: ['settings-panel'] as const,
|
||||
security: ['settings-security'] as const,
|
||||
channels: ['notification-channels'] as const,
|
||||
@@ -59,6 +60,25 @@ export function useProfile() {
|
||||
});
|
||||
}
|
||||
|
||||
export interface MyQuota {
|
||||
user_id: number;
|
||||
max_instances: number | null;
|
||||
max_cores: number | null;
|
||||
max_memory_mb: number | null;
|
||||
max_disk_gb: number | null;
|
||||
used_instances: number;
|
||||
used_cores: number;
|
||||
used_memory_mb: number;
|
||||
used_disk_gb: number;
|
||||
}
|
||||
|
||||
export function useMyQuota() {
|
||||
return useQuery({
|
||||
queryKey: settingsKeys.quota,
|
||||
queryFn: () => apiClient.get<MyQuota>('/settings/api/quota'),
|
||||
});
|
||||
}
|
||||
|
||||
export function useUpdateProfile() {
|
||||
const qc = useQueryClient();
|
||||
return useMutation({
|
||||
|
||||
@@ -6,6 +6,7 @@ export const userKeys = {
|
||||
users: ['users'] as const,
|
||||
user: (id: number) => ['user', id] as const,
|
||||
userServers: (id: number) => ['user-server-assignments', id] as const,
|
||||
userQuota: (id: number) => ['user-quota', id] as const,
|
||||
roles: ['roles'] as const,
|
||||
permissions: ['permissions-v2'] as const,
|
||||
sessions: ['sessions'] as const,
|
||||
@@ -208,6 +209,47 @@ export function useSetUserServers() {
|
||||
});
|
||||
}
|
||||
|
||||
// ==================== User → Quota ====================
|
||||
|
||||
export interface UserQuota {
|
||||
user_id: number;
|
||||
max_instances: number | null;
|
||||
max_cores: number | null;
|
||||
max_memory_mb: number | null;
|
||||
max_disk_gb: number | null;
|
||||
used_instances: number;
|
||||
used_cores: number;
|
||||
used_memory_mb: number;
|
||||
used_disk_gb: number;
|
||||
}
|
||||
|
||||
export interface SetUserQuotaPayload {
|
||||
max_instances?: number | null;
|
||||
max_cores?: number | null;
|
||||
max_memory_mb?: number | null;
|
||||
max_disk_gb?: number | null;
|
||||
}
|
||||
|
||||
export function useUserQuota(userId: number) {
|
||||
return useQuery({
|
||||
queryKey: userKeys.userQuota(userId),
|
||||
queryFn: () => apiClient.get<UserQuota>(`/admin/api/users/${userId}/quota`),
|
||||
enabled: userId > 0,
|
||||
});
|
||||
}
|
||||
|
||||
export function useSetUserQuota() {
|
||||
const qc = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: ({ userId, ...data }: { userId: number } & SetUserQuotaPayload) =>
|
||||
apiClient.put<UserQuota>(`/admin/api/users/${userId}/quota`, data),
|
||||
onSuccess: (_, vars) => {
|
||||
qc.invalidateQueries({ queryKey: userKeys.userQuota(vars.userId) });
|
||||
qc.invalidateQueries({ queryKey: userKeys.users });
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
// ==================== Roles ====================
|
||||
|
||||
export function useRoles() {
|
||||
|
||||
Reference in New Issue
Block a user