diff --git a/os_clients/ubuntu/pathHandling.go b/os_clients/ubuntu/pathHandling.go new file mode 100644 index 0000000000000000000000000000000000000000..1f93774911f9ea7edf9b52532bf22cbdbdf8eee3 --- /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 c287dbce3d35438585a2ceafbca02c4017f69a81..2cef5536ae2da597e9eebf3fdf648d1147fd0e3d 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") } }