parser

package
v0.1.42 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2021 License: Apache-2.0 Imports: 13 Imported by: 2

Documentation

Index

Constants

View Source
const (
	// values
	Slice    = "slice"
	NonSlice = "nonSlice"
	// errors
	ErrJSONMarshal       = "cannot marshal JSON object"
	ErrJSONCompare       = "cannot compare JSON objects"
	ErrJSONMarshalIndent = "cannot marshal JSON object with indent"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ConfigTreeAction added in v0.1.4

type ConfigTreeAction string

ConfigTreeAction defines the states the resource object is reporting

const (
	ConfigTreeActionGet    ConfigTreeAction = "get"
	ConfigTreeActionDelete ConfigTreeAction = "delete"
	ConfigTreeActionCreate ConfigTreeAction = "create"
	ConfigTreeActionUpdate ConfigTreeAction = "update"
	ConfigTreeActionFind   ConfigTreeAction = "find"
	ConfigResolveLeafRef   ConfigTreeAction = "resolve leafref"
)

func (*ConfigTreeAction) String added in v0.1.4

func (c *ConfigTreeAction) String() string

type LeafRef added in v0.1.42

type LeafRef struct {
	LocalPath  *config.Path `json:"localPath,omitempty"`
	RemotePath *config.Path `json:"remotePath,omitempty"`
}

type Option

type Option func(p *Parser)

Option can be used to manipulate Options.

func WithLogger

func WithLogger(log logging.Logger) Option

WithLogger specifies how the Parser should log messages.

type Parser

type Parser struct {
	// contains filtered or unexported fields
}

func NewParser

func NewParser(opts ...Option) *Parser

func (*Parser) AddJSONDataToList added in v0.1.15

func (p *Parser) AddJSONDataToList(x interface{}) (interface{}, error)

AddJSONDataToList adds the JSON data to a list

func (*Parser) AppendElemInPath added in v0.1.7

func (p *Parser) AppendElemInPath(path *config.Path, name, key string) *config.Path

AppendElemInPath adds a pathElem to the config gnmi path

func (*Parser) CleanCacheValueForComparison added in v0.1.7

func (p *Parser) CleanCacheValueForComparison(path *config.Path, cacheValue interface{}, valueType string) (x1 interface{}, err error)

we update the cache value for comparison 1. any map[string]interface{} -> will come from another subscription 2. any key in the path can be removed since this is part of the path iso data comparison 3. if the value is a slice we should remove all strings/int/floats, if the data is not a slice we remove all slices -> the gnmi server splits slice data and non slice data

func (*Parser) CleanConfig added in v0.1.7

func (p *Parser) CleanConfig(x1 map[string]interface{}) map[string]interface{}

func (*Parser) CleanConfig2String added in v0.1.7

func (p *Parser) CleanConfig2String(cfg map[string]interface{}) (map[string]interface{}, *string, error)

CleanConfig2String returns a clean config and a string clean means removing the prefixes in the json elements

func (*Parser) CleanDeviceValueForComparison added in v0.1.7

func (p *Parser) CleanDeviceValueForComparison(deviceValue interface{}) (interface{}, error)

CleanDeviceValueForComparison cleans the data coming from the device it cleans the prefixes of the yang value; key and value

func (*Parser) CompareValues added in v0.1.7

func (p *Parser) CompareValues(path *config.Path, cacheValue, deviceValue interface{}, valueType string) (jsondiff.Patch, error)

CompareValues compares the 2 values and provides a json diff result

func (*Parser) ConfigGnmiPathToName added in v0.1.7

func (p *Parser) ConfigGnmiPathToName(path *config.Path) string

ConfigGnmiPathToName converts a config gnmi path to a name where each element of the path is seperated by a "-"

func (*Parser) ConfigGnmiPathToXPath added in v0.1.7

func (p *Parser) ConfigGnmiPathToXPath(path *config.Path, keys bool) *string

ConfigGnmiPathToXPath converts a config gnmi path with or withour keys to a string pointer

func (*Parser) ConfigPath2GnmiPath added in v0.1.28

func (p *Parser) ConfigPath2GnmiPath(inPath *config.Path) *gnmi.Path

ConfigPath2GnmiPath converts the config path to gnmi path

func (*Parser) CopyAndCleanTxValues added in v0.1.7

func (p *Parser) CopyAndCleanTxValues(value interface{}) interface{}

func (*Parser) CreatePathElem added in v0.1.7

func (p *Parser) CreatePathElem(e *yang.Entry) *config.PathElem

CreatePathElem returns a config path element from a yang Entry

func (*Parser) DeepCopy added in v0.1.7

func (p *Parser) DeepCopy(in interface{}) (interface{}, error)

Make a deep copy from in into out object.

func (*Parser) DeepCopyPath added in v0.1.8

func (p *Parser) DeepCopyPath(in *config.Path) *config.Path

func (*Parser) DeepCopyResolvedLeafRef added in v0.1.42

func (p *Parser) DeepCopyResolvedLeafRef(in *ResolvedLeafRef) (out *ResolvedLeafRef)

func (*Parser) GetKeyInfo added in v0.1.7

func (p *Parser) GetKeyInfo(keys map[string]string) ([]string, []string)

GetKeyInfo returns all keys and values in a []slice

func (*Parser) GetKeyNamesFromConfigPaths added in v0.1.9

func (p *Parser) GetKeyNamesFromConfigPaths(path *config.Path, lastElem string, refPaths []*config.Path) []string

GetKeyNamesFromConfigPaths returns the keyNames for a path based on a reference path list (predetermined path list, coming from yang processing) due to yang processing this should always return keys, if not something was not configured properly

func (*Parser) GetTypeKind added in v0.1.7

func (p *Parser) GetTypeKind(e *yang.Entry) string

GetTypeKind return a string of the kind of the yang entry

func (*Parser) GetTypeName added in v0.1.7

func (p *Parser) GetTypeName(e *yang.Entry) string

GetypeName return a string of the type of the yang entry

func (*Parser) GetUpdatesFromJSONData added in v0.1.9

func (p *Parser) GetUpdatesFromJSONData(rootPath, path *config.Path, x1 interface{}, refPaths []*config.Path) []*config.Update

GetUpdatesFromJSONData returns config.Updates based on the JSON input data and config.Path/reference Paths These updates are used prepared so they can be send to a GNMI capable device

func (*Parser) GetValue added in v0.1.7

func (p *Parser) GetValue(updValue *gnmi.TypedValue) (interface{}, error)

GetValue return the data of the gnmo typed value

func (*Parser) GetValueType added in v0.1.7

func (p *Parser) GetValueType(value interface{}) string

GetValueType return if a value is a slice or not

func (*Parser) GnmiPath2ConfigPath added in v0.1.7

func (p *Parser) GnmiPath2ConfigPath(inPath *gnmi.Path) *config.Path

GnmiPath2ConfigPath converts the gnmi path to config path

func (*Parser) GnmiPathToXPath added in v0.1.7

func (p *Parser) GnmiPathToXPath(path *gnmi.Path, keys bool) *string

GnmiPathToXPath converts a gnmi path with or withour keys to a string pointer

func (*Parser) HandleEndOfListWithKeyInParseKeyWithAction added in v0.1.42

func (p *Parser) HandleEndOfListWithKeyInParseKeyWithAction(x interface{}, value string, tc *TraceCtxt)

HandleEndOfListWithKeyInParseKeyWithAction is called to assist Get, Create, Delete, Update Action it validates if the value of the JSON object matches the key value of the path

func (*Parser) HandleNotEndOfListWithKeyInParseKeyWithAction added in v0.1.42

func (p *Parser) HandleNotEndOfListWithKeyInParseKeyWithAction(x interface{}, value string, tc *TraceCtxt) bool

HandleNotEndOfListWithKeyInParseKeyWithAction is called to assist Get, Create, Delete, Update Action it validates if the value of the JSON object matches the key value of the path

func (*Parser) ParseJSONData2ConfigUpdates added in v0.1.9

func (p *Parser) ParseJSONData2ConfigUpdates(tc *TraceCtxt, path *config.Path, x1 interface{}, idx int, updates []*config.Update, refPaths []*config.Path) ([]*config.Update, *TraceCtxt)

ParseJSONData2UpdatePaths returns config.Updates according to the gnmi spec based on JSON input data

func (*Parser) ParseTreeWithAction added in v0.1.7

func (p *Parser) ParseTreeWithAction(x1 interface{}, tc *TraceCtxt, idx int) interface{}

p.ParseTreeWithAction parses various actions on a json object in a recursive way actions can be Get, Update, Delete and Create

func (*Parser) ParseTreeWithActionOld added in v0.1.42

func (p *Parser) ParseTreeWithActionOld(x1 interface{}, tc *TraceCtxt, idx int) interface{}

p.ParseTreeWithAction parses various actions on a json object in a recursive way actions can be Get, Update, Delete and Create

func (*Parser) PopulateLocalLeafRefKey added in v0.1.42

func (p *Parser) PopulateLocalLeafRefKey(x interface{}, tc *TraceCtxt, idx int)

func (*Parser) PopulateLocalLeafRefValue added in v0.1.42

func (p *Parser) PopulateLocalLeafRefValue(x interface{}, tc *TraceCtxt, idx int)

PopulateLocalLeafRefValue, populates the values and the keyvalues in the resolved leafref objects

func (*Parser) PostProcessAugmentValues added in v0.1.41

func (p *Parser) PostProcessAugmentValues(updates []*config.Update, objKeyValues map[int]map[string][]string, objKeyValuesIdx map[int]map[string]int) []*config.Update

func (*Parser) PostProcessUpdates added in v0.1.9

func (p *Parser) PostProcessUpdates(rootPath *config.Path, updates []*config.Update) []*config.Update

the order of the processed paths should remain fixed since this allows to fill out the data ina consistent way First we process the data to capture the values of all resolved keys per pathElem level Second we augment the values with the recorded data from the previous step Lastly we augment the path with the rootPath information

func (*Parser) PostProcessUpdatesCaptureValues added in v0.1.41

func (p *Parser) PostProcessUpdatesCaptureValues(updates []*config.Update) (map[int]map[string][]string, map[int]map[string]int)

PostProcessUpdatesCaptureValues captures the values of all resolved keys per pathElem level map[int]map[string][]string -> map[int -> level in path]map[string -> keyName][]string -> Value

func (*Parser) ProcessLeafRef added in v0.1.7

func (p *Parser) ProcessLeafRef(e *yang.Entry, resfullPath string, activeResPath *config.Path) (*config.Path, *config.Path, bool)

ProcessLeafRef processes the leafref and returns if a leafref localPath, remotePath and if the leafRef is local or external to the resource used for yang parser

func (*Parser) RemoveFirstEntry added in v0.1.7

func (p *Parser) RemoveFirstEntry(s string) string

RemoveFirstEntry removes the first entry of the xpath, so it trims the first element of the /

func (*Parser) RemoveLeafsFromJSONData added in v0.1.14

func (p *Parser) RemoveLeafsFromJSONData(x interface{}, leafStrings []string) interface{}

RemoveLeafsFromJSONData removes the leaf keys from the data

func (*Parser) TransformPathAsRelative2Resource added in v0.1.7

func (p *Parser) TransformPathAsRelative2Resource(localPath, activeResPath *config.Path) *config.Path

TransformPathAsRelative2Resource returns a relative path

func (*Parser) TransformPathToLeafRefPath added in v0.1.7

func (p *Parser) TransformPathToLeafRefPath(path *config.Path) *config.Path

TransformPathToLeafRefPath returns a config gnmi path tailored for leafrefs For a leafRef path the last entry of the name should be a key in the previous element

func (*Parser) XpathToConfigGnmiPath added in v0.1.8

func (p *Parser) XpathToConfigGnmiPath(xpath string, offset int) (path *config.Path)

XpathToGnmiPath convertss a xpath string to a config gnmi path

type ResolvedLeafRef added in v0.1.42

type ResolvedLeafRef struct {
	LocalPath  *config.Path `json:"localPath,omitempty"`
	RemotePath *config.Path `json:"remotePath,omitempty"`
	Value      string       `json:"value,omitempty"`
	Resolved   bool         `json:"resolved,omitempty"`
}

type TraceCtxt added in v0.1.4

type TraceCtxt struct {
	Action           ConfigTreeAction
	Found            bool
	Idx              int
	Path             *config.Path // the input path data
	ResolvedIdx      int          // keeps track of the amount of amount of resolved Indexes
	ResolvedLeafRefs []*ResolvedLeafRef
	Data             interface{}
	Value            interface{}
	Msg              []string
}

func (*TraceCtxt) AddMsg added in v0.1.42

func (tc *TraceCtxt) AddMsg(s string)

Jump to

Keyboard shortcuts

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