utils

package
v0.7.23 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 18, 2021 License: Apache-2.0 Imports: 7 Imported by: 7

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GnmiFullPath

func GnmiFullPath(prefix, path *pb.Path) *pb.Path

GnmiFullPath builds the full path from the prefix and path.

func ParseStringPath

func ParseStringPath(stringPath string) ([]interface{}, error)

ParseStringPath parses a string path and produces a []interface{} of parsed path elements. Path elements in a string path are separated by '/'. Each path element can either be a schema node name or a List path element. Schema node names must be valid YANG identifiers. A List path element is encoded using the following pattern: list-name[key1=value1]...[keyN=valueN]. Each List path element generates two parsed path elements: List name and a map[string]string containing List key-value pairs with value(s) in string representation. A '/' within a List key value pair string, i.e., between a pair of '[' and ']', does not serve as a path separator, and is allowed to be part of a List key leaf value. For example, given a string path:

"/a/list-name[k=v/v]/c",

this API returns:

[]interface{}{"a", "list-name", map[string]string{"k": "v/v"}, "c"}.

String path parsing consists of two passes. In the first pass, the input string is split into []string using valid separator '/'. An incomplete List key value string, i.e, a '[' which starts a List key value string without a closing ']', in input string generates an error. In the above example, this pass produces:

[]string{"a", "list-name[k=v/v]", "c"}.

In the second pass, each element in split []string is parsed checking syntax and pattern correctness. Errors are generated for invalid YANG identifiers, malformed List key-value string, etc.. In the above example, the second pass produces:

[]interface{}{"a", "list-name", map[string]string{"k", "v/v"}, "c"}.

func StrPathElem

func StrPathElem(pathElem []*pb.PathElem) string

StrPathElem builds a human-readable form of a list of path elements. e.g. /a/b/c[e=f]

func ToFloat added in v0.7.2

func ToFloat(value interface{}) (float32, error)

ToFloat converts an interface value to float

func ToGNMIPath

func ToGNMIPath(xpath string) (*pb.Path, error)

ToGNMIPath parses an xpath string into a gnmi Path struct defined in gnmi proto. Path convention can be found in https://github.com/openconfig/reference/blob/master/rpc/gnmi/gnmi-path-conventions.md

For example, xpath /interfaces/interface[name=Ethernet1/2/3]/state/counters will be parsed to:

elem: <name: "interfaces" >
elem: <
    name: "interface"
    key: <
        key: "name"
        value: "Ethernet1/2/3"
    >
>
elem: <name: "state" >
elem: <name: "counters" >

func ToString added in v0.7.2

func ToString(value interface{}) (string, error)

ToString converts value to string

func ToUint64 added in v0.7.2

func ToUint64(value interface{}) (uint64, error)

ToUint converts an interface value to uint64

func ToXPath

func ToXPath(path *pb.Path) string

ToXPath builds a human-readable form of a gnmi path. e.g. /a/b/c[e=f]

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL