parser

package
v0.2.8 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2022 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

func GnmiPathDeepCopy added in v0.1.200

func GnmiPathDeepCopy(in *gnmi.Path) *gnmi.Path

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 LeafRefGnmi added in v0.1.62

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

type LeafRefValidationKind added in v0.1.57

type LeafRefValidationKind string
const (
	LeafRefValidationLocal    LeafRefValidationKind = "local"
	LeafRefValidationExternal LeafRefValidationKind = "external"
)

type Operation added in v0.1.58

type Operation struct {
	Type  OperationType
	Path  string
	Value interface{}
}

type OperationType added in v0.1.58

type OperationType string

A OperationType represents an operatio on a JSON resource

const (
	// delete
	OperationTypeDelete OperationType = "Delete"
	// replace
	OperationTypeUpdate OperationType = "Update"
	// create
	OperationTypeCreate OperationType = "Create"
)

Condition Kinds.

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) AppendElemInGnmiPath added in v0.1.62

func (p *Parser) AppendElemInGnmiPath(path *gnmi.Path, name string, keys []string) *gnmi.Path

AppendElemInPath adds a pathElem to the config gnmi path

func (*Parser) AppendElemInGnmiPathWithFullKey added in v0.1.62

func (p *Parser) AppendElemInGnmiPathWithFullKey(path *gnmi.Path, name string, key map[string]string) *gnmi.Path

AppendElemInPath adds a pathElem to the config gnmi path

func (*Parser) CleanCacheValueForComparisonGnmi added in v0.1.62

func (p *Parser) CleanCacheValueForComparisonGnmi(path *gnmi.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) CompareGnmiPathsWithResourceKeys added in v0.1.62

func (p *Parser) CompareGnmiPathsWithResourceKeys(path *gnmi.Path, resourceKeys map[string]string) (bool, []*gnmi.Path, map[string]string)

CompareConfigPathsWithResourceKeys returns changed true when resourceKeys were provided and if they are different. In this case the deletePath is also valid, otherwise when changd is false the delete path is not reliable

func (*Parser) CompareJSONData added in v0.1.58

func (p *Parser) CompareJSONData(t, s []byte) ([]Operation, error)

CompareJSONData compares the target with the source and provides operation guides

func (*Parser) CompareValuesGnmi added in v0.1.62

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

CompareValues compares the 2 values and provides a json diff result

func (*Parser) CopyAndCleanTxValues added in v0.1.7

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

func (*Parser) CopyPathElemKey added in v0.1.50

func (p *Parser) CopyPathElemKey(key map[string]string) map[string]string

func (*Parser) CreatePathElem added in v0.1.7

func (p *Parser) CreatePathElem(e *yang.Entry) *gnmi.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) DeepCopyGnmiPath added in v0.1.62

func (p *Parser) DeepCopyGnmiPath(in *gnmi.Path) *gnmi.Path

func (*Parser) DeepCopyResolvedLeafRefGnmi added in v0.1.62

func (p *Parser) DeepCopyResolvedLeafRefGnmi(in *ResolvedLeafRefGnmi) (out *ResolvedLeafRefGnmi)

func (*Parser) FindResourceDeltaGnmi added in v0.1.62

func (p *Parser) FindResourceDeltaGnmi(updatesx1, updatesx2 []*gnmi.Update, log logging.Logger) ([]*gnmi.Path, []*gnmi.Update, error)

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) GetKeyNamesFromGnmiPaths added in v0.1.62

func (p *Parser) GetKeyNamesFromGnmiPaths(path *gnmi.Path, lastElem string, refPaths []*gnmi.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) GetRemoteGnmiPathsFromResolvedLeafRef added in v0.1.62

func (p *Parser) GetRemoteGnmiPathsFromResolvedLeafRef(resolvedLeafRef *ResolvedLeafRefGnmi) []*gnmi.Path

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) GetUpdatesFromJSONDataGnmi added in v0.1.62

func (p *Parser) GetUpdatesFromJSONDataGnmi(rootPath, path *gnmi.Path, x1 interface{}, refPaths []*gnmi.Path) []*gnmi.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 gnmi 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) GnmiPathToName added in v0.1.62

func (p *Parser) GnmiPathToName(path *gnmi.Path) string

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

func (*Parser) GnmiPathToSubResourceName added in v0.1.187

func (p *Parser) GnmiPathToSubResourceName(path *gnmi.Path) string

GnmiPathToSubResourceName special case since we have to remove the - from the first elemen

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) HandleEndOfListWithKeyInParseKeyWithActionGnmi added in v0.1.62

func (p *Parser) HandleEndOfListWithKeyInParseKeyWithActionGnmi(x interface{}, value string, tc *TraceCtxtGnmi)

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) HandleNotEndOfListWithKeyInParseKeyWithActionGnmi added in v0.1.62

func (p *Parser) HandleNotEndOfListWithKeyInParseKeyWithActionGnmi(x interface{}, value string, tc *TraceCtxtGnmi) 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) ParseJSONData2ConfigUpdatesGnmi added in v0.1.62

func (p *Parser) ParseJSONData2ConfigUpdatesGnmi(tc *TraceCtxtGnmi, path *gnmi.Path, x1 interface{}, idx int, updates []*gnmi.Update, refPaths []*gnmi.Path) ([]*gnmi.Update, *TraceCtxtGnmi)

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

func (*Parser) ParseTreeWithActionGnmi added in v0.1.62

func (p *Parser) ParseTreeWithActionGnmi(x1 interface{}, tc *TraceCtxtGnmi, idx, lridx int) interface{}

p.ParseTreeWithAction parses various actions on a json object in a recursive way actions can be Get, Update, Delete and Create, LeafRef, Find and LeafRefResolution NOTE1: idx and lridx are indexes that needs to be relevant in the ctxt of the recursive resolution and cannot be put in tc since tc is a global conext NOTE2: ConfigResolveLeafRef is a run to completion and hsould not find a return in the path until the end NOTE3: all other actions are returning something based on the path they traverse

func (*Parser) PopulateLocalLeafRefKeyGnmi added in v0.1.62

func (p *Parser) PopulateLocalLeafRefKeyGnmi(x interface{}, tc *TraceCtxtGnmi, idx, lridx int)

func (*Parser) PopulateLocalLeafRefValueGnmi added in v0.1.62

func (p *Parser) PopulateLocalLeafRefValueGnmi(x interface{}, tc *TraceCtxtGnmi, idx, lridx int)

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

func (*Parser) PopulateRemoteLeafRefKeyGnmi added in v0.1.62

func (p *Parser) PopulateRemoteLeafRefKeyGnmi(rlref *ResolvedLeafRefGnmi)

Populates the Key of the remote leafref

func (*Parser) PostProcessAugmentValuesGnmi added in v0.1.62

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

func (*Parser) PostProcessUpdatesCaptureValuesGnmi added in v0.1.62

func (p *Parser) PostProcessUpdatesCaptureValuesGnmi(updates []*gnmi.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) PostProcessUpdatesGnmi added in v0.1.62

func (p *Parser) PostProcessUpdatesGnmi(rootPath *gnmi.Path, updates []*gnmi.Update) []*gnmi.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) ProcessLeafRefGnmi added in v0.1.62

func (p *Parser) ProcessLeafRefGnmi(e *yang.Entry, resfullPath string, activeResPath *gnmi.Path) (*gnmi.Path, *gnmi.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) TransformGnmiPathAsRelative2Resource added in v0.1.62

func (p *Parser) TransformGnmiPathAsRelative2Resource(localPath, activeResPath *gnmi.Path) *gnmi.Path

TransformPathAsRelative2Resource returns a relative path

func (*Parser) TransformGnmiPathToLeafRefPath added in v0.1.62

func (p *Parser) TransformGnmiPathToLeafRefPath(path *gnmi.Path) *gnmi.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) ValidateLeafRefGnmi added in v0.1.62

func (p *Parser) ValidateLeafRefGnmi(kind LeafRefValidationKind, x1, x2 interface{}, definedLeafRefs []*LeafRefGnmi, log logging.Logger) (bool, []*ResolvedLeafRefGnmi, error)

ValidateLocalLeafRef validates the local leafred information on the local resource data first the local leafrefs are resolved and if they are resolved the remote leaf refs within the objects are located / based on the result this funciton return the result + information on the validation

func (*Parser) ValidateParentDependency added in v0.1.57

func (p *Parser) ValidateParentDependency(x1 interface{}, definedParentDependencies []*LeafRefGnmi, log logging.Logger) (bool, []*ResolvedLeafRefGnmi, error)

ValidateParentDependency validates the parent resource dependency based on the result this function returns the result + information on the validation we use a get here since we resolved the values of the keys alreay

func (*Parser) ValidateParentDependencyGnmi added in v0.1.62

func (p *Parser) ValidateParentDependencyGnmi(x1 interface{}, value string, definedParentDependencies []*LeafRefGnmi, log logging.Logger) (bool, []*ResolvedLeafRefGnmi, error)

NOT SURE IF A SINGLE VALUE IS SOMETHING THAT WILL BE OK ACCROSS THE BOARD ValidateParentDependency validates the parent resource dependency the remote leaf refs within the objects are located / based on the result this funciton return the result + information on the validation

func (*Parser) XpathToGnmiPath added in v0.1.7

func (p *Parser) XpathToGnmiPath(xpath string, offset int) (path *gnmi.Path)

XpathToGnmiPath convertss a xpath string to a config gnmi path

type ResolvedLeafRefGnmi added in v0.1.62

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

type TraceCtxtGnmi added in v0.1.62

type TraceCtxtGnmi struct {
	Action           ConfigTreeAction
	Found            bool
	Idx              int
	Path             *gnmi.Path             // the input path data
	ResolvedLeafRefs []*ResolvedLeafRefGnmi // holds all the resolved leafRefs if they get resolved
	Data             interface{}
	Value            interface{} // used for leafref resolution
	Msg              []string
}

func (*TraceCtxtGnmi) AddMsg added in v0.1.62

func (tc *TraceCtxtGnmi) AddMsg(s string)

Jump to

Keyboard shortcuts

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