-
Notifications
You must be signed in to change notification settings - Fork 2
/
systemd.go
82 lines (68 loc) · 2.22 KB
/
systemd.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package netconf
import (
"fmt"
"github.com/metal-stack/metal-go/api/models"
"github.com/metal-stack/metal-networker/pkg/net"
)
const (
// tplSystemdLinkLan defines the name of the template to render system.link file.
tplSystemdLinkLan = "networkd/10-lan.link.tpl"
tplSystemdNetworkLo = "networkd/00-lo.network.tpl"
// tplSystemdNetworkLan defines the name of the template to render system.network file.
tplSystemdNetworkLan = "networkd/10-lan.network.tpl"
// mtuFirewall defines the value for MTU specific to the needs of a firewall. VXLAN requires higher MTU.
mtuFirewall = 9216
// mtuMachine defines the value for MTU specific to the needs of a machine.
mtuMachine = 9000
)
type (
// SystemdCommonData contains attributes common to systemd.network and systemd.link files.
SystemdCommonData struct {
Comment string
Index int
}
// SystemdLinkData contains attributes required to render systemd.link files.
SystemdLinkData struct {
SystemdCommonData
MAC string
MTU int
EVPNIfaces []EVPNIface
}
// systemdValidator validates systemd.network and system.link files.
systemdValidator struct {
path string
}
)
// newSystemdNetworkdApplier creates a new Applier to configure systemd.network.
func newSystemdNetworkdApplier(tmpFile string, data any) net.Applier {
validator := systemdValidator{tmpFile}
return net.NewNetworkApplier(data, validator, nil)
}
// newSystemdLinkApplier creates a new Applier to configure systemd.link.
func newSystemdLinkApplier(kind BareMetalType, machineUUID string, nicIndex int, nic *models.V1MachineNic,
tmpFile string, evpnIfaces []EVPNIface) (net.Applier, error) {
var mtu int
switch kind {
case Firewall:
mtu = mtuFirewall
case Machine:
mtu = mtuMachine
default:
return nil, fmt.Errorf("unknown configuratorType of configurator: %d", kind)
}
data := SystemdLinkData{
SystemdCommonData: SystemdCommonData{
Comment: versionHeader(machineUUID),
Index: nicIndex,
},
MTU: mtu,
MAC: *nic.Mac,
EVPNIfaces: evpnIfaces,
}
validator := systemdValidator{tmpFile}
return net.NewNetworkApplier(data, validator, nil), nil
}
// Validate validates systemd.network and systemd.link files.
func (v systemdValidator) Validate() error {
return nil
}