gnmi

package
v0.0.0-...-a8d7af0 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2024 License: Apache-2.0 Imports: 31 Imported by: 21

Documentation

Index

Constants

View Source
const (

	// HostnameArg is the value to be replaced by the actual hostname
	HostnameArg = "HOSTNAME"
)

Variables

View Source
var TLSVersions = getTLSVersions()

TLSVersions is a map from TLS version strings to the tls version constants in the crypto/tls package

Functions

func ArbitrationExt

func ArbitrationExt(s string) (*gnmi_ext.Extension, error)

ArbitrationExt takes a string representation of a master arbitration value (e.g. "23", "role:42") and return a *gnmi_ext.Extension.

func Capabilities

func Capabilities(ctx context.Context, client pb.GNMIClient) error

Capabilities retuns the capabilities of the client.

func DecimalToFloat

func DecimalToFloat(dec *pb.Decimal64) float64

DecimalToFloat converts a gNMI Decimal64 to a float64

func Dial

func Dial(cfg *Config) (pb.GNMIClient, error)

Dial connects to a gnmi service and returns a client

func DialContext

func DialContext(ctx context.Context, cfg *Config) (pb.GNMIClient, error)

DialContext connects to a gnmi service and returns a client

func DialContextConn

func DialContextConn(ctx context.Context, cfg *Config) (*grpc.ClientConn, error)

DialContextConn connects to a gnmi service and return a client connection

func ElemToString

func ElemToString(elm *pb.PathElem) string

ElemToString is used to get the string representation of the Element.

func ExtractValue

func ExtractValue(update *pb.Update) (interface{}, error)

ExtractValue pulls a value out of a gNMI Update, parsing JSON if present. Possible return types:

string
int64
uint64
bool
[]byte
float32
*gnmi.Decimal64
json.Number
*any.Any
[]interface{}
map[string]interface{}

func Get

func Get(ctx context.Context, client pb.GNMIClient, paths [][]string,
	origin string) error

Get sends a GetRequest to the given client.

func GetWithRequest

func GetWithRequest(ctx context.Context, client pb.GNMIClient,
	req *pb.GetRequest) error

GetWithRequest takes a fully formed GetRequest, performs the Get, and displays any response.

func HistoryRangeExtension

func HistoryRangeExtension(s, e int64) *gnmi_ext.Extension_History

HistoryRangeExtension returns an Extension_History for the the specified start and end times.

func HistorySnapshotExtension

func HistorySnapshotExtension(t int64) *gnmi_ext.Extension_History

HistorySnapshotExtension returns an Extension_History for the given time.

func JoinPaths

func JoinPaths(paths ...*pb.Path) *pb.Path

JoinPaths joins multiple gnmi paths into a single path

func KeyToString

func KeyToString(key map[string]string) string

KeyToString is used to get the string representation of the keys.

func LogSubscribeResponse

func LogSubscribeResponse(response *pb.SubscribeResponse) error

LogSubscribeResponse logs update responses to stderr.

func NewContext

func NewContext(ctx context.Context, cfg *Config) context.Context

NewContext returns a new context with username and password metadata if they are set in cfg, as well as any other metadata provided.

func NewGetRequest

func NewGetRequest(paths [][]string, origin string) (*pb.GetRequest, error)

NewGetRequest returns a GetRequest for the given paths

func NewSubscribeRequest

func NewSubscribeRequest(subscribeOptions *SubscribeOptions) (*pb.SubscribeRequest, error)

NewSubscribeRequest returns a SubscribeRequest for the given paths

func NotificationToMap

func NotificationToMap(notif *gnmi.Notification) (map[string]interface{}, error)

NotificationToMap converts a Notification into a map[string]interface{}

func ParseGNMIElements

func ParseGNMIElements(elms []string) (*pb.Path, error)

ParseGNMIElements builds up a gnmi path, from user-supplied text

func ParseHostnames

func ParseHostnames(list string) ([]string, error)

ParseHostnames parses a comma-separated list of names and replaces HOSTNAME with the current hostname in it

func ParseKeys

func ParseKeys(keyPart string) (map[string]string, error)

ParseKeys parses just the keys portion of the stringified elem and returns the map of stringified keys.

func Set

func Set(ctx context.Context, client pb.GNMIClient, setOps []*Operation,
	exts ...*gnmi_ext.Extension) error

Set sends a SetRequest to the given client.

func SplitPath

func SplitPath(path string) []string

SplitPath splits a gnmi path according to the spec. See https://github.com/openconfig/reference/blob/master/rpc/gnmi/gnmi-path-conventions.md No validation is done. Behavior is undefined if path is an invalid gnmi path. TODO: Do validation?

func SplitPaths

func SplitPaths(paths []string) [][]string

SplitPaths splits multiple gnmi paths

func StrPath

func StrPath(path *pb.Path) string

StrPath builds a human-readable form of a gnmi path. e.g. /a/b/c[e=f]

func StrUpdateVal

func StrUpdateVal(u *pb.Update) string

StrUpdateVal will return a string representing the value within the supplied update

func StrUpdateValCompactJSON

func StrUpdateValCompactJSON(u *pb.Update) string

StrUpdateValCompactJSON will return a string representing the value within the supplied update. If the value is a JSON value, a non-indented JSON string will be returned.

func StrVal

func StrVal(val *pb.TypedValue) string

StrVal will return a string representing the supplied value

func StrValCompactJSON

func StrValCompactJSON(val *pb.TypedValue) string

StrValCompactJSON will return a string representing the supplied value. If the value is a JSON value, a non-indented JSON string will be returned.

func Subscribe

func Subscribe(ctx context.Context, client pb.GNMIClient, subscribeOptions *SubscribeOptions,
	respChan chan<- *pb.SubscribeResponse, errChan chan<- error)

Subscribe sends a SubscribeRequest to the given client. Deprecated: Use SubscribeErr instead.

func SubscribeErr

func SubscribeErr(ctx context.Context, client pb.GNMIClient, subscribeOptions *SubscribeOptions,
	respChan chan<- *pb.SubscribeResponse) error

SubscribeErr makes a gNMI.Subscribe call and writes the responses to the respChan. Before returning respChan will be closed.

func TypedValue

func TypedValue(val interface{}) *pb.TypedValue

TypedValue marshals an interface into a gNMI TypedValue value

Types

type Config

type Config struct {
	Addr string

	// File path to load data or raw cert data. Alternatively, raw data can be provided below.
	CAFile   string
	CertFile string
	KeyFile  string

	// Raw certificate data. If respective file is provided above, that is used instead.
	CAData   []byte
	CertData []byte
	KeyData  []byte

	Password      string
	Username      string
	TLS           bool
	TLSMinVersion string
	TLSMaxVersion string
	Compression   string
	BDP           bool
	DialOptions   []grpc.DialOption
	Token         string
	GRPCMetadata  map[string]string
}

Config is the gnmi.Client config

func ParseFlags

func ParseFlags() (*Config, []string)

ParseFlags reads arguments from stdin and returns a populated Config object and a list of paths to subscribe to

type Operation

type Operation struct {
	Type   string
	Origin string
	Target string
	Path   []string
	Val    string
}

Operation describes an gNMI operation.

type PublishFunc

type PublishFunc func(addr string, message proto.Message)

PublishFunc is the method to publish responses

type SubscribeOptions

type SubscribeOptions struct {
	UpdatesOnly       bool
	Prefix            string
	Mode              string
	StreamMode        string
	SampleInterval    uint64
	SuppressRedundant bool
	HeartbeatInterval uint64
	Paths             [][]string
	Origin            string
	Target            string
	Extensions        []*gnmi_ext.Extension
}

SubscribeOptions is the gNMI subscription request options

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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