Skip to content
Snippets Groups Projects
Commit 6959b092 authored by istmxrein's avatar istmxrein
Browse files

implement system.Datetime and system.Boottime

parent d9fc102d
No related branches found
No related tags found
1 merge request!2First working version that retrieves the real state from the device
Pipeline #91113 passed
......@@ -9,7 +9,7 @@ COPY . .
RUN GOOS=linux go build -o gnmi-target ./main.go
FROM alpine:latest
RUN apk add --no-cache git iproute2 iptables dumb-init coreutils
RUN apk add --no-cache git iproute2 iptables dumb-init coreutils bash
COPY --from=builder /build/gnmi-target /usr/bin/gnmi-target
EXPOSE 7030
ENTRYPOINT ["dumb-init", "--"]
......
......@@ -15,25 +15,11 @@ import (
)
type OsclientUbuntu struct {
gt *gnmitargetygot.Gnmitarget
root string
}
func getHostPrefix() (string, error) {
path := "/host"
_, err := os.Stat(path)
if err == nil {
return "/host", nil
}
if os.IsNotExist(err) {
return "", nil
}
return "", err
gt *gnmitargetygot.Gnmitarget
}
func NewOsclientUbuntu() *OsclientUbuntu {
client := new(OsclientUbuntu)
client.root, _ = getHostPrefix()
return client
}
......@@ -95,10 +81,15 @@ func (ou *OsclientUbuntu) getSystemInformationen(gt *gnmitargetygot.Gnmitarget)
// Create Config
system.Hostname = ygot.String(name)
system.CurrentDatetime = ygot.String(time.Now().Format(time.RFC3339))
o, _ := os.Stat("/proc/")
system.BootTime = ygot.Uint64(uint64(o.ModTime().UTC().UnixNano()))
// Create Clock
system.Clock = system.GetOrCreateClock()
zonename, _ := exec.Command("realpath", "--relative-to", ou.root+"/usr/share/zoneinfo", "/etc/localtime").Output()
output, _ := exec.Command("realpath", "--relative-to=/usr/share/zoneinfo", "/etc/localtime").Output()
ss := strings.Split(string(output), " ")
zonename := ss[len(ss)-1]
system.Clock.TimezoneName = ygot.String(strings.TrimSuffix(string(zonename), "\n"))
//validate struct
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment