Skip to content

Commit 8681d27

Browse files
committed
fix(vmware): don't fail when primary ip is not synced successfully
1 parent 3924860 commit 8681d27

File tree

2 files changed

+5
-9
lines changed

2 files changed

+5
-9
lines changed

internal/source/ovirt/ovirt_sync.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -503,13 +503,13 @@ func (o *OVirtSource) collectHostNicsData(nbHost *objects.Device, nbi *inventory
503503
// var nicType *objects.InterfaceType
504504
nicSpeedBips, exists := nic.Speed()
505505
if !exists {
506-
o.Logger.Warning(o.Ctx, "speed for oVirt nic with id ", nicID, " is empty.")
506+
o.Logger.Debugf(o.Ctx, "speed for oVirt nic with id %s is empty", nicID)
507507
}
508508
nicSpeedKbps := nicSpeedBips / constants.KB
509509

510510
nicMtu, exists := nic.Mtu()
511511
if !exists {
512-
o.Logger.Warning(o.Ctx, "mtu for oVirt nic with id ", nicID, " is empty.")
512+
o.Logger.Debugf(o.Ctx, "mtu for oVirt nic with id %s is empty", nicID)
513513
}
514514

515515
nicComment, _ := nic.Comment()

internal/source/vmware/vmware_sync.go

+3-7
Original file line numberDiff line numberDiff line change
@@ -890,10 +890,7 @@ func (vc *VmwareSource) syncVMInterfaces(nbi *inventory.NetboxInventory, vmwareV
890890
vmIPv4Addresses, vmIPv6Addresses = vc.addVMInterfaceIPs(nbi, nbVMInterface, nicIPv4Addresses, nicIPv6Addresses, vmIPv4Addresses, vmIPv6Addresses)
891891
}
892892
}
893-
err := vc.setVMPrimaryIPAddress(nbi, netboxVM, vmDefaultGatewayIpv4, vmDefaultGatewayIpv6, vmIPv4Addresses, vmIPv6Addresses)
894-
if err != nil {
895-
return fmt.Errorf("setting vm primary ip address: %s", err)
896-
}
893+
vc.setVMPrimaryIPAddress(nbi, netboxVM, vmDefaultGatewayIpv4, vmDefaultGatewayIpv6, vmIPv4Addresses, vmIPv6Addresses)
897894
return nil
898895
}
899896

@@ -1111,7 +1108,7 @@ func (vc *VmwareSource) addVMInterfaceIPs(nbi *inventory.NetboxInventory, nbVMIn
11111108
// we loop through all of the collected IPv4 and IPv6 addresses for the vm.
11121109
// If any of the ips is in the same subnet as the default gateway, we choose it.
11131110
// If there is no ip in the subnet of the default gateway, we choose the first one.
1114-
func (vc *VmwareSource) setVMPrimaryIPAddress(nbi *inventory.NetboxInventory, netboxVM *objects.VM, vmDefaultGatewayIpv4 string, vmDefaultGatewayIpv6 string, vmIPv4Addresses []*objects.IPAddress, vmIPv6Addresses []*objects.IPAddress) error {
1111+
func (vc *VmwareSource) setVMPrimaryIPAddress(nbi *inventory.NetboxInventory, netboxVM *objects.VM, vmDefaultGatewayIpv4 string, vmDefaultGatewayIpv6 string, vmIPv4Addresses []*objects.IPAddress, vmIPv6Addresses []*objects.IPAddress) {
11151112
if len(vmIPv4Addresses) > 0 || len(vmIPv6Addresses) > 0 {
11161113
var vmIPv4PrimaryAddress *objects.IPAddress
11171114
for _, addr := range vmIPv4Addresses {
@@ -1130,10 +1127,9 @@ func (vc *VmwareSource) setVMPrimaryIPAddress(nbi *inventory.NetboxInventory, ne
11301127
newNetboxVM.PrimaryIPv6 = vmIPv6PrimaryAddress
11311128
_, err := nbi.AddVM(vc.Ctx, &newNetboxVM)
11321129
if err != nil {
1133-
return fmt.Errorf("updating vm's primary ip: %s", err)
1130+
vc.Logger.Warningf(vc.Ctx, "updating vm's primary ip: %s", err)
11341131
}
11351132
}
1136-
return nil
11371133
}
11381134

11391135
func (vc *VmwareSource) addVMContact(nbi *inventory.NetboxInventory, nbVM *objects.VM, vmOwners []string, vmOwnerEmails []string) error {

0 commit comments

Comments
 (0)