Skip to content

Commit

Permalink
fix(vmware): add vlan prefix to missing vlans
Browse files Browse the repository at this point in the history
This applies only to vlans that don't already start with vlan prefix
  • Loading branch information
bl4ko committed Feb 28, 2025
1 parent 08272fe commit 4c098e3
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion internal/source/vmware/vmware_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ func (vc *VmwareSource) syncNetworks(nbi *inventory.NetboxInventory) error {
return fmt.Errorf("vlanTenant: %s", err)
}
if len(dvpg.VlanIDs) == 1 && len(dvpg.VlanIDRanges) == 0 && dvpg.VlanIDs[0] != 0 {
vlanName := dvpg.Name
if !strings.HasPrefix(vlanName, "VLAN") {
vlanName = fmt.Sprintf("VLAN%04d_%s", dvpg.VlanIDs[0], vlanName)
}
networkTags := vc.Object2NBTags[dvpgID]
vlanStruct := &objects.Vlan{
NetboxObject: objects.NetboxObject{
Expand All @@ -86,7 +90,7 @@ func (vc *VmwareSource) syncNetworks(nbi *inventory.NetboxInventory) error {
constants.CustomFieldSourceIDName: dvpgID,
},
},
Name: dvpg.Name,
Name: vlanName,
Group: vlanGroup,
Site: vlanSite,
Vid: dvpg.VlanIDs[0],
Expand Down Expand Up @@ -580,6 +584,9 @@ func (vc *VmwareSource) collectHostPhysicalNicData(
}
} else {
vlanName := portgroupName
if !strings.HasPrefix(vlanName, "VLAN") {
vlanName = fmt.Sprintf("VLAN%04d_%s", portgroupData.vlanID, vlanName)
}
vlanSite, err := common.MatchVlanToSite(vc.Ctx, nbi, vlanName, vc.SourceConfig.VlanSiteRelations)
if err != nil {
return nil, "", fmt.Errorf("match vlan to site: %s", err)
Expand Down

0 comments on commit 4c098e3

Please sign in to comment.