Skip to content
Snippets Groups Projects

Resolve "A SetRequest to change a specific path of an OND only works for paths with string values"

Compare and
7 files
+ 169
79
Compare changes
  • Side-by-side
  • Inline
Files
7
+ 48
2
@@ -32,12 +32,31 @@ POSSIBILITY OF SUCH DAMAGE.
package cmd
import (
"fmt"
ppb "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/pnd"
"github.com/google/uuid"
gpb "github.com/openconfig/gnmi/proto/gnmi"
"github.com/openconfig/ygot/ygot"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"google.golang.org/protobuf/encoding/protojson"
)
type pathMessage struct {
time int64
path string
updates string
}
func (pm pathMessage) String() string {
// TODO: different prints based on typedValue type
return fmt.Sprintf("timestamp: %v\npath: %v\nupdates: %v\n}",
pm.time,
pm.path,
pm.updates,
)
}
// deviceGetCmd represents the get command
var deviceGetCmd = &cobra.Command{
Use: "get [uuid] [path]",
@@ -60,7 +79,34 @@ The device UUID and request path must be specified as a positional arguments.`,
log.Error(err)
}
log.Info(protojson.Format(message))
resp, ok := message.(*ppb.GetPathResponse)
if !ok {
log.Fatal(err)
}
for _, d := range resp.Device {
path, err := ygot.PathToString(d.Update[0].GetPath())
if err != nil {
log.Fatal(err)
}
pm := pathMessage{
time: resp.GetTimestamp(),
path: path,
updates: d.Update[0].GetVal().String(),
}
val := d.Update[0].GetVal()
switch valTyped := val.GetValue().(type) {
case *gpb.TypedValue_JsonIetfVal:
pm.updates = string(valTyped.JsonIetfVal)
case *gpb.TypedValue_JsonVal:
pm.updates = string(valTyped.JsonVal)
default:
pm.updates = val.String()
}
fmt.Println(pm.String())
}
},
}
Loading