xpath

package
v0.0.0-...-eccbe3f Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2020 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package xpath parses xpath string into gnmi Path struct.

Package xpath provides utility functions to parse gnmi xpath.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

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 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" >

Types

This section is empty.

Jump to

Keyboard shortcuts

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