mirror of
https://github.com/speatzle/nfsense.git
synced 2025-05-10 18:38:22 +00:00
remwork networkd templates
This commit is contained in:
parent
66dac3cd82
commit
61ccf4ec6a
13 changed files with 49 additions and 105 deletions
|
@ -1,47 +0,0 @@
|
|||
package interfaces
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
|
||||
"nfsense.net/nfsense/internal/definitions"
|
||||
)
|
||||
|
||||
func GenerateInterfacesFile(conf definitions.Config) (string, error) {
|
||||
buf := new(bytes.Buffer)
|
||||
err := templates.ExecuteTemplate(buf, "interfaces.tmpl", conf)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("executing template: %w", err)
|
||||
}
|
||||
return buf.String(), nil
|
||||
}
|
||||
|
||||
func ApplyInterfacesFile(content string) (string, error) {
|
||||
f, err := os.Create("interfaces.conf")
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("creating File: %w", err)
|
||||
}
|
||||
|
||||
_, err = f.WriteString(content + "\n")
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("writing File: %w", err)
|
||||
}
|
||||
|
||||
err = f.Sync()
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("syncing File: %w", err)
|
||||
}
|
||||
|
||||
cmd := exec.Command("ifreload", "-a")
|
||||
|
||||
var out bytes.Buffer
|
||||
cmd.Stdout = &out
|
||||
|
||||
err = cmd.Run()
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("reloading Interfaces: %w", err)
|
||||
}
|
||||
return out.String(), nil
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
package interfaces
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"text/template"
|
||||
)
|
||||
|
||||
//go:embed template
|
||||
var templateFS embed.FS
|
||||
var templates *template.Template
|
||||
|
||||
func init() {
|
||||
|
||||
var err error
|
||||
templates, err = template.New("").ParseFS(templateFS, "template/*.tmpl")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
|
@ -1,13 +0,0 @@
|
|||
[Match]
|
||||
{{ if .VlanID -}}
|
||||
OriginalName={{ .Name .VlanID }}
|
||||
{{- else -}}
|
||||
MACAddress={{ .Mac }}
|
||||
{{- end }}
|
||||
[Link]
|
||||
{{ if .VlanID -}}
|
||||
MACAddress={{ .Mac }}
|
||||
{{ end -}}
|
||||
{{ if .Alias -}}
|
||||
Alias={{ .Alias }}
|
||||
{{- end }}
|
|
@ -1,5 +0,0 @@
|
|||
[NetDev]
|
||||
Name={{ .Name }}
|
||||
Kind=vlan
|
||||
[VLAN]
|
||||
Id={{ .VlanID }}
|
|
@ -1,21 +0,0 @@
|
|||
[Match]
|
||||
{{ if .VlanID -}}
|
||||
OriginalName={{ .Name .VlanID }}
|
||||
{{- else -}}
|
||||
MACAddress={{ .Mac }}
|
||||
{{- end }}
|
||||
[Network]
|
||||
LLMNR=no
|
||||
{{- if and .DHCP4 .DHCP6 }}
|
||||
DHCP=yes
|
||||
{{- else if .DHCP4 }}
|
||||
DHCP=ipv4
|
||||
{{- else if .DHCP6 }}
|
||||
DHCP=ipv6
|
||||
{{- end }}
|
||||
{{- range .IPs }}
|
||||
Address={{ . }}
|
||||
{{- end }}
|
||||
{{- range .Vlans }}
|
||||
VLAN={{ VlanIDName . }}
|
||||
{{- end}}
|
5
internal/networkd/template/bond-membership.network.tmpl
Normal file
5
internal/networkd/template/bond-membership.network.tmpl
Normal file
|
@ -0,0 +1,5 @@
|
|||
[Match]
|
||||
Name= {{ .Name }}
|
||||
|
||||
[Network]
|
||||
Vlan= {{ .BondName }}
|
|
@ -0,0 +1,5 @@
|
|||
[Match]
|
||||
Name= {{ .Name }}
|
||||
|
||||
[Network]
|
||||
Bridge= {{ .BridgeName }}
|
|
@ -0,0 +1,9 @@
|
|||
[Match]
|
||||
Name= {{ .Name }}
|
||||
[Network]
|
||||
LLMNR=no
|
||||
{{ if eq .AddressingMode 2 }}
|
||||
DHCP=yes
|
||||
{{- else }}
|
||||
Address= {{ .Name }}
|
||||
{{- end }}
|
6
internal/networkd/template/create-bond.netdev.tmpl
Normal file
6
internal/networkd/template/create-bond.netdev.tmpl
Normal file
|
@ -0,0 +1,6 @@
|
|||
[NetDev]
|
||||
Name= {{ .Name }}
|
||||
Kind=bond
|
||||
|
||||
[Bond]
|
||||
Mode=active-backup
|
3
internal/networkd/template/create-bridge.netdev.tmpl
Normal file
3
internal/networkd/template/create-bridge.netdev.tmpl
Normal file
|
@ -0,0 +1,3 @@
|
|||
[NetDev]
|
||||
Name= {{ .Name }}
|
||||
Kind=bridge
|
6
internal/networkd/template/create-vlan.netdev.tmpl
Normal file
6
internal/networkd/template/create-vlan.netdev.tmpl
Normal file
|
@ -0,0 +1,6 @@
|
|||
[NetDev]
|
||||
Name= {{ .Name }}
|
||||
Kind=vlan
|
||||
|
||||
[VLAN]
|
||||
Id= {{ .VlanID }}
|
8
internal/networkd/template/rename-hardware.link.tmpl
Normal file
8
internal/networkd/template/rename-hardware.link.tmpl
Normal file
|
@ -0,0 +1,8 @@
|
|||
[Match]
|
||||
OriginalName= {{ .HardwareInterface }}
|
||||
|
||||
[Link]
|
||||
Name= {{ .Name }}
|
||||
{{ if .Alias -}}
|
||||
Alias= {{ .Alias }}
|
||||
{{- end }}
|
7
internal/networkd/template/vlan-assignments.network.tmpl
Normal file
7
internal/networkd/template/vlan-assignments.network.tmpl
Normal file
|
@ -0,0 +1,7 @@
|
|||
[Match]
|
||||
Name= {{ .Name }}
|
||||
|
||||
[Network]
|
||||
{{- range .Vlans }}
|
||||
VLAN= {{ . }}
|
||||
{{- end}}
|
Loading…
Add table
Reference in a new issue