From 176228381b91db14533d28f00a848918ee82a42c Mon Sep 17 00:00:00 2001 From: rcourtman Date: Fri, 27 Mar 2026 11:27:15 +0000 Subject: [PATCH] Preserve guest NIC identity before IP assignment (#1319) --- internal/monitoring/guest_metadata.go | 11 ++++++++++- internal/monitoring/guest_metadata_test.go | 17 ++++++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/internal/monitoring/guest_metadata.go b/internal/monitoring/guest_metadata.go index d6e3fd43c..e6016fbff 100644 --- a/internal/monitoring/guest_metadata.go +++ b/internal/monitoring/guest_metadata.go @@ -592,7 +592,16 @@ func processGuestNetworkInterfaces(raw []proxmox.VMNetworkInterface) ([]string, txBytes := parseInterfaceStat(iface.Statistics, "tx-bytes") if len(addresses) == 0 && rxBytes == 0 && txBytes == 0 { - continue + if len(iface.IPAddresses) > 0 { + continue + } + lowerName := strings.ToLower(ifaceName) + if ifaceName == "" || lowerName == "lo" || lowerName == "loopback" { + continue + } + if mac == "" || mac == "00:00:00:00:00:00" { + continue + } } guestIfaces = append(guestIfaces, models.GuestNetworkInterface{ diff --git a/internal/monitoring/guest_metadata_test.go b/internal/monitoring/guest_metadata_test.go index e076d04f0..23c00d188 100644 --- a/internal/monitoring/guest_metadata_test.go +++ b/internal/monitoring/guest_metadata_test.go @@ -508,7 +508,7 @@ func TestProcessGuestNetworkInterfaces(t *testing.T) { }, }, { - name: "interface with no IPs and no traffic is excluded", + name: "interface with no IPs and no traffic keeps non-loopback identity", raw: []proxmox.VMNetworkInterface{ { Name: "eth0", @@ -517,6 +517,21 @@ func TestProcessGuestNetworkInterfaces(t *testing.T) { Statistics: nil, }, }, + wantIPs: []string{}, + wantIfaces: []models.GuestNetworkInterface{ + {Name: "eth0", MAC: "00:11:22:33:44:55", Addresses: nil}, + }, + }, + { + name: "loopback-only interface with no IPs and no traffic is excluded", + raw: []proxmox.VMNetworkInterface{ + { + Name: "lo", + HardwareAddr: "00:00:00:00:00:00", + IPAddresses: nil, + Statistics: nil, + }, + }, wantIPs: []string{}, wantIfaces: []models.GuestNetworkInterface{}, },