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
2 changes: 1 addition & 1 deletion gnmi_cli_py/py_gnmicli.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ def _get_val(json_value):
json_value.strip('@'), 'rb').read())
except (IOError, ValueError) as e:
raise JsonReadError('Error while loading JSON: %s' % str(e))
val.json_ietf_val = json.dumps(set_json)
val.json_ietf_val = json.dumps(set_json).encode('utf-8')
return val
coerced_val = _format_type(json_value)
type_to_value = {bool: 'bool_val', int: 'int_val', float: 'float_val',
Expand Down
25 changes: 18 additions & 7 deletions gnmi_set/gnmi_set.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
/* Copyright 2017 Google Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand Down Expand Up @@ -54,16 +51,17 @@ var (
targetAddr = flag.String("target_addr", "localhost:10161", "The target address in the format of host:port")
targetName = flag.String("target_name", "hostname.com", "The target name use to verify the hostname returned by TLS handshake")
timeOut = flag.Duration("time_out", 10*time.Second, "Timeout for the Get request, 10 seconds by default")
leafList = flag.String("leaf_list_node", "false", "Set this flag to true to update leaf list node value.")
)

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 All @@ -89,7 +87,20 @@ func buildPbUpdateList(pathValuePairs []string) []*pb.Update {
},
}
} else {
if intVal, err := strconv.ParseInt(pathValuePair[1], 10, 64); err == nil {
if *leafList == "true" {
v := strings.Split(pathValuePair[1],",")
sa := &pb.ScalarArray{Element: make([]*pb.TypedValue, len(v))}
for x, s := range v {
if t, err := strconv.ParseInt(s, 10, 64); err == nil {
sa.Element[x] = &pb.TypedValue{Value: &pb.TypedValue_IntVal{t}}
} else {
sa.Element[x] = &pb.TypedValue{Value: &pb.TypedValue_StringVal{s}}
}
}
pbVal = &pb.TypedValue{
Value: &pb.TypedValue_LeaflistVal{ sa },
}
} else if intVal, err := strconv.ParseInt(pathValuePair[1], 10, 64); err == nil {
pbVal = &pb.TypedValue{
Value: &pb.TypedValue_IntVal{
IntVal: intVal,
Expand Down