Skip to content

Commit

Permalink
fix(vmware): don't fail when primary ip is not synced successfully
Browse files Browse the repository at this point in the history
  • Loading branch information
bl4ko committed May 13, 2024
1 parent 3924860 commit 8681d27
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
4 changes: 2 additions & 2 deletions internal/source/ovirt/ovirt_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -503,13 +503,13 @@ func (o *OVirtSource) collectHostNicsData(nbHost *objects.Device, nbi *inventory
// var nicType *objects.InterfaceType
nicSpeedBips, exists := nic.Speed()
if !exists {
o.Logger.Warning(o.Ctx, "speed for oVirt nic with id ", nicID, " is empty.")
o.Logger.Debugf(o.Ctx, "speed for oVirt nic with id %s is empty", nicID)

Check warning on line 506 in internal/source/ovirt/ovirt_sync.go

View check run for this annotation

Codecov / codecov/patch

internal/source/ovirt/ovirt_sync.go#L506

Added line #L506 was not covered by tests
}
nicSpeedKbps := nicSpeedBips / constants.KB

nicMtu, exists := nic.Mtu()
if !exists {
o.Logger.Warning(o.Ctx, "mtu for oVirt nic with id ", nicID, " is empty.")
o.Logger.Debugf(o.Ctx, "mtu for oVirt nic with id %s is empty", nicID)

Check warning on line 512 in internal/source/ovirt/ovirt_sync.go

View check run for this annotation

Codecov / codecov/patch

internal/source/ovirt/ovirt_sync.go#L512

Added line #L512 was not covered by tests
}

nicComment, _ := nic.Comment()
Expand Down
10 changes: 3 additions & 7 deletions internal/source/vmware/vmware_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -890,10 +890,7 @@ func (vc *VmwareSource) syncVMInterfaces(nbi *inventory.NetboxInventory, vmwareV
vmIPv4Addresses, vmIPv6Addresses = vc.addVMInterfaceIPs(nbi, nbVMInterface, nicIPv4Addresses, nicIPv6Addresses, vmIPv4Addresses, vmIPv6Addresses)
}
}
err := vc.setVMPrimaryIPAddress(nbi, netboxVM, vmDefaultGatewayIpv4, vmDefaultGatewayIpv6, vmIPv4Addresses, vmIPv6Addresses)
if err != nil {
return fmt.Errorf("setting vm primary ip address: %s", err)
}
vc.setVMPrimaryIPAddress(nbi, netboxVM, vmDefaultGatewayIpv4, vmDefaultGatewayIpv6, vmIPv4Addresses, vmIPv6Addresses)

Check warning on line 893 in internal/source/vmware/vmware_sync.go

View check run for this annotation

Codecov / codecov/patch

internal/source/vmware/vmware_sync.go#L893

Added line #L893 was not covered by tests
return nil
}

Expand Down Expand Up @@ -1111,7 +1108,7 @@ func (vc *VmwareSource) addVMInterfaceIPs(nbi *inventory.NetboxInventory, nbVMIn
// we loop through all of the collected IPv4 and IPv6 addresses for the vm.
// If any of the ips is in the same subnet as the default gateway, we choose it.
// If there is no ip in the subnet of the default gateway, we choose the first one.
func (vc *VmwareSource) setVMPrimaryIPAddress(nbi *inventory.NetboxInventory, netboxVM *objects.VM, vmDefaultGatewayIpv4 string, vmDefaultGatewayIpv6 string, vmIPv4Addresses []*objects.IPAddress, vmIPv6Addresses []*objects.IPAddress) error {
func (vc *VmwareSource) setVMPrimaryIPAddress(nbi *inventory.NetboxInventory, netboxVM *objects.VM, vmDefaultGatewayIpv4 string, vmDefaultGatewayIpv6 string, vmIPv4Addresses []*objects.IPAddress, vmIPv6Addresses []*objects.IPAddress) {

Check warning on line 1111 in internal/source/vmware/vmware_sync.go

View check run for this annotation

Codecov / codecov/patch

internal/source/vmware/vmware_sync.go#L1111

Added line #L1111 was not covered by tests
if len(vmIPv4Addresses) > 0 || len(vmIPv6Addresses) > 0 {
var vmIPv4PrimaryAddress *objects.IPAddress
for _, addr := range vmIPv4Addresses {
Expand All @@ -1130,10 +1127,9 @@ func (vc *VmwareSource) setVMPrimaryIPAddress(nbi *inventory.NetboxInventory, ne
newNetboxVM.PrimaryIPv6 = vmIPv6PrimaryAddress
_, err := nbi.AddVM(vc.Ctx, &newNetboxVM)
if err != nil {
return fmt.Errorf("updating vm's primary ip: %s", err)
vc.Logger.Warningf(vc.Ctx, "updating vm's primary ip: %s", err)

Check warning on line 1130 in internal/source/vmware/vmware_sync.go

View check run for this annotation

Codecov / codecov/patch

internal/source/vmware/vmware_sync.go#L1130

Added line #L1130 was not covered by tests
}
}
return nil
}

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

0 comments on commit 8681d27

Please sign in to comment.