Skip to content
Snippets Groups Projects
Commit 395ed59e authored by Malte Bauch's avatar Malte Bauch
Browse files

Adding a callback function for `Set`

parent ec76b14a
Branches
No related tags found
4 merge requests!17Build basic ci,!10Add simple modem support on linux through modemmanager,!8General refactoring,!5Draft: Add basic set support for ip/routing via gnmi
# tooling # tooling
build-tools/ build-tools/
artifacts/
# non vimmers # non vimmers
.devcontainer/
.vscode/ .vscode/
.idea/ .idea/
......
...@@ -27,7 +27,7 @@ var GnmiTargetYgot ygot.ValidatedGoStruct ...@@ -27,7 +27,7 @@ var GnmiTargetYgot ygot.ValidatedGoStruct
func scheduler(server *gnmiserver.Server, osclient os_clients.Osclient) { func scheduler(server *gnmiserver.Server, osclient os_clients.Osclient) {
for { for {
<-time.After(5 * time.Second) <-time.After(30 * time.Second)
log.Info("Update config...") log.Info("Update config...")
go server.InternalUpdate(currentosclient.UpdateConfig) go server.InternalUpdate(currentosclient.UpdateConfig)
} }
...@@ -66,7 +66,7 @@ func StartGNMITarget(bindAddress string, configFile string, osclient string) err ...@@ -66,7 +66,7 @@ func StartGNMITarget(bindAddress string, configFile string, osclient string) err
} }
} }
gnmiServer, err := gnmiserver.NewServer(model, GnmiTargetYgot, nil) gnmiServer, err := gnmiserver.NewServer(model, GnmiTargetYgot, currentosclient.GetCallbackFunc())
if err != nil { if err != nil {
log.Fatalf("error in creating GNMI target: %v", err) log.Fatalf("error in creating GNMI target: %v", err)
} }
......
package ubuntu package ubuntu
import ( import (
"fmt"
"net" "net"
"os" "os"
"os/exec" "os/exec"
"strings" "strings"
"syscall"
"time" "time"
"code.fbi.h-da.de/danet/gnmi-target/modeldata/gnmitargetygot" "code.fbi.h-da.de/danet/gnmi-target/modeldata/gnmitargetygot"
gnmiv "github.com/openconfig/gnmi/value"
"github.com/openconfig/ygot/ygot" "github.com/openconfig/ygot/ygot"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"github.com/vishvananda/netlink" "github.com/vishvananda/netlink"
...@@ -32,19 +33,19 @@ func (ou OsclientUbuntu) UpdateConfig(config *ygot.ValidatedGoStruct) error { ...@@ -32,19 +33,19 @@ func (ou OsclientUbuntu) UpdateConfig(config *ygot.ValidatedGoStruct) error {
func (ou *OsclientUbuntu) GetConfig() *gnmitargetygot.Gnmitarget { func (ou *OsclientUbuntu) GetConfig() *gnmitargetygot.Gnmitarget {
ou.gt = &gnmitargetygot.Gnmitarget{} ou.gt = &gnmitargetygot.Gnmitarget{}
// Create Interfaces // // Create Interfaces
h, err := netlink.NewHandle() // h, err := netlink.NewHandle()
if err != nil { // if err != nil {
log.WithFields(log.Fields{}).Error(err) // log.WithFields(log.Fields{}).Error(err)
} // }
// defer h.Delete() // // defer h.Delete()
localIfaces, err := h.LinkList() // localIfaces, err := h.LinkList()
if err != nil { // if err != nil {
log.WithFields(log.Fields{}).Error(err) // log.WithFields(log.Fields{}).Error(err)
} // }
for _, localIface := range localIfaces { // for _, localIface := range localIfaces {
ou.createInterfaces(localIface, ou.gt) // ou.createInterfaces(localIface, ou.gt)
} // }
ou.getSystem(ou.gt) ou.getSystem(ou.gt)
...@@ -52,11 +53,35 @@ func (ou *OsclientUbuntu) GetConfig() *gnmitargetygot.Gnmitarget { ...@@ -52,11 +53,35 @@ func (ou *OsclientUbuntu) GetConfig() *gnmitargetygot.Gnmitarget {
} }
func (ou *OsclientUbuntu) GetCallbackFunc() func(ygot.ValidatedGoStruct) error { func (ou *OsclientUbuntu) GetCallbackFunc() func(ygot.ValidatedGoStruct) error {
return callbackFunc return ou.callbackFunc
} }
func callbackFunc(config ygot.ValidatedGoStruct) error { func (ou *OsclientUbuntu) callbackFunc(config ygot.ValidatedGoStruct) error {
fmt.Printf("config: %v\n", config) diffs, err := ygot.Diff(ou.GetConfig(), config)
if err != nil {
return err
}
for _, diff := range diffs.GetUpdate() {
path, err := ygot.PathToString(diff.GetPath())
if err != nil {
return err
}
log.Info(path)
switch path {
case "/system/config/hostname":
value, err := gnmiv.ToScalar(diff.GetVal())
if err != nil {
return err
}
err = syscall.Sethostname([]byte(value.(string)))
if err != nil {
return err
}
default:
//INFO: currently this case is ignored
}
}
return nil return nil
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment