Skip to content

Commit

Permalink
fix: adding vlan tenant relation for fortigate and paloalto, also pre…
Browse files Browse the repository at this point in the history
…fix have same tenant as vlan
  • Loading branch information
bl4ko committed Apr 16, 2024
1 parent 5aa72bd commit 55d60a3
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,9 @@ source:
hostTenantRelations:
- .* = MyTenant
hostSiteRelations:
- .* = MySite
- .* = MyTenant
hostTenantRelations:
- .* = MyTenant

- name: pa-uk
type: paloalto
Expand All @@ -151,6 +153,10 @@ source:
password: passw0rd
hostTenantRelations:
- .* = MyTenant
hostSiteRelations:
- .* = MySite
vlanTenantRelations:
- .* = MyTenant

- name: dnacenter
type: dnac
Expand Down
6 changes: 6 additions & 0 deletions internal/source/fortigate/fortigate_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,18 @@ func (fs *FortigateSource) SyncInterfaces(nbi *inventory.NetboxInventory) error
if err != nil {
return fmt.Errorf("match vlan to group: %s", err)
}
vlanTenant, err := common.MatchVlanToTenant(fs.Ctx, nbi, vlanName, fs.VlanTenantRelations)
if err != nil {
return fmt.Errorf("match vlan to tenant: %s", err)

Check warning on line 179 in internal/source/fortigate/fortigate_sync.go

View check run for this annotation

Codecov / codecov/patch

internal/source/fortigate/fortigate_sync.go#L177-L179

Added lines #L177 - L179 were not covered by tests
}
NBVlan, err := nbi.AddVlan(fs.Ctx, &objects.Vlan{
NetboxObject: objects.NetboxObject{
Tags: fs.SourceTags,
},
Status: &objects.VlanStatusActive,
Name: vlanName,
Vid: vlanID,
Tenant: vlanTenant,

Check warning on line 188 in internal/source/fortigate/fortigate_sync.go

View check run for this annotation

Codecov / codecov/patch

internal/source/fortigate/fortigate_sync.go#L188

Added line #L188 was not covered by tests
Group: vlanGroup,
})
if err != nil {
Expand All @@ -196,6 +201,7 @@ func (fs *FortigateSource) SyncInterfaces(nbi *inventory.NetboxInventory) error
}
_, err = nbi.AddPrefix(fs.Ctx, &objects.Prefix{
Prefix: prefix,
Tenant: NBVlan.Tenant,

Check warning on line 204 in internal/source/fortigate/fortigate_sync.go

View check run for this annotation

Codecov / codecov/patch

internal/source/fortigate/fortigate_sync.go#L204

Added line #L204 was not covered by tests
Vlan: NBVlan,
})
if err != nil {
Expand Down
13 changes: 12 additions & 1 deletion internal/source/paloalto/paloalto_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,15 @@ func (pas *PaloAltoSource) SyncInterfaces(nbi *inventory.NetboxInventory) error
var subifaceMode *objects.InterfaceMode
if subIface.Tag != 0 {
// Extract Vlan
vlanGroup, err := common.MatchVlanToGroup(pas.Ctx, nbi, fmt.Sprintf("Vlan%d", subIface.Tag), pas.VlanGroupRelations)
vlanName := fmt.Sprintf("Vlan%d", subIface.Tag)
vlanGroup, err := common.MatchVlanToGroup(pas.Ctx, nbi, vlanName, pas.VlanGroupRelations)

Check warning on line 160 in internal/source/paloalto/paloalto_sync.go

View check run for this annotation

Codecov / codecov/patch

internal/source/paloalto/paloalto_sync.go#L159-L160

Added lines #L159 - L160 were not covered by tests
if err != nil {
return fmt.Errorf("match vlan to group: %s", err)
}
vlanTenant, err := common.MatchVlanToTenant(pas.Ctx, nbi, vlanName, pas.VlanTenantRelations)
if err != nil {
return fmt.Errorf("match vlan to tenant: %s", err)

Check warning on line 166 in internal/source/paloalto/paloalto_sync.go

View check run for this annotation

Codecov / codecov/patch

internal/source/paloalto/paloalto_sync.go#L164-L166

Added lines #L164 - L166 were not covered by tests
}
subIfaceVlan, err = nbi.AddVlan(pas.Ctx, &objects.Vlan{
NetboxObject: objects.NetboxObject{
Tags: pas.SourceTags,
Expand All @@ -168,6 +173,7 @@ func (pas *PaloAltoSource) SyncInterfaces(nbi *inventory.NetboxInventory) error
Status: &objects.VlanStatusActive,
Name: fmt.Sprintf("Vlan%d", subIface.Tag),
Vid: subIface.Tag,
Tenant: vlanTenant,

Check warning on line 176 in internal/source/paloalto/paloalto_sync.go

View check run for this annotation

Codecov / codecov/patch

internal/source/paloalto/paloalto_sync.go#L176

Added line #L176 was not covered by tests
Group: vlanGroup,
})
if err != nil {
Expand Down Expand Up @@ -228,8 +234,13 @@ func (pas *PaloAltoSource) syncIPs(nbi *inventory.NetboxInventory, nbIface *obje
if err != nil {
pas.Logger.Warningf(pas.Ctx, "extract prefix from address: %s", err)
} else {
var prefixTenant *objects.Tenant
if prefixVlan != nil {
prefixTenant = prefixVlan.Tenant

Check warning on line 239 in internal/source/paloalto/paloalto_sync.go

View check run for this annotation

Codecov / codecov/patch

internal/source/paloalto/paloalto_sync.go#L237-L239

Added lines #L237 - L239 were not covered by tests
}
_, err = nbi.AddPrefix(pas.Ctx, &objects.Prefix{
Prefix: prefix,
Tenant: prefixTenant,

Check warning on line 243 in internal/source/paloalto/paloalto_sync.go

View check run for this annotation

Codecov / codecov/patch

internal/source/paloalto/paloalto_sync.go#L243

Added line #L243 was not covered by tests
Vlan: prefixVlan,
})
if err != nil {
Expand Down

0 comments on commit 55d60a3

Please sign in to comment.