util

package
v0.0.0-...-5f1191e Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	INFO = 0 + iota
	WARNING
	ERROR
	FATAL
	INFO_DEBUG
	INFO_API
	INFO_DATA
	INFO_DETAIL
	INFO_TRACE
	INFO_ALL
)
View Source
const (
	TRACE_MIN      = 0
	TRACE_MAX      = 8
	TRACE_CACHE    = 1 << TRACE_MIN
	TRACE_LIBYANG  = 1 << 1
	TRACE_YPARSER  = 1 << 2
	TRACE_CREATE   = 1 << 3
	TRACE_UPDATE   = 1 << 4
	TRACE_DELETE   = 1 << 5
	TRACE_SEMANTIC = 1 << 6
	TRACE_ONERROR  = 1 << 7
	TRACE_SYNTAX   = 1 << TRACE_MAX
)
View Source
const CVL_LOG_FILE = "/tmp/cvl.log"
View Source
const ENV_VAR_SONIC_DB_CONFIG_FILE = "DB_CONFIG_PATH"
View Source
const SONIC_DB_CONFIG_FILE string = "/var/run/redis/sonic-db/database_config.json"

Variables

View Source
var CVL_CFG_FILE string = "/usr/sbin/cvl_cfg.json"
View Source
var CVL_SCHEMA string = "schema/"
View Source
var FILTER_ENTRIES_LUASCRIPT *redis.Script = redis.NewScript(`
    --ARGV[1] => Key patterns
    --ARGV[2] => Key names separated by '|'
    --ARGV[3] => predicate patterns
    --ARGV[4] => Fields to return
    --ARGV[5] => Count of entries to return

    local tableData = {} ; local tbl = {}

    local keys = redis.call('KEYS', ARGV[1])
    if #keys == 0 then return end

    local count = -1
    if (ARGV[5] ~= nil and ARGV[5] ~= "") then count=tonumber(ARGV[5]) end

    local sepStart = string.find(keys[1], "|")
    if sepStart == nil then return ; end

    -- Function to load lua predicate code
    local function loadPredicateScript(str)
        if (str == nil or str == "") then return nil; end

        local f, err = loadstring("return function (k,h) " .. str .. " end")
        if f then return f(); else return nil;end
    end

    local keySetNames = {}
    ARGV[2]:gsub("([^|]+)",function(c) table.insert(keySetNames, c) end)

    local predicate = loadPredicateScript(ARGV[3])

    for _, key in ipairs(keys) do
        local hash = redis.call('HGETALL', key)
        local row = {}; local keySet = {}; local keyVal = {}
        local keyOnly = string.sub(key, sepStart+1)

        for index = 1, #hash, 2 do
            row[hash[index]] = hash[index + 1]
        end

        --Split key values
        keyOnly:gsub("([^|]+)", function(c)  table.insert(keyVal, c) end)

        for idx = 1, #keySetNames, 1 do
            keySet[keySetNames[idx]] = keyVal[idx]
        end

        if (predicate == nil) or (predicate(keySet, row) == true) then
            tbl[keyOnly] = row
        end

        if (count ~= -1 and #tbl == count) then break end

    end

    tableData[string.sub(keys[1], 0, sepStart-1)] = tbl

    return cjson.encode(tableData)
`)
View Source
var Tracing bool = false

Functions

func AddToFormatterFuncsMap

func AddToFormatterFuncsMap(s string, f Formatter) error

func CVL_LEVEL_LOG

func CVL_LEVEL_LOG(level CVLLogLevel, format string, args ...interface{})

func ConfigFileSyncHandler

func ConfigFileSyncHandler()

func Format

func Format(fname string, val string) string

func GetDbId

func GetDbId(dbName string) int

GetDbId Get DB id on given db name

func GetDbPassword

func GetDbPassword(dbName string) string

GetDbPassword Get DB password

func GetDbSeparator

func GetDbSeparator(dbName string) string

GetDbSeparator Get DB separator based on given DB name

func GetDbSock

func GetDbSock(dbName string) string

GetDbSock Get DB socket path

func GetDbTcpAddr

func GetDbTcpAddr(dbName string) string

GetDbTcpAddr Get DB TCP endpoint

func GetDifference

func GetDifference(a, b []string) []string

GetDifference This will determine items which are missing in a-list if size of b-list is greater missing in b-list if size of a-list is greater missing in a-list if size of a-list, b-list are equal

func GetTableAndKeyFromRedisKey

func GetTableAndKeyFromRedisKey(redisKey, delim string) (string, string)

GetTableAndKeyFromRedisKey This will return tableName and Key from given rediskey. For ex. rediskey = PORTCHANNEL_MEMBER|PortChannel1|Ethernet4 Output will be "PORTCHANNEL_MEMBER" and "PortChannel1|Ethernet4"

func IsTraceAllowed

func IsTraceAllowed(tracelevel CVLTraceLevel) bool

func IsTraceSet

func IsTraceSet() bool

func NewDbClient

func NewDbClient(dbName string) *redis.Client

NewDbClient Get new redis client

func ReadConfFile

func ReadConfFile() map[string]string

func SetTrace

func SetTrace(on bool)

func SkipSemanticValidation

func SkipSemanticValidation() bool

func SkipValidation

func SkipValidation() bool

func TRACE_LEVEL_LOG

func TRACE_LEVEL_LOG(tracelevel CVLTraceLevel, fmtStr string, args ...interface{})

func UpdateRedisOptions

func UpdateRedisOptions(opts *redis.Options)

Types

type CVLLogLevel

type CVLLogLevel uint8

CVLLogLevel Logging Level for CVL global logging

type CVLTraceLevel

type CVLTraceLevel uint32

CVLTraceLevel Logging levels for CVL Tracing

type Formatter

type Formatter func(string) string

Jump to

Keyboard shortcuts

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