Skip to content

Commit 55d60a3

Browse files
committed
fix: adding vlan tenant relation for fortigate and paloalto, also prefix have same tenant as vlan
1 parent 5aa72bd commit 55d60a3

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

README.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,9 @@ source:
142142
hostTenantRelations:
143143
- .* = MyTenant
144144
hostSiteRelations:
145-
- .* = MySite
145+
- .* = MyTenant
146+
hostTenantRelations:
147+
- .* = MyTenant
146148

147149
- name: pa-uk
148150
type: paloalto
@@ -151,6 +153,10 @@ source:
151153
password: passw0rd
152154
hostTenantRelations:
153155
- .* = MyTenant
156+
hostSiteRelations:
157+
- .* = MySite
158+
vlanTenantRelations:
159+
- .* = MyTenant
154160

155161
- name: dnacenter
156162
type: dnac

internal/source/fortigate/fortigate_sync.go

+6
Original file line numberDiff line numberDiff line change
@@ -174,13 +174,18 @@ func (fs *FortigateSource) SyncInterfaces(nbi *inventory.NetboxInventory) error
174174
if err != nil {
175175
return fmt.Errorf("match vlan to group: %s", err)
176176
}
177+
vlanTenant, err := common.MatchVlanToTenant(fs.Ctx, nbi, vlanName, fs.VlanTenantRelations)
178+
if err != nil {
179+
return fmt.Errorf("match vlan to tenant: %s", err)
180+
}
177181
NBVlan, err := nbi.AddVlan(fs.Ctx, &objects.Vlan{
178182
NetboxObject: objects.NetboxObject{
179183
Tags: fs.SourceTags,
180184
},
181185
Status: &objects.VlanStatusActive,
182186
Name: vlanName,
183187
Vid: vlanID,
188+
Tenant: vlanTenant,
184189
Group: vlanGroup,
185190
})
186191
if err != nil {
@@ -196,6 +201,7 @@ func (fs *FortigateSource) SyncInterfaces(nbi *inventory.NetboxInventory) error
196201
}
197202
_, err = nbi.AddPrefix(fs.Ctx, &objects.Prefix{
198203
Prefix: prefix,
204+
Tenant: NBVlan.Tenant,
199205
Vlan: NBVlan,
200206
})
201207
if err != nil {

internal/source/paloalto/paloalto_sync.go

+12-1
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,15 @@ func (pas *PaloAltoSource) SyncInterfaces(nbi *inventory.NetboxInventory) error
156156
var subifaceMode *objects.InterfaceMode
157157
if subIface.Tag != 0 {
158158
// Extract Vlan
159-
vlanGroup, err := common.MatchVlanToGroup(pas.Ctx, nbi, fmt.Sprintf("Vlan%d", subIface.Tag), pas.VlanGroupRelations)
159+
vlanName := fmt.Sprintf("Vlan%d", subIface.Tag)
160+
vlanGroup, err := common.MatchVlanToGroup(pas.Ctx, nbi, vlanName, pas.VlanGroupRelations)
160161
if err != nil {
161162
return fmt.Errorf("match vlan to group: %s", err)
162163
}
164+
vlanTenant, err := common.MatchVlanToTenant(pas.Ctx, nbi, vlanName, pas.VlanTenantRelations)
165+
if err != nil {
166+
return fmt.Errorf("match vlan to tenant: %s", err)
167+
}
163168
subIfaceVlan, err = nbi.AddVlan(pas.Ctx, &objects.Vlan{
164169
NetboxObject: objects.NetboxObject{
165170
Tags: pas.SourceTags,
@@ -168,6 +173,7 @@ func (pas *PaloAltoSource) SyncInterfaces(nbi *inventory.NetboxInventory) error
168173
Status: &objects.VlanStatusActive,
169174
Name: fmt.Sprintf("Vlan%d", subIface.Tag),
170175
Vid: subIface.Tag,
176+
Tenant: vlanTenant,
171177
Group: vlanGroup,
172178
})
173179
if err != nil {
@@ -228,8 +234,13 @@ func (pas *PaloAltoSource) syncIPs(nbi *inventory.NetboxInventory, nbIface *obje
228234
if err != nil {
229235
pas.Logger.Warningf(pas.Ctx, "extract prefix from address: %s", err)
230236
} else {
237+
var prefixTenant *objects.Tenant
238+
if prefixVlan != nil {
239+
prefixTenant = prefixVlan.Tenant
240+
}
231241
_, err = nbi.AddPrefix(pas.Ctx, &objects.Prefix{
232242
Prefix: prefix,
243+
Tenant: prefixTenant,
233244
Vlan: prefixVlan,
234245
})
235246
if err != nil {

0 commit comments

Comments
 (0)