mirror of
https://github.com/speatzle/nfsense.git
synced 2025-05-11 02:48:21 +00:00
move vlan-assignments into config-addressing
This commit is contained in:
parent
fc49a2479e
commit
dec123e9ee
3 changed files with 9 additions and 38 deletions
|
@ -16,6 +16,7 @@ type NetworkdConfigFile struct {
|
||||||
type InterfaceWithName struct {
|
type InterfaceWithName struct {
|
||||||
Name string
|
Name string
|
||||||
definitions.Interface
|
definitions.Interface
|
||||||
|
Vlans []string
|
||||||
}
|
}
|
||||||
|
|
||||||
type BondMembership struct {
|
type BondMembership struct {
|
||||||
|
@ -28,11 +29,6 @@ type BridgeMembership struct {
|
||||||
BridgeName string
|
BridgeName string
|
||||||
}
|
}
|
||||||
|
|
||||||
type VlanAssignments struct {
|
|
||||||
Name string
|
|
||||||
Vlans []string
|
|
||||||
}
|
|
||||||
|
|
||||||
func GenerateNetworkdConfiguration(conf definitions.Config) ([]NetworkdConfigFile, error) {
|
func GenerateNetworkdConfiguration(conf definitions.Config) ([]NetworkdConfigFile, error) {
|
||||||
files := []NetworkdConfigFile{}
|
files := []NetworkdConfigFile{}
|
||||||
|
|
||||||
|
@ -130,8 +126,9 @@ func GenerateNetworkdConfiguration(conf definitions.Config) ([]NetworkdConfigFil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Step 6 Generate Vlan Assignments
|
// Step 6 Generate addressing network files
|
||||||
for name, inter := range conf.Network.Interfaces {
|
for name, inter := range conf.Network.Interfaces {
|
||||||
|
vlans := []string{}
|
||||||
if inter.Type != definitions.Vlan {
|
if inter.Type != definitions.Vlan {
|
||||||
vlans := []string{}
|
vlans := []string{}
|
||||||
for vlanName, vlanInter := range conf.Network.Interfaces {
|
for vlanName, vlanInter := range conf.Network.Interfaces {
|
||||||
|
@ -141,42 +138,20 @@ func GenerateNetworkdConfiguration(conf definitions.Config) ([]NetworkdConfigFil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
slog.Info("Vlans on interface", "interface", name, "count", len(vlans))
|
slog.Info("Vlans on interface", "interface", name, "count", len(vlans))
|
||||||
|
|
||||||
if len(vlans) != 0 {
|
|
||||||
parentName := name
|
|
||||||
if inter.Type == definitions.Hardware {
|
|
||||||
parentName = *inter.HardwareDevice
|
|
||||||
}
|
|
||||||
buf := new(bytes.Buffer)
|
|
||||||
err := templates.ExecuteTemplate(buf, "vlan-assignments.network.tmpl", VlanAssignments{
|
|
||||||
Name: parentName,
|
|
||||||
Vlans: vlans,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("executing vlan-assignments.network.tmpl template: %w", err)
|
|
||||||
}
|
|
||||||
files = append(files, NetworkdConfigFile{
|
|
||||||
Name: fmt.Sprintf("60-vlan-assignments-%v.network", name),
|
|
||||||
Content: buf.String(),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Step 7 Generate addressing network files
|
|
||||||
for name, inter := range conf.Network.Interfaces {
|
|
||||||
buf := new(bytes.Buffer)
|
buf := new(bytes.Buffer)
|
||||||
err := templates.ExecuteTemplate(buf, "config-addressing.network.tmpl", InterfaceWithName{
|
err := templates.ExecuteTemplate(buf, "config-addressing.network.tmpl", InterfaceWithName{
|
||||||
Name: name,
|
Name: name,
|
||||||
Interface: inter,
|
Interface: inter,
|
||||||
|
Vlans: vlans,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("executing config-addressing.network.tmpl template: %w", err)
|
return nil, fmt.Errorf("executing config-addressing.network.tmpl template: %w", err)
|
||||||
}
|
}
|
||||||
files = append(files, NetworkdConfigFile{
|
files = append(files, NetworkdConfigFile{
|
||||||
Name: fmt.Sprintf("70-config-addressing-%v.network", name),
|
Name: fmt.Sprintf("60-config-addressing-%v.network", name),
|
||||||
Content: buf.String(),
|
Content: buf.String(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,3 +12,6 @@ Address={{ .Address }}
|
||||||
{{- else if eq .AddressingMode 2 }}
|
{{- else if eq .AddressingMode 2 }}
|
||||||
DHCP=yes
|
DHCP=yes
|
||||||
{{- end }}
|
{{- end }}
|
||||||
|
{{- range .Vlans }}
|
||||||
|
VLAN={{ . }}
|
||||||
|
{{- end}}
|
|
@ -1,7 +0,0 @@
|
||||||
[Match]
|
|
||||||
Name={{ .Name }}
|
|
||||||
|
|
||||||
[Network]
|
|
||||||
{{- range .Vlans }}
|
|
||||||
VLAN={{ . }}
|
|
||||||
{{- end}}
|
|
Loading…
Add table
Reference in a new issue