Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions configdb/configdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,8 @@ func GenerateConfigDB(input *values.Values, platform *p.Platform, currentDeviceM
MgmtVRFEnabled: strconv.FormatBool(input.MgmtVRF),
},
},
NTP: NTP{
NTPGlobal: NTPGlobal{
SrcIntf: "eth0",
},
},
NTPServers: getNTPServers(input.NTPServers),
NTP: getNTP(input.NTP),
NTPServers: getNTPServers(input.NTP.Servers),
Ports: ports,
PortChannels: getPortChannels(input.PortChannels),
PortChannelMembers: getPortChannelMembers(input.PortChannels.List),
Expand Down Expand Up @@ -329,6 +325,20 @@ func getMgmtInterfaces(mgmtif values.MgmtInterface) map[string]MgmtInterface {
return mgmtInterfaces
}

func getNTP(ntp values.NTP) NTP {
srcif := "eth0"
if ntp.SrcInterface != "" {
srcif = ntp.SrcInterface
}

return NTP{
NTPGlobal: NTPGlobal{
SrcIntf: srcif,
VRF: ntp.VRF,
},
}
}

func getNTPServers(servers []string) map[string]struct{} {
ntpServers := make(map[string]struct{})

Expand Down
1 change: 1 addition & 0 deletions configdb/fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ type NTP struct {

type NTPGlobal struct {
SrcIntf string `json:"src_intf"`
VRF string `json:"vrf,omitempty"`
}

type PacketAction string
Expand Down
3 changes: 2 additions & 1 deletion tests/1/expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,8 @@
},
"NTP": {
"global": {
"src_intf": "eth0"
"src_intf": "Loopback0",
"vrf": "default"
}
},
"NTP_SERVER": {
Expand Down
13 changes: 8 additions & 5 deletions tests/1/sonic-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,14 @@ nameservers:
- 1.1.1.1
- 8.8.8.8

ntpservers:
- 0.europe.pool.ntp.org
- 1.europe.pool.ntp.org
- 2.europe.pool.ntp.org
- 3.europe.pool.ntp.org
ntp:
src_interface: Loopback0
vrf: default
servers:
- 0.europe.pool.ntp.org
- 1.europe.pool.ntp.org
- 2.europe.pool.ntp.org
- 3.europe.pool.ntp.org

portchannels:
default_mtu: 9000
Expand Down
11 changes: 6 additions & 5 deletions tests/2/sonic-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@ nameservers:
- 1.1.1.1
- 8.8.8.8

ntpservers:
- 0.europe.pool.ntp.org
- 1.europe.pool.ntp.org
- 2.europe.pool.ntp.org
- 3.europe.pool.ntp.org
ntp:
servers:
- 0.europe.pool.ntp.org
- 1.europe.pool.ntp.org
- 2.europe.pool.ntp.org
- 3.europe.pool.ntp.org

ports:
default_fec: none
Expand Down
11 changes: 6 additions & 5 deletions tests/3/sonic-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,12 @@ nameservers:
- 1.1.1.1
- 8.8.8.8

ntpservers:
- 0.europe.pool.ntp.org
- 1.europe.pool.ntp.org
- 2.europe.pool.ntp.org
- 3.europe.pool.ntp.org
ntp:
servers:
- 0.europe.pool.ntp.org
- 1.europe.pool.ntp.org
- 2.europe.pool.ntp.org
- 3.europe.pool.ntp.org

portchannels:
default_mtu: 9000
Expand Down
8 changes: 7 additions & 1 deletion values/values.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ type MgmtInterface struct {
IP string `yaml:"ip"`
}

type NTP struct {
SrcInterface string `yaml:"src_interface"`
Servers []string `yaml:"servers"`
VRF string `yaml:"vrf"`
}

type Port struct {
IPs []string `yaml:"ips"`
FECMode FECMode `yaml:"fec"`
Expand Down Expand Up @@ -88,7 +94,7 @@ type Values struct {
MgmtInterface MgmtInterface `yaml:"mgmt_interface"`
MgmtVRF bool `yaml:"mgmt_vrf"`
Nameservers []string `yaml:"nameservers"`
NTPServers []string `yaml:"ntpservers"`
NTP NTP `yaml:"ntp"`
PortChannels PortChannels `yaml:"portchannels"`
Ports Ports `yaml:"ports"`
SAG SAG `yaml:"sag"`
Expand Down