fix(ipam): require resource name before allocating IP and fill missing fields on VM link
All checks were successful
Backend Tests / pytest (Python 3.12) (push) Successful in 46s
Deploy to Production / Trigger production update (push) Successful in 8s

- Validate resource name in auto-allocate form before sending request
- Fill resource_name, proxmox_node, resource_type, mac_address when syncing
  a VM that already has matching vmid/server_id but missing metadata

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-06-20 03:23:57 +05:00
parent 7546883393
commit 965fb858da
4 changed files with 12 additions and 1 deletions

View File

@@ -707,8 +707,16 @@ class IPAMService:
last_seen=utcnow()
)
else:
# Just update last_seen
# vmid/server already match — update last_seen and fill missing resource_name/node
existing.last_seen = utcnow()
if not existing.resource_name and vm_name:
existing.resource_name = vm_name
if not existing.proxmox_node and node:
existing.proxmox_node = node
if not existing.resource_type and vm_type:
existing.resource_type = vm_type
if mac_address and not existing.mac_address:
existing.mac_address = mac_address
self.db.commit()
return existing, None

View File

@@ -97,6 +97,7 @@ function AllocateCard() {
};
const handleAllocate = () => {
if (!networkId) { toast.error(t('ipam.select_network')); return; }
if (!resourceName.trim()) { toast.error(t('ipam.resource_required')); return; }
autoAllocate.mutate(
{ network_id: Number(networkId), resource_name: resourceName || undefined, hostname: hostname || undefined },
{

View File

@@ -583,6 +583,7 @@
"linked": "Linked",
"ip_history": "IP history lookup",
"pool_required_hint": "Auto-allocation requires an auto-assign pool in the network.",
"resource_required": "Please specify a resource before allocating an IP.",
"dashboard": "IPAM Dashboard",
"networks": "Networks",
"networks_count": "Networks",

View File

@@ -583,6 +583,7 @@
"linked": "Связано",
"ip_history": "История по IP",
"pool_required_hint": "Авто-выделение требует пул с auto-assign в сети.",
"resource_required": "Укажите ресурс перед выделением IP.",
"dashboard": "IPAM Дашборд",
"networks": "Сети",
"networks_count": "Сетей",