move vlan-assignments into config-addressing

This commit is contained in:
Samuel Lorch 2023-04-08 15:01:28 +02:00
parent fc49a2479e
commit dec123e9ee
3 changed files with 9 additions and 38 deletions

View file

@ -16,6 +16,7 @@ type NetworkdConfigFile struct {
type InterfaceWithName struct {
Name string
definitions.Interface
Vlans []string
}
type BondMembership struct {
@ -28,11 +29,6 @@ type BridgeMembership struct {
BridgeName string
}
type VlanAssignments struct {
Name string
Vlans []string
}
func GenerateNetworkdConfiguration(conf definitions.Config) ([]NetworkdConfigFile, error) {
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 {
vlans := []string{}
if inter.Type != definitions.Vlan {
vlans := []string{}
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))
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)
err := templates.ExecuteTemplate(buf, "config-addressing.network.tmpl", InterfaceWithName{
Name: name,
Interface: inter,
Vlans: vlans,
})
if err != nil {
return nil, fmt.Errorf("executing config-addressing.network.tmpl template: %w", err)
}
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(),
})
}

View file

@ -11,4 +11,7 @@ LLMNR=no
Address={{ .Address }}
{{- else if eq .AddressingMode 2 }}
DHCP=yes
{{- end }}
{{- end }}
{{- range .Vlans }}
VLAN={{ . }}
{{- end}}

View file

@ -1,7 +0,0 @@
[Match]
Name={{ .Name }}
[Network]
{{- range .Vlans }}
VLAN={{ . }}
{{- end}}