From a14f90aa7f5c6841b864a586e4ff346fc475acf6 Mon Sep 17 00:00:00 2001 From: Malte Bauch <malte.bauch@extern.h-da.de> Date: Tue, 7 Jun 2022 15:03:40 +0200 Subject: [PATCH] WIP --- os_clients/ubuntu/pathHandling.go | 30 ++++++++++++++++++++++++++++++ os_clients/ubuntu/ubuntu.go | 9 +++++---- 2 files changed, 35 insertions(+), 4 deletions(-) create mode 100644 os_clients/ubuntu/pathHandling.go diff --git a/os_clients/ubuntu/pathHandling.go b/os_clients/ubuntu/pathHandling.go new file mode 100644 index 0000000..1f93774 --- /dev/null +++ b/os_clients/ubuntu/pathHandling.go @@ -0,0 +1,30 @@ +package ubuntu + +import ( + "fmt" + + "github.com/openconfig/gnmi/proto/gnmi" +) + +type PathFunc func(path *gnmi.Path, val *gnmi.TypedValue) error + +type PathMap map[string]PathFunc + +func (pm PathMap) Register(s string, fn PathFunc) error { + if _, found := pm[s]; found { + return fmt.Errorf("a function is already registered for path: '%s'", s) + } + pm[s] = fn + return nil +} + +func (pm PathMap) Execute(s string) error { + return execute(pm, s) +} + +func execute(pm PathMap, p string) error { + if _, found := pm[p]; found { + //return fn() + } + return fmt.Errorf("The given path: '%s' is not supported", p) +} diff --git a/os_clients/ubuntu/ubuntu.go b/os_clients/ubuntu/ubuntu.go index c287dbc..2cef553 100644 --- a/os_clients/ubuntu/ubuntu.go +++ b/os_clients/ubuntu/ubuntu.go @@ -1,6 +1,7 @@ package ubuntu import ( + "fmt" "net" "os" "os/exec" @@ -62,12 +63,12 @@ func (ou *OsclientUbuntu) callbackFunc(config ygot.ValidatedGoStruct) error { return err } for _, diff := range diffs.GetUpdate() { - path, err := ygot.PathToString(diff.GetPath()) + schemaPath, err := ygot.PathToSchemaPath(diff.GetPath()) if err != nil { return err } - log.Info(path) - switch path { + log.Info(schemaPath) + switch schemaPath { case "/system/config/hostname": value, err := gnmiv.ToScalar(diff.GetVal()) if err != nil { @@ -78,7 +79,7 @@ func (ou *OsclientUbuntu) callbackFunc(config ygot.ValidatedGoStruct) error { return err } default: - //INFO: currently this case is ignored + return fmt.Errorf("this path is not supported") } } -- GitLab