diff --git a/configdb/configdb.go b/configdb/configdb.go index b12f537..7db8e24 100644 --- a/configdb/configdb.go +++ b/configdb/configdb.go @@ -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), @@ -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{}) diff --git a/configdb/fields.go b/configdb/fields.go index e88360d..cd73eac 100644 --- a/configdb/fields.go +++ b/configdb/fields.go @@ -142,6 +142,7 @@ type NTP struct { type NTPGlobal struct { SrcIntf string `json:"src_intf"` + VRF string `json:"vrf,omitempty"` } type PacketAction string diff --git a/tests/1/expected.json b/tests/1/expected.json index 34f9604..6401da4 100644 --- a/tests/1/expected.json +++ b/tests/1/expected.json @@ -219,7 +219,8 @@ }, "NTP": { "global": { - "src_intf": "eth0" + "src_intf": "Loopback0", + "vrf": "default" } }, "NTP_SERVER": { diff --git a/tests/1/sonic-config.yaml b/tests/1/sonic-config.yaml index 9cc7b88..49dd406 100644 --- a/tests/1/sonic-config.yaml +++ b/tests/1/sonic-config.yaml @@ -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 diff --git a/tests/2/sonic-config.yaml b/tests/2/sonic-config.yaml index 1fce591..303652c 100644 --- a/tests/2/sonic-config.yaml +++ b/tests/2/sonic-config.yaml @@ -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 diff --git a/tests/3/sonic-config.yaml b/tests/3/sonic-config.yaml index b528388..2477ab4 100644 --- a/tests/3/sonic-config.yaml +++ b/tests/3/sonic-config.yaml @@ -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 diff --git a/values/values.go b/values/values.go index 46bf8b2..b6c910e 100644 --- a/values/values.go +++ b/values/values.go @@ -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"` @@ -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"`