Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions gnmi_set/gnmi_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ var (
func buildPbUpdateList(pathValuePairs []string) []*pb.Update {
var pbUpdateList []*pb.Update
for _, item := range pathValuePairs {
pathValuePair := strings.SplitN(item, ":", 2)
// TODO (leguo): check if any path attribute contains ':'
if len(pathValuePair) != 2 || len(pathValuePair[1]) == 0 {
splitIndex := strings.LastIndexAny(item, ":")
if splitIndex < 1 {
log.Exitf("invalid path-value pair: %v", item)
}
pathValuePair := []string{item[:splitIndex], item[(splitIndex + 1):]}
pbPath, err := xpath.ToGNMIPath(pathValuePair[0])
if err != nil {
log.Exitf("error in parsing xpath %q to gnmi path", pathValuePair[0])
Expand Down
9 changes: 8 additions & 1 deletion utils/xpath/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package xpath

import (
"fmt"
"strings"

pb "github.com/openconfig/gnmi/proto/gnmi"
)
Expand All @@ -40,6 +41,12 @@ import (
// elem: <name: "state" >
// elem: <name: "counters" >
func ToGNMIPath(xpath string) (*pb.Path, error) {
var origin string
i := strings.Index(xpath, ":")
if i != -1 {
origin = xpath[:i]
xpath = xpath[i+1:]
}
xpathElements, err := ParseStringPath(xpath)
if err != nil {
return nil, err
Expand All @@ -62,5 +69,5 @@ func ToGNMIPath(xpath string) (*pb.Path, error) {
return nil, fmt.Errorf("wrong data type: %T", v)
}
}
return &pb.Path{Elem: pbPathElements}, nil
return &pb.Path{Origin: origin, Elem: pbPathElements}, nil
}