Skip to content

Commit 503cac6

Browse files
committed
Allow configuring ntp source interface and vrf
1 parent 4536666 commit 503cac6

File tree

7 files changed

+46
-23
lines changed

7 files changed

+46
-23
lines changed

configdb/configdb.go

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,8 @@ func GenerateConfigDB(input *values.Values, platform *p.Platform, currentDeviceM
8989
MgmtVRFEnabled: strconv.FormatBool(input.MgmtVRF),
9090
},
9191
},
92-
NTP: NTP{
93-
NTPGlobal: NTPGlobal{
94-
SrcIntf: "eth0",
95-
},
96-
},
97-
NTPServers: getNTPServers(input.NTPServers),
92+
NTP: getNTP(input.NTP),
93+
NTPServers: getNTPServers(input.NTP.Servers),
9894
Ports: ports,
9995
PortChannels: getPortChannels(input.PortChannels),
10096
PortChannelMembers: getPortChannelMembers(input.PortChannels.List),
@@ -329,6 +325,20 @@ func getMgmtInterfaces(mgmtif values.MgmtInterface) map[string]MgmtInterface {
329325
return mgmtInterfaces
330326
}
331327

328+
func getNTP(ntp values.NTP) NTP {
329+
srcif := "eth0"
330+
if ntp.SrcInterface != "" {
331+
srcif = ntp.SrcInterface
332+
}
333+
334+
return NTP{
335+
NTPGlobal: NTPGlobal{
336+
SrcIntf: srcif,
337+
VRF: ntp.VRF,
338+
},
339+
}
340+
}
341+
332342
func getNTPServers(servers []string) map[string]struct{} {
333343
ntpServers := make(map[string]struct{})
334344

configdb/fields.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ type NTP struct {
142142

143143
type NTPGlobal struct {
144144
SrcIntf string `json:"src_intf"`
145+
VRF string `json:"vrf,omitempty"`
145146
}
146147

147148
type PacketAction string

tests/1/expected.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,8 @@
219219
},
220220
"NTP": {
221221
"global": {
222-
"src_intf": "eth0"
222+
"src_intf": "Loopback0",
223+
"vrf": "default"
223224
}
224225
},
225226
"NTP_SERVER": {

tests/1/sonic-config.yaml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,14 @@ nameservers:
4545
- 1.1.1.1
4646
- 8.8.8.8
4747

48-
ntpservers:
49-
- 0.europe.pool.ntp.org
50-
- 1.europe.pool.ntp.org
51-
- 2.europe.pool.ntp.org
52-
- 3.europe.pool.ntp.org
48+
ntp:
49+
src_interface: Loopback0
50+
vrf: default
51+
servers:
52+
- 0.europe.pool.ntp.org
53+
- 1.europe.pool.ntp.org
54+
- 2.europe.pool.ntp.org
55+
- 3.europe.pool.ntp.org
5356

5457
portchannels:
5558
default_mtu: 9000

tests/2/sonic-config.yaml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,12 @@ nameservers:
2525
- 1.1.1.1
2626
- 8.8.8.8
2727

28-
ntpservers:
29-
- 0.europe.pool.ntp.org
30-
- 1.europe.pool.ntp.org
31-
- 2.europe.pool.ntp.org
32-
- 3.europe.pool.ntp.org
28+
ntp:
29+
servers:
30+
- 0.europe.pool.ntp.org
31+
- 1.europe.pool.ntp.org
32+
- 2.europe.pool.ntp.org
33+
- 3.europe.pool.ntp.org
3334

3435
ports:
3536
default_fec: none

tests/3/sonic-config.yaml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,12 @@ nameservers:
4040
- 1.1.1.1
4141
- 8.8.8.8
4242

43-
ntpservers:
44-
- 0.europe.pool.ntp.org
45-
- 1.europe.pool.ntp.org
46-
- 2.europe.pool.ntp.org
47-
- 3.europe.pool.ntp.org
43+
ntp:
44+
servers:
45+
- 0.europe.pool.ntp.org
46+
- 1.europe.pool.ntp.org
47+
- 2.europe.pool.ntp.org
48+
- 3.europe.pool.ntp.org
4849

4950
portchannels:
5051
default_mtu: 9000

values/values.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ type MgmtInterface struct {
4343
IP string `yaml:"ip"`
4444
}
4545

46+
type NTP struct {
47+
SrcInterface string `yaml:"src_interface"`
48+
Servers []string `yaml:"servers"`
49+
VRF string `yaml:"vrf"`
50+
}
51+
4652
type Port struct {
4753
IPs []string `yaml:"ips"`
4854
FECMode FECMode `yaml:"fec"`
@@ -88,7 +94,7 @@ type Values struct {
8894
MgmtInterface MgmtInterface `yaml:"mgmt_interface"`
8995
MgmtVRF bool `yaml:"mgmt_vrf"`
9096
Nameservers []string `yaml:"nameservers"`
91-
NTPServers []string `yaml:"ntpservers"`
97+
NTP NTP `yaml:"ntp"`
9298
PortChannels PortChannels `yaml:"portchannels"`
9399
Ports Ports `yaml:"ports"`
94100
SAG SAG `yaml:"sag"`

0 commit comments

Comments
 (0)