device

package
v0.0.0-...-1768917 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetAddressOption

func GetAddressOption(optionName string,
	options map[string]string) (string, error)

GetAddressOption returns the option specified by optionName as a validated IP address or hostname.

func GetBoolOption

func GetBoolOption(optionName string,
	options map[string]string) (bool, error)

GetBoolOption returns the option specified by optionName as a boolean.

func GetDurationOption

func GetDurationOption(optionName string,
	options map[string]string) (time.Duration, error)

GetDurationOption returns the option specified by optionName as a time.Duration.

func GetIntOption

func GetIntOption(optionName string,
	options map[string]string) (int, error)

GetIntOption returns the option specified by optionName as an int.

func GetPortOption

func GetPortOption(optionName string, options map[string]string) (string, error)

GetPortOption returns the option specified by optionName as a validated port number.

func GetStringListOption

func GetStringListOption(optionName string,
	options map[string]string) ([]string, error)

GetStringListOption returns the option specified by optionName as a string slice.

func GetStringOption

func GetStringOption(optionName string,
	options map[string]string) (string, error)

GetStringOption returns the option specified by optionName as a string.

func IsBadConfigError

func IsBadConfigError(err error) bool

IsBadConfigError check if given errors is a bad configuration error.

func NewBadConfigError

func NewBadConfigError(err error) error

NewBadConfigError returns a BadConfigError

func NewBadConfigErrorf

func NewBadConfigErrorf(msg string, args ...interface{}) error

NewBadConfigErrorf returns a BadConfigError

func NewInventoryService

func NewInventoryService(inventory Inventory) gen.DeviceInventoryServer

NewInventoryService returns a protobuf DeviceInventoryServer from an Inventory.

func OptionHelp

func OptionHelp(deviceName string) (map[string]string, error)

OptionHelp returns the options and associated help strings of the specified device.

func PackageFile

func PackageFile(file string) string

PackageFile will find the last package and filename. Example: my/package/here/file.go -> here/file.go

func Register

func Register(name string, creator Creator, options map[string]Option)

Register registers a function that can create a new Device of the given name.

func Registered

func Registered() (keys []string)

Registered returns a list of registered device names.

func SanitizedOptions

func SanitizedOptions(options map[string]Option,
	config map[string]string) (map[string]string, error)

SanitizedOptions takes the map of device option keys and values passed in at the command line and checks it against the device or manager's exported list of accepted options, returning an error if there are inappropriate or missing options.

func Unregister

func Unregister(name string)

Unregister removes a device from the registry.

func WriteConfigs

func WriteConfigs(configPath string, configs []*Config) error

WriteConfigs writes a list of Config to the specified path.

Types

type ClusterClock

type ClusterClock interface {
	// clock channel created using below function is expected to be closed,
	// in case of any failures
	SubscribeToClusterClock(ctx context.Context,
		conn grpc.ClientConnInterface) (chan time.Time, error)
}

ClusterClock is the interface used to implement clock sync logic.

type Config

type Config struct {
	Name     string            `yaml:"Name,omitempty"`
	Device   string            `yaml:"Device,omitempty"`
	NoStream bool              `yaml:"NoStream,omitempty"`
	Options  map[string]string `yaml:"Options,omitempty"`
	LogLevel string            `yaml:"LogLevel,omitempty"`

	Credentials map[string]string `yaml:"Credentials,omitempty"`
	Enabled     bool              `yaml:"Enabled,omitempty"`
	ForceUpdate int64             `yaml:"ForceUpdate,omitempty"`
	// contains filtered or unexported fields
}

Config represents a single device configuration.

func NewConfig

func NewConfig(name string) *Config

NewConfig creates a new Config

func NewDeletedConfig

func NewDeletedConfig(name string) *Config

NewDeletedConfig creates a config that indicates a deleted device config.

func NewSyncEndConfig

func NewSyncEndConfig() *Config

NewSyncEndConfig creates a new config that represents the end of the sync phase

func ReadConfigs

func ReadConfigs(configPath string) ([]*Config, error)

ReadConfigs generates device configs from the config file at the specified path.

func (*Config) Equal

func (c *Config) Equal(o *Config) bool

Equal returns true if the two configs are config equal

func (*Config) IsDeleted

func (c *Config) IsDeleted() bool

IsDeleted returns true if the config is marked as deleted.

type Creator

type Creator = func(context.Context, map[string]string, provider.Monitor) (Device, error)

Creator returns a new instance of a Device.

type CredentialResolver

type CredentialResolver interface {
	Resolve(ctx context.Context, ref string) (string, error)
}

CredentialResolver is the interface used to resolve credentials.

type Device

type Device interface {
	Alive(ctx context.Context) (bool, error)
	DeviceID(ctx context.Context) (string, error)
	Providers() ([]provider.Provider, error)
	// Type should return the type of the device. The returned
	// values should be one of the constants defined for the purpose
	// in the cvclient/v2 package such as VirtualSwitch etc.
	// If this method returns an empty string, a default value
	// (NetworkElement) is used.
	Type() string
	// IPAddr should return the management IP address of the device.
	// Return "" if this is not known.
	IPAddr(ctx context.Context) (string, error)
}

A Device knows how to interact with a specific device.

type GRPCConnector

type GRPCConnector interface {
	Connect(ctx context.Context, conn *grpc.ClientConn,
		addr string, config GRPCConnectorConfig) (*grpc.ClientConn, error)
}

GRPCConnector allows callers to supply one gRPC connection and to create another to be used by a device implementation

func NewDefaultGRPCConnector

func NewDefaultGRPCConnector() GRPCConnector

NewDefaultGRPCConnector return empty object

type GRPCConnectorConfig

type GRPCConnectorConfig struct {
	DeviceID   string
	Standalone bool
}

GRPCConnectorConfig used to pass configuration parameters to GRPCConnector interface

type Info

type Info struct {
	ID      string
	Context context.Context
	Device  Device
	Config  *Config
	Status  ManagedDeviceStatus
}

Info contains the running state of an instantiated device.

func NewDeviceInfo

func NewDeviceInfo(ctx context.Context, config *Config, monitor provider.Monitor) (*Info, error)

NewDeviceInfo takes a device config, creates the device, and returns an device Info.

func (*Info) String

func (i *Info) String() string

type Inventory

type Inventory interface {
	Add(deviceInfo *Info) error
	Delete(key string) error
	Get(key string) (*Info, error)
	List() []*Info
	SetStatus(key string, status ManagedDeviceStatus) error
}

An Inventory maintains a set of devices.

func NewInventory

func NewInventory(ctx context.Context, gnmiClient gnmi.GNMIClient,
	clientFactory func(gnmi.GNMIClient, *Info) cvclient.CVClient) Inventory

NewInventory creates an Inventory. Deprecated: Use NewInventoryWithOptions instead.

func NewInventoryWithOptions

func NewInventoryWithOptions(ctx context.Context,
	options ...InventoryOption) Inventory

NewInventoryWithOptions creates an Inventory with the supplied options.

type InventoryOption

type InventoryOption func(*inventory)

InventoryOption configures how we create the Inventory.

func WithClientFactory

func WithClientFactory(
	f func(gnmi.GNMIClient, *Info) cvclient.CVClient) InventoryOption

WithClientFactory sets a client factory on the Inventory.

func WithGNMIClient

func WithGNMIClient(c gnmi.GNMIClient) InventoryOption

WithGNMIClient sets a gNMI client on the Inventory.

func WithGRPCConn

func WithGRPCConn(c *grpc.ClientConn) InventoryOption

WithGRPCConn sets a gRPC connection on the Inventory.

func WithGRPCConnector

func WithGRPCConnector(c GRPCConnector) InventoryOption

WithGRPCConnector sets a gRPC connector on the Inventory.

func WithGRPCServerAddr

func WithGRPCServerAddr(addr string) InventoryOption

WithGRPCServerAddr sets an grpc server address on the Inventory.

func WithStandaloneStatus

func WithStandaloneStatus(standalone bool) InventoryOption

WithStandaloneStatus sets flag to identify if its standalone sensor

type ManagedDeviceStatus

type ManagedDeviceStatus string

ManagedDeviceStatus contains the status of a managed device.

var (
	// StatusActive indicates that a device is active.
	StatusActive ManagedDeviceStatus = "DEVICE_STATUS_ACTIVE"
	// StatusInactive indicates that a device is inactive, should
	// still be tracked by CloudVision.
	StatusInactive ManagedDeviceStatus = "DEVICE_STATUS_INACTIVE"
	// StatusRemoved indicates that a device should no longer
	// be tracked by CloudVision.
	StatusRemoved ManagedDeviceStatus = "DEVICE_STATUS_REMOVED"
)

type Manager

type Manager interface {
	Device
	Manage(ctx context.Context, inventory Inventory) error
}

A Manager manages a device inventory, adding and deleting devices as appropriate.

type MetricTracker

type MetricTracker interface {
	// TrackDatasources tracks how many unique datasources exist in the sensor
	TrackDatasources(ctx context.Context, numDatasource int)
	// TrackDatasourceErrors tracks how many errors the datasources encounter. This metric is
	// partitioned by the type of the datasource and the error. This metric is monotonically
	// increasing
	TrackDatasourceErrors(ctx context.Context, typ string, errorType string)
	// TrackDatasourceDeploys tracks how often datasources of a particular type are deployed.
	// This metric is monotonically increasing
	TrackDatasourceDeploys(ctx context.Context, typ string)
	// TrackDatasourceRestarts tracks how often datasources of a particular type are restarted.
	// This metric is monotonically increasing
	TrackDatasourceRestarts(ctx context.Context, typ string)
}

MetricTracker tracks various metrics for datasources.

type Option

type Option struct {
	Description string
	Default     string
	Pattern     string
	Required    bool
}

Option defines a command-line option accepted by a device.

type Sensor

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

Sensor manages the config for multiple datasources

func NewSensor

func NewSensor(name string, logRate float64, opts ...SensorOption) *Sensor

NewSensor creates a new Sensor

func (*Sensor) Run

func (s *Sensor) Run(ctx context.Context) error

Run executes the sensor to start to manage datasources

type SensorConfig

type SensorConfig struct {
	Connector GRPCConnector

	// Receives the grpcServer connection and returns a CredentialResolver.
	CredResolverCreator func(conn *grpc.ClientConn) (CredentialResolver, error)

	//Receives the grpc connection and returns a ClusterClock
	ClusterClockCreator func(conn *grpc.ClientConn) (ClusterClock, error)
}

SensorConfig to store GRPCConnector config

type SensorOption

type SensorOption func(m *Sensor)

SensorOption is used to configure the Sensor.

func WithLimitDatasourcesToRun

func WithLimitDatasourcesToRun(limit int) SensorOption

WithLimitDatasourcesToRun limits the number of datasources that can be run at any given time in the sensor. The datasources that are run are random. If a datasources is stopped/deleted once we hit the limit, an arbitary one will be chosen to run in its place.

func WithMetricTracker

func WithMetricTracker(metricTracker MetricTracker) SensorOption

WithMetricTracker adds a metric tracker to the sensor to track metrics

func WithSensorClientFactory

func WithSensorClientFactory(f func(gnmi.GNMIClient,
	*Info) cvclient.CVClient) SensorOption

WithSensorClientFactory sets a cvclient factory on the Sensor.

func WithSensorClusterClock

func WithSensorClusterClock(c ClusterClock) SensorOption

WithSensorClusterClock sets a cluster clock object.

func WithSensorConfigChan

func WithSensorConfigChan(configCh chan *Config) SensorOption

WithSensorConfigChan provides a channel for supplying configs to the sensor

func WithSensorConnector

func WithSensorConnector(c GRPCConnector) SensorOption

WithSensorConnector sets a gRPC connector.

func WithSensorConnectorAddress

func WithSensorConnectorAddress(addr string) SensorOption

WithSensorConnectorAddress sets the connector address.

func WithSensorCredentialResolver

func WithSensorCredentialResolver(c CredentialResolver) SensorOption

WithSensorCredentialResolver sets a credential resolver.

func WithSensorFailureRetryBackoffBase

func WithSensorFailureRetryBackoffBase(d time.Duration) SensorOption

WithSensorFailureRetryBackoffBase sets the duration between datasource restarts on failure.

func WithSensorFailureRetryBackoffMax

func WithSensorFailureRetryBackoffMax(d time.Duration) SensorOption

WithSensorFailureRetryBackoffMax sets the max backoff between datasource restarts due to failures.

func WithSensorGNMIClient

func WithSensorGNMIClient(c gnmi.GNMIClient) SensorOption

WithSensorGNMIClient sets a gNMI client on the Sensor.

func WithSensorGRPCConn

func WithSensorGRPCConn(c *grpc.ClientConn) SensorOption

WithSensorGRPCConn sets a gRPC connection on the Sensor.

func WithSensorHeartbeatInterval

func WithSensorHeartbeatInterval(d time.Duration) SensorOption

WithSensorHeartbeatInterval sets the duration between sensor heartbeats.

func WithSensorHostname

func WithSensorHostname(hostname string) SensorOption

WithSensorHostname sets the the hostname of the Sensor.

func WithSensorIP

func WithSensorIP(ip string) SensorOption

WithSensorIP sets the the IP of the Sensor.

func WithSensorMaxClockDelta

func WithSensorMaxClockDelta(d time.Duration) SensorOption

WithSensorMaxClockDelta sets the time delta allowed between sensor and server clock

func WithSensorMetricIntervalTime

func WithSensorMetricIntervalTime(d time.Duration) SensorOption

WithSensorMetricIntervalTime sets the interval time used to send metrics to server

func WithSensorSkipSubscribe

func WithSensorSkipSubscribe(skipSubscribe bool) SensorOption

WithSensorSkipSubscribe determines whether we skip subscribing for datasource configurations

func WithSensorStandaloneStatus

func WithSensorStandaloneStatus(standalone bool) SensorOption

WithSensorStandaloneStatus sets the stanalone status.

Directories

Path Synopsis
Package cvclient defines an interface for connecting to and communicating with CloudVision.
Package cvclient defines an interface for connecting to and communicating with CloudVision.
mock
Package mock is a generated GoMock package.
Package mock is a generated GoMock package.
v1
Package v1 implements the version v1 client for communicating with CloudVision.
Package v1 implements the version v1 client for communicating with CloudVision.
v2
Package v2 implements the v2 protocol for communicating with CloudVision.
Package v2 implements the v2 protocol for communicating with CloudVision.
Package mock is a generated GoMock package.
Package mock is a generated GoMock package.

Jump to

Keyboard shortcuts

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