Skip to content

Commit cdea878

Browse files
committed
add dns nameservers to config
1 parent f271477 commit cdea878

File tree

9 files changed

+39
-2
lines changed

9 files changed

+39
-2
lines changed

configdb/configdb.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ type ConfigDB struct {
1616
ACLTables map[string]ACLTable `json:"ACL_TABLE,omitempty"`
1717
Breakouts map[string]BreakoutConfig `json:"BREAKOUT_CFG,omitempty"`
1818
DeviceMetadata `json:"DEVICE_METADATA"`
19-
Features map[string]Feature `json:"FEATURE,omitempty"`
20-
Interfaces map[string]Interface `json:"INTERFACE,omitempty"`
19+
DNSNameservers map[string]DNSNameserver `json:"DNS_NAMESERVER,omitempty"`
20+
Features map[string]Feature `json:"FEATURE,omitempty"`
21+
Interfaces map[string]Interface `json:"INTERFACE,omitempty"`
2122
LLDP `json:"LLDP"`
2223
LoopbackInterface map[string]struct{} `json:"LOOPBACK_INTERFACE,omitempty"`
2324
MCLAGDomains map[string]MCLAGDomain `json:"MCLAG_DOMAIN,omitempty"`
@@ -59,6 +60,7 @@ func GenerateConfigDB(input *values.Values, platform *p.Platform, currentDeviceM
5960
ACLTables: tables,
6061
Breakouts: breakouts,
6162
DeviceMetadata: *deviceMetadata,
63+
DNSNameservers: getDNSNameservers(input.Nameservers),
6264
Features: map[string]Feature{
6365
"dhcp_relay": {
6466
AutoRestart: FeatureModeEnabled,
@@ -207,6 +209,14 @@ func getDeviceMetadata(input *values.Values, currentMetadata DeviceMetadata) (*D
207209
}, nil
208210
}
209211

212+
func getDNSNameservers(nameservers []string) map[string]DNSNameserver {
213+
dnsNameservers := make(map[string]DNSNameserver)
214+
for _, n := range nameservers {
215+
dnsNameservers[n] = DNSNameserver{}
216+
}
217+
return dnsNameservers
218+
}
219+
210220
func getInterfaces(ports []values.Port, bgpPorts []string) map[string]Interface {
211221
interfaces := make(map[string]Interface)
212222

configdb/fields.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ type DeviceMetadata struct {
3636
Localhost Metadata `json:"localhost"`
3737
}
3838

39+
type DNSNameserver struct{}
40+
3941
type DockerRoutingConfigMode string
4042

4143
const (

tests/1/expected.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,10 @@
148148
"type": "LeafRouter"
149149
}
150150
},
151+
"DNS_NAMESERVER": {
152+
"1.1.1.1": {},
153+
"8.8.8.8": {}
154+
},
151155
"FEATURE": {
152156
"dhcp_relay": {
153157
"auto_restart": "enabled",

tests/1/sonic-config.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ mgmtif_gateway: 10.7.10.1
3333
mgmtif_ip: 10.7.10.2
3434
mgmt_vrf: false
3535

36+
nameservers:
37+
- 1.1.1.1
38+
- 8.8.8.8
39+
3640
ntpservers:
3741
- 0.europe.pool.ntp.org
3842
- 1.europe.pool.ntp.org

tests/2/expected.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,10 @@
148148
"type": "LeafRouter"
149149
}
150150
},
151+
"DNS_NAMESERVER": {
152+
"1.1.1.1": {},
153+
"8.8.8.8": {}
154+
},
151155
"FEATURE": {
152156
"dhcp_relay": {
153157
"auto_restart": "enabled",

tests/2/sonic-config.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ mgmtif_gateway: 10.7.10.1
1616
mgmtif_ip: 10.7.10.2
1717
mgmt_vrf: false
1818

19+
nameservers:
20+
- 1.1.1.1
21+
- 8.8.8.8
22+
1923
ntpservers:
2024
- 0.europe.pool.ntp.org
2125
- 1.europe.pool.ntp.org

tests/3/expected.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,10 @@
214214
"type": "LeafRouter"
215215
}
216216
},
217+
"DNS_NAMESERVER": {
218+
"1.1.1.1": {},
219+
"8.8.8.8": {}
220+
},
217221
"FEATURE": {
218222
"dhcp_relay": {
219223
"auto_restart": "enabled",

tests/3/sonic-config.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ mgmtif_gateway: 10.7.10.1
3434
mgmtif_ip: 10.7.10.2
3535
mgmt_vrf: false
3636

37+
nameservers:
38+
- 1.1.1.1
39+
- 8.8.8.8
40+
3741
ntpservers:
3842
- 0.europe.pool.ntp.org
3943
- 1.europe.pool.ntp.org

values/values.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ type Values struct {
6464
MgmtIfGateway string `yaml:"mgmtif_gateway,omitempty"`
6565
MgmtIfIP string `yaml:"mgmtif_ip,omitempty"`
6666
MgmtVRF bool `yaml:"mgmt_vrf,omitempty"`
67+
Nameservers []string `yaml:"nameservers,omitempty"`
6768
NTPServers []string `yaml:"ntpservers,omitempty"`
6869
PortChannels []PortChannel `yaml:"portchannels,omitempty"`
6970
PortChannelsDefaultMTU int `yaml:"portchannels_default_mtu,omitempty"`

0 commit comments

Comments
 (0)