common

package
v0.0.0-...-328d806 Latest Latest
Warning

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

Go to latest
Published: May 6, 2024 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OP_NONE   CVLOperation = 0      //Used to just validate the config without any operation
	OP_CREATE              = 1 << 0 //For Create operation
	OP_UPDATE              = 1 << 1 //For Update operation
	OP_DELETE              = 1 << 2 //For Delete operation
)

Variables

This section is empty.

Functions

func KeyMatch

func KeyMatch(value, pattern string) bool

KeyMatch checks if the value matches a key pattern. vIndex and pIndex are start positions of value and pattern strings to match. Mimics redis pattern matcher - i.e, glob like pattern matcher which matches '/' against wildcard. Supports '*' and '?' wildcards with '\' as the escape character. '*' matches any char sequence or none; '?' matches exactly one char. Character classes are not supported (redis supports it).

Types

type CVLEditConfigData

type CVLEditConfigData struct {
	VType     CVLValidateType   //Validation type
	VOp       CVLOperation      //Operation type
	Key       string            //Key format : "PORT|Ethernet4"
	Data      map[string]string //Value :  {"alias": "40GE0/28", "mtu" : 9100,  "admin_status":  down}
	ReplaceOp bool
}

CVLEditConfigData Strcture for key and data in API

type CVLOperation

type CVLOperation uint

type CVLValidateType

type CVLValidateType uint
const (
	VALIDATE_NONE      CVLValidateType = iota //Data is used as dependent data
	VALIDATE_SYNTAX                           //Syntax is checked and data is used as dependent data
	VALIDATE_SEMANTICS                        //Semantics is checked
	VALIDATE_ALL                              //Syntax and Semantics are checked
)

type DBAccess

type DBAccess interface {
	Exists(key string) IntResult
	Keys(pattern string) StrSliceResult
	HGet(key, field string) StrResult
	HMGet(key string, fields ...string) SliceResult
	HGetAll(key string) StrMapResult
	Pipeline() PipeResult

	// Lookup entries using a Search criteria and return them in sonic db json format.
	// E.g, {"INTERFACE": {"Ethernet0": {"vrf", "Vrf1"}, "Ethernet0|1.2.3.4": {"NULL": "NULL"}}}
	// TODO fix the return value for not found case
	Lookup(s Search) JsonResult
	// Count entries using a Search criteria. Returns 0 if there are no matches.
	Count(s Search) IntResult
}

DBAccess is used by cvl and custom validation functions to access the ConfigDB. This allows cvl clients to plugin additional data source, like transaction cache, into cvl. Most of the interface methods mimic the go-redis APIs. It also defines Lookup and Count methods to perform advanced search by matching hash field values.

type IntResult

type IntResult interface {
	Result() (int64, error)
}

type JsonResult

type JsonResult interface {
	Result() (string, error) //TODO have it as map instead of string
}

type PipeResult

type PipeResult interface {
	Keys(pattern string) StrSliceResult
	HGet(key, field string) StrResult
	HMGet(key string, fields ...string) SliceResult
	HGetAll(key string) StrMapResult
	Exec() error
	Close()
}

type RequestCacheType

type RequestCacheType struct {
	ReqData  CVLEditConfigData
	YangData *xmlquery.Node
}

RequestCacheType Struct for request data and YANG data

type Search struct {
	// Pattern to match the keys from a redis table. Must contain a table name prefix.
	// E.g, `INTERFACE|Ethernet0` `INTERFACE|*` "INTERFACE|*|*"
	Pattern string
	// Predicate is a lua condition statement to inspect an entry's key and hash attributes.
	// It can use map variables 'k' and 'h' to access key & hash attributes.
	// E.g, `k['type'] == 'L3' and h['enabled'] == true`
	Predicate string
	// KeyNames must contain the key component names in order. Required only if Predicate uses 'k'.
	// E.g, if ["name","type"], a key "ACL|TEST|L3" will expand to lua map {name="TEST", type="L3"}
	KeyNames []string
	// WithField selects a entry only if it contains this hash field
	WithField string
	// Limit the results to maximum these number of entries
	Limit int
}

Search criteria for advanced lookup. Initial filtering is done by matching the key Pattern. Results are further refined by applying Predicate, WithField and Limit constraints (optional)

type SliceResult

type SliceResult interface {
	Result() ([]interface{}, error)
}

type StrMapResult

type StrMapResult interface {
	Result() (map[string]string, error)
}

type StrResult

type StrResult interface {
	Result() (string, error)
}

type StrSliceResult

type StrSliceResult interface {
	Result() ([]string, error)
}

Jump to

Keyboard shortcuts

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