Version: v0.0.0-...-b84de06 Latest Latest

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

Go to latest
Published: Aug 9, 2020 License: Apache-2.0 Imports: 53 Imported by: 0



Example (InfinibandValidMAC)
tests := []string{
	"00:00:00:00:fe:80:00:00:00:00:00:00:02:00:5e:10:00:00:00:01", // valid long form
	"a0:00:0f:c0:fe:80:00:00:00:00:00:00:4a:c8:f9:1b:aa:57:ef:19", // valid long form
	"02:00:5e:10:00:00:00:01",                                     // valid short form
	"4a:c8:f9:1b:aa:57:ef:19",                                     // valid short form
	"00-00-00-00-fe-80-00-00-00-00-00-00-02-00-5e-10-00-00-00-01", // invalid delimiter long form
	"0000.0000.fe80.0000.0000.0000.0200.5e10.0000.0001",           // invalid delimiter long form
	"02-00-5e-10-00-00-00-01",                                     // invalid delimiter short form
	"0200.5e10.0000.0001",                                         // invalid delimiter short form
	"00:00:5e:00:53:01",                                           // invalid ethernet MAC

for _, v := range tests {
	err := infinibandValidMAC(v)
	fmt.Printf("%s, %t\n", v, err == nil)

00:00:00:00:fe:80:00:00:00:00:00:00:02:00:5e:10:00:00:00:01, true
a0:00:0f:c0:fe:80:00:00:00:00:00:00:4a:c8:f9:1b:aa:57:ef:19, true
02:00:5e:10:00:00:00:01, true
4a:c8:f9:1b:aa:57:ef:19, true
00-00-00-00-fe-80-00-00-00-00-00-00-02-00-5e-10-00-00-00-01, false
0000.0000.fe80.0000.0000.0000.0200.5e10.0000.0001, false
02-00-5e-10-00-00-00-01, false
0200.5e10.0000.0001, false
00:00:5e:00:53:01, false
invalid, false
, false




View Source
const IBDevPrefix = "infiniband.unix"

IBDevPrefix Infiniband devices prefix.


View Source
var ErrUnsupportedDevType = fmt.Errorf("Unsupported device type")

ErrUnsupportedDevType is the error that occurs when an unsupported device type is created.


func BlockFsDetect

func BlockFsDetect(dev string) (string, error)

BlockFsDetect detects the type of block device.

func DiskMount

func DiskMount(srcPath string, dstPath string, readonly bool, recursive bool, propagation string, rawMountOptions string, fsName string) error

DiskMount mounts a disk device.

func InotifyHandler

func InotifyHandler(s *state.State)

InotifyHandler starts watching for inotify events.

func InotifyInit

func InotifyInit(s *state.State) (int, error)

InotifyInit initialises the inotify internal structures.

func IsBlockdev

func IsBlockdev(path string) bool

IsBlockdev returns boolean indicating whether device is block type.

func NetworkGetDevMAC

func NetworkGetDevMAC(devName string) (string, error)

NetworkGetDevMAC retrieves the current MAC setting for a named network device.

func NetworkRemoveInterface

func NetworkRemoveInterface(nic string) error

NetworkRemoveInterface removes a network interface by name.

func NetworkSetDevMAC

func NetworkSetDevMAC(devName string, mac string) error

NetworkSetDevMAC sets the MAC setting for a named network device if different from current.

func NetworkSetDevMTU

func NetworkSetDevMTU(devName string, mtu uint64) error

NetworkSetDevMTU sets the MTU setting for a named network device if different from current.

func ProxyParseAddr

func ProxyParseAddr(addr string) (*deviceConfig.ProxyAddress, error)

ProxyParseAddr validates a proxy address and parses it into its constituent parts.

func USBRunHandlers

func USBRunHandlers(state *state.State, event *USBEvent)

USBRunHandlers executes any handlers registered for USB events.

func UnixDeviceExists

func UnixDeviceExists(devicesPath string, prefix string, path string) bool

UnixDeviceExists checks if the unix device already exists in devices path.

func UnixHotplugRunHandlers

func UnixHotplugRunHandlers(state *state.State, event *UnixHotplugEvent)

UnixHotplugRunHandlers executes any handlers registered for Unix hotplug events.

func Validate

func Validate(instConfig instance.ConfigReader, state *state.State, name string, conf deviceConfig.Device) error

Validate checks a device's config is valid. This only requires an instance.ConfigReader rather than an full blown instance to allow profile devices to be validated too.


type Device

type Device interface {
	// CanHotPlug returns true if device can be managed whilst instance is running.
	// It also returns a slice of config fields that can be live updated. If only fields in this
	// list have changed then Update() is called rather than triggering a device remove & add.
	CanHotPlug() (bool, []string)

	// Add performs any host-side setup when a device is added to an instance.
	// It is called irrespective of whether the instance is running or not.
	Add() error

	// Start peforms any host-side configuration required to start the device for the instance.
	// This can be when a device is plugged into a running instance or the instance is starting.
	// Returns run-time configuration needed for configuring the instance with the new device.
	Start() (*deviceConfig.RunConfig, error)

	// Register provides the ability for a device to subcribe to events that LXD can generate.
	// It is called after a device is started (after Start()) or when LXD starts.
	Register() error

	// Update performs host-side modifications for a device based on the difference between the
	// current config and previous devices config supplied as an argument. This called if the
	// only config fields that have changed are supplied in the list returned from CanHotPlug().
	// The function also accepts a boolean indicating whether the instance is running or not.
	Update(oldDevices deviceConfig.Devices, running bool) error

	// Stop performs any host-side cleanup required when a device is removed from an instance,
	// either due to unplugging it from a running instance or instance is being shutdown.
	// Returns run-time configuration needed for detaching the device from the instance.
	Stop() (*deviceConfig.RunConfig, error)

	// Remove performs any host-side cleanup when an instance is removed from an instance.
	Remove() error

Device represents a device that can be added to an instance.

func New

func New(inst instance.Instance, state *state.State, name string, conf deviceConfig.Device, volatileGet VolatileGetter, volatileSet VolatileSetter) (Device, error)

New instantiates a new device struct, validates the supplied config and sets it into the device. If the device type is valid, but the other config validation fails then an instantiated device is still returned with the validation error. If an unknown device is requested or the device is not compatible with the instance type then an ErrUnsupportedDevType error is returned.

type USBEvent

type USBEvent struct {
	Action string

	Vendor  string
	Product string

	Path        string
	Major       uint32
	Minor       uint32
	UeventParts []string
	UeventLen   int

USBEvent represents the properties of a USB device uevent.

func USBNewEvent

func USBNewEvent(action string, vendor string, product string, major string, minor string, busnum string, devnum string, devname string, ueventParts []string, ueventLen int) (USBEvent, error)

USBNewEvent instantiates a new USBEvent struct.

type UnixDevice

type UnixDevice struct {
	HostPath     string      // Absolute path to the device on the host.
	RelativePath string      // Relative path where the device will be mounted inside instance.
	Type         string      // Type of device; c (for char) or b for (block).
	Major        uint32      // Major number.
	Minor        uint32      // Minor number.
	Mode         os.FileMode // File mode.
	UID          int         // Owner UID.
	GID          int         // Owner GID.

UnixDevice contains information about a created UNIX device.

func UnixDeviceCreate

func UnixDeviceCreate(s *state.State, idmapSet *idmap.IdmapSet, devicesPath string, prefix string, m deviceConfig.Device, defaultMode bool) (*UnixDevice, error)

UnixDeviceCreate creates a UNIX device (either block or char). If the supplied device config map contains a major and minor number for the device, then a stat is avoided, otherwise this info retrieved from the origin device. Similarly, if a mode is supplied in the device config map or defaultMode is set as true, then the device is created with the supplied or default mode (0660) respectively, otherwise the origin device's mode is used. If the device config doesn't contain a type field then it defaults to created a unix-char device. The ownership of the created device defaults to root (0) but can be specified with the uid and gid fields in the device config map. It returns a UnixDevice containing information about the device created.

type UnixEvent

type UnixEvent struct {
	Action string // The type of event, either add or remove.
	Path   string // The absolute source path on the host.

UnixEvent represents the properties of a Unix device inotify event.

type UnixHotplugEvent

type UnixHotplugEvent struct {
	Action string

	Vendor  string
	Product string

	Path        string
	Major       uint32
	Minor       uint32
	Subsystem   string
	UeventParts []string
	UeventLen   int

UnixHotplugEvent represents the properties of a Unix hotplug device uevent.

func UnixHotplugNewEvent

func UnixHotplugNewEvent(action string, vendor string, product string, major string, minor string, subsystem string, devname string, ueventParts []string, ueventLen int) (UnixHotplugEvent, error)

UnixHotplugNewEvent instantiates a new UnixHotplugEvent struct.

type UnixSubscription

type UnixSubscription struct {
	Path    string                                           // The absolute source path on the host.
	Handler func(UnixEvent) (*deviceConfig.RunConfig, error) // The function to run when an event occurs.

UnixSubscription used to subcribe to specific events.

type VirtFuncInfo

type VirtFuncInfo struct {
	VF         int              `json:"vf"`
	Address    string           `json:"address"`
	MAC        string           `json:"mac"` // Deprecated
	VLANs      []map[string]int `json:"vlan_list"`
	SpoofCheck bool             `json:"spoofchk"`

VirtFuncInfo holds information about SR-IOV virtual functions.

type VolatileGetter

type VolatileGetter func() map[string]string

VolatileGetter is a function that retrieves any key/value string that exists in the LXD database config for this instance. It should only return keys that match the volatile device name prefix, and should remove the prefix before being returned.

type VolatileSetter

type VolatileSetter func(map[string]string) error

VolatileSetter is a function that accepts one or more key/value strings to save into the LXD config for this instance. It should add the volatile device name prefix to each key when saving.


Path Synopsis
Package nictype is a small package to allow resolving NIC "network" key to "nictype" key.
Package nictype is a small package to allow resolving NIC "network" key to "nictype" key.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL