Skip to content

Commit d8e783c

Browse files
authored
Allow specifying custom features (#7)
1 parent ade826c commit d8e783c

File tree

4 files changed

+92
-66
lines changed

4 files changed

+92
-66
lines changed

configdb/configdb.go

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,7 @@ func GenerateConfigDB(input *values.Values, platform *p.Platform, currentDeviceM
5454
}
5555

5656
rules, tables := getACLRulesAndTables(input.SSHSourceranges)
57-
58-
features := make(map[string]Feature)
59-
if input.DHCPRelayEnabled {
60-
features["dhcp_relay"] = Feature{
61-
AutoRestart: FeatureModeEnabled,
62-
State: FeatureModeEnabled,
63-
}
64-
}
57+
features := getFeatures(input.Features)
6558

6659
configdb := ConfigDB{
6760
ACLRules: rules,
@@ -220,6 +213,27 @@ func getDNSNameservers(nameservers []string) map[string]DNSNameserver {
220213
return dnsNameservers
221214
}
222215

216+
func getFeatures(features map[string]values.Feature) map[string]Feature {
217+
configFeatures := make(map[string]Feature)
218+
219+
for name, feature := range features {
220+
autoRestart := FeatureModeDisabled
221+
state := FeatureModeDisabled
222+
if feature.AutoRestart {
223+
autoRestart = FeatureModeEnabled
224+
}
225+
if feature.Enabled {
226+
state = FeatureModeEnabled
227+
}
228+
configFeatures[name] = Feature{
229+
AutoRestart: autoRestart,
230+
State: state,
231+
}
232+
}
233+
234+
return configFeatures
235+
}
236+
223237
func getInterfaces(ports []values.Port, bgpPorts []string) map[string]Interface {
224238
interfaces := make(map[string]Interface)
225239

tests/1/sonic-config.yaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,13 @@ bgp_ports:
55
breakouts:
66
Ethernet0: 4x25G
77

8-
dhcp_relay_enabled: true
98
docker_routing_config_mode: split
9+
10+
features:
11+
dhcp_relay:
12+
auto_restart: true
13+
enabled: true
14+
1015
frr_mgmt_framework_config: false
1116

1217
interconnects:

tests/2/sonic-config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ breakouts:
66
Ethernet0: 4x25G
77

88
docker_routing_config_mode: split
9+
features: {}
910
frr_mgmt_framework_config: false
1011

1112
hostname: leaf01

values/values.go

Lines changed: 63 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,17 @@ import "gopkg.in/yaml.v3"
55
type DockerRoutingConfigMode string
66

77
const (
8-
DockerRoutingConfigModeSeparated DockerRoutingConfigMode = "separated"
9-
DockerRoutingConfigModeSplit DockerRoutingConfigMode = "split"
10-
DockerRoutingConfigModeUnified DockerRoutingConfigMode = "unified"
8+
DockerRoutingConfigModeSeparated DockerRoutingConfigMode = "separated"
9+
DockerRoutingConfigModeSplit DockerRoutingConfigMode = "split"
10+
DockerRoutingConfigModeSplitUnified DockerRoutingConfigMode = "split-unified"
11+
DockerRoutingConfigModeUnified DockerRoutingConfigMode = "unified"
1112
)
1213

14+
type Feature struct {
15+
AutoRestart bool `yaml:"auto_restart"`
16+
Enabled bool `yaml:"enabled"`
17+
}
18+
1319
type FECMode string
1420

1521
const (
@@ -18,81 +24,81 @@ const (
1824
)
1925

2026
type Interconnect struct {
21-
VNI string `yaml:"vni,omitempty"`
22-
VRF string `yaml:"vrf,omitempty"`
27+
VNI string `yaml:"vni"`
28+
VRF string `yaml:"vrf"`
2329
}
2430

2531
type MCLAG struct {
26-
KeepaliveVLAN string `yaml:"keepalive_vlan,omitempty"`
27-
MemberPortChannels []string `yaml:"member_port_channels,omitempty"`
28-
PeerIP string `yaml:"peer_ip,omitempty"`
29-
PeerLink string `yaml:"peer_link,omitempty"`
30-
SourceIP string `yaml:"source_ip,omitempty"`
31-
SystemMAC string `yaml:"system_mac,omitempty"`
32+
KeepaliveVLAN string `yaml:"keepalive_vlan"`
33+
MemberPortChannels []string `yaml:"member_port_channels"`
34+
PeerIP string `yaml:"peer_ip"`
35+
PeerLink string `yaml:"peer_link"`
36+
SourceIP string `yaml:"source_ip"`
37+
SystemMAC string `yaml:"system_mac"`
3238
}
3339

3440
type Port struct {
35-
IPs []string `yaml:"ips,omitempty"`
36-
FECMode `yaml:"fec,omitempty"`
37-
MTU int `yaml:"mtu,omitempty"`
38-
Name string `yaml:"name,omitempty"`
39-
Speed int `yaml:"speed,omitempty"`
40-
VRF string `yaml:"vrf,omitempty"`
41+
IPs []string `yaml:"ips"`
42+
FECMode `yaml:"fec"`
43+
MTU int `yaml:"mtu"`
44+
Name string `yaml:"name"`
45+
Speed int `yaml:"speed"`
46+
VRF string `yaml:"vrf"`
4147
}
4248

4349
type PortChannel struct {
44-
Number string `yaml:"number,omitempty"`
45-
MTU int `yaml:"mtu,omitempty"`
46-
Fallback bool `yaml:"fallback,omitempty"`
47-
Members []string `yaml:"members,omitempty"`
50+
Number string `yaml:"number"`
51+
MTU int `yaml:"mtu"`
52+
Fallback bool `yaml:"fallback"`
53+
Members []string `yaml:"members"`
4854
}
4955

5056
type SAG struct {
51-
MAC string `yaml:"mac,omitempty"`
57+
MAC string `yaml:"mac"`
5258
}
5359

5460
type Values struct {
55-
BGPPorts []string `yaml:"bgp_ports,omitempty"`
56-
Breakouts map[string]string `yaml:"breakouts,omitempty"`
57-
DHCPRelayEnabled bool `yaml:"dhcp_relay_enabled"`
58-
DockerRoutingConfigMode `yaml:"docker_routing_config_mode,omitempty"`
59-
FRRMgmtFrameworkConfig bool `yaml:"frr_mgmt_framework_config,omitempty"`
60-
Hostname string `yaml:"hostname,omitempty"`
61-
Interconnects map[string]Interconnect `yaml:"interconnects,omitempty"`
62-
LLDPHelloTime int `yaml:"lldp_hello_time,omitempty"`
63-
LoopbackAddress string `yaml:"loopback_address,omitempty"`
64-
MCLAG *MCLAG `yaml:"mclag,omitempty"`
65-
MgmtIfGateway string `yaml:"mgmtif_gateway,omitempty"`
66-
MgmtIfIP string `yaml:"mgmtif_ip,omitempty"`
67-
MgmtVRF bool `yaml:"mgmt_vrf,omitempty"`
68-
Nameservers []string `yaml:"nameservers,omitempty"`
69-
NTPServers []string `yaml:"ntpservers,omitempty"`
70-
PortChannels []PortChannel `yaml:"portchannels,omitempty"`
71-
PortChannelsDefaultMTU int `yaml:"portchannels_default_mtu,omitempty"`
72-
Ports []Port `yaml:"ports,omitempty"`
73-
PortsDefaultFEC FECMode `yaml:"ports_default_fec,omitempty"`
74-
PortsDefaultMTU int `yaml:"ports_default_mtu,omitempty"`
75-
SAG `yaml:"sag,omitempty"`
76-
SSHSourceranges []string `yaml:"ssh_sourceranges,omitempty"`
77-
VLANMembers bool `yaml:"vlan_members,omitempty"`
78-
VLANs []VLAN `yaml:"vlans,omitempty"`
79-
VTEPs []VTEP `yaml:"vteps,omitempty"`
61+
BGPPorts []string `yaml:"bgp_ports"`
62+
Breakouts map[string]string `yaml:"breakouts"`
63+
DockerRoutingConfigMode `yaml:"docker_routing_config_mode"`
64+
Features map[string]Feature `yaml:"features"`
65+
FRRMgmtFrameworkConfig bool `yaml:"frr_mgmt_framework_config"`
66+
Hostname string `yaml:"hostname"`
67+
Interconnects map[string]Interconnect `yaml:"interconnects"`
68+
LLDPHelloTime int `yaml:"lldp_hello_time"`
69+
LoopbackAddress string `yaml:"loopback_address"`
70+
MCLAG *MCLAG `yaml:"mclag"`
71+
MgmtIfGateway string `yaml:"mgmtif_gateway"`
72+
MgmtIfIP string `yaml:"mgmtif_ip"`
73+
MgmtVRF bool `yaml:"mgmt_vrf"`
74+
Nameservers []string `yaml:"nameservers"`
75+
NTPServers []string `yaml:"ntpservers"`
76+
PortChannels []PortChannel `yaml:"portchannels"`
77+
PortChannelsDefaultMTU int `yaml:"portchannels_default_mtu"`
78+
Ports []Port `yaml:"ports"`
79+
PortsDefaultFEC FECMode `yaml:"ports_default_fec"`
80+
PortsDefaultMTU int `yaml:"ports_default_mtu"`
81+
SAG `yaml:"sag"`
82+
SSHSourceranges []string `yaml:"ssh_sourceranges"`
83+
VLANMembers bool `yaml:"vlan_members"`
84+
VLANs []VLAN `yaml:"vlans"`
85+
VTEPs []VTEP `yaml:"vteps"`
8086
}
8187

8288
type VLAN struct {
83-
DHCPServers []string `yaml:"dhcp_servers,omitempty"`
84-
ID string `yaml:"id,omitempty"`
85-
IP string `yaml:"ip,omitempty"`
86-
SAG bool `yaml:"sag,omitempty"`
87-
TaggedPorts []string `yaml:"tagged_ports,omitempty"`
88-
UntaggedPorts []string `yaml:"untagged_ports,omitempty"`
89-
VRF string `yaml:"vrf,omitempty"`
89+
DHCPServers []string `yaml:"dhcp_servers"`
90+
ID string `yaml:"id"`
91+
IP string `yaml:"ip"`
92+
SAG bool `yaml:"sag"`
93+
TaggedPorts []string `yaml:"tagged_ports"`
94+
UntaggedPorts []string `yaml:"untagged_ports"`
95+
VRF string `yaml:"vrf"`
9096
}
9197

9298
type VTEP struct {
93-
Comment string `yaml:"comment,omitempty"`
94-
VNI string `yaml:"vni,omitempty"`
95-
VLAN string `yaml:"vlan,omitempty"`
99+
Comment string `yaml:"comment"`
100+
VNI string `yaml:"vni"`
101+
VLAN string `yaml:"vlan"`
96102
}
97103

98104
func UnmarshalValues(in []byte) (*Values, error) {

0 commit comments

Comments
 (0)