example

package
v0.0.0-...-ae3a0a2 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2022 License: MPL-2.0 Imports: 16 Imported by: 0

README

This package provides an example implementation of a device plugin for reference.

Behavior

The example device plugin models files within a specified directory as devices. The plugin will periodically scan the directory for changes and will expose them via the streaming Fingerprint RPC. Device health is set to unhealthy if the file has a specific filemode permission as described by the config unhealthy_perm. Further statistics are also collected on the detected devices.

Config

The configuration should be passed via an HCL file that begins with a top level config stanza:

config {
  dir = "/my/path/to/scan"
  list_period = "1s"
  unhealthy_perm = "-rw-rw-rw-"
}

The valid configuration options are:

  • dir (string: "."): The directory to scan for files that will represent fake devices.
  • list_period (string: "5s"): The interval to scan the directory for changes.
  • unhealthy_perm (string: "-rwxrwxrwx"): The file mode permission that if set on a detected file will casue the device to be considered unhealthy.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Dir           string `codec:"dir"`
	ListPeriod    string `codec:"list_period"`
	UnhealthyPerm string `codec:"unhealthy_perm"`
}

Config contains configuration information for the plugin.

type FsDevice

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

FsDevice is an example device plugin. The device plugin exposes files as devices and periodically polls the directory for new files. If a file has a given file permission, it is considered unhealthy. This device plugin is purely for use as an example.

func NewExampleDevice

func NewExampleDevice(log log.Logger) *FsDevice

NewExampleDevice returns a new example device plugin.

func (*FsDevice) ConfigSchema

func (d *FsDevice) ConfigSchema() (*hclspec.Spec, error)

ConfigSchema returns the plugins configuration schema.

func (*FsDevice) Fingerprint

func (d *FsDevice) Fingerprint(ctx context.Context) (<-chan *device.FingerprintResponse, error)

Fingerprint streams detected devices. If device changes are detected or the devices health changes, messages will be emitted.

func (*FsDevice) PluginInfo

func (d *FsDevice) PluginInfo() (*base.PluginInfoResponse, error)

PluginInfo returns information describing the plugin.

func (*FsDevice) Reserve

func (d *FsDevice) Reserve(deviceIDs []string) (*device.ContainerReservation, error)

Reserve returns information on how to mount the given devices.

func (*FsDevice) SetConfig

func (d *FsDevice) SetConfig(c *base.Config) error

SetConfig is used to set the configuration of the plugin.

func (*FsDevice) Stats

func (d *FsDevice) Stats(ctx context.Context, interval time.Duration) (<-chan *device.StatsResponse, error)

Stats streams statistics for the detected devices.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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