host

package
v0.22.1 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: Apache-2.0 Imports: 27 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	// LogService is the service name the agent publishes its log events
	// under (sys.log.agent); the Logs page filters on it.
	LogService = "agent"
	// LogPublishMaxPerSec caps how many log events per second each of the
	// agent's loggers publishes to NATS.
	LogPublishMaxPerSec = 100
)
View Source
const (
	PF_POLICY_CURRENT = "current"
	PF_POLICY_PLANNED = "planned"
)
View Source
const (
	PF_SELECTOR_KIND_VENDOR_REGEXP    = "vendor_regexp"
	PF_SELECTOR_VENDOR_REGEXP_DEFAULT = ".*"
)

Variables

View Source
var (
	MByte = 1024000
	GByte = 1073741824
)
View Source
var (
	ErrPlanRequired = errors.New("pf-plan required by not available")
)

Functions

func ApplyPfConfigs

func ApplyPfConfigs(pfConfigs *[]PfConfig) []error

apply the pf-policy concrete config we don't want to return if there is a single error - return slice of errors

func BusTrimmed

func BusTrimmed(address string) string

func DoesFileExist

func DoesFileExist(filename string) bool

func Driver

func Driver(address string) string

get the driver for a give pci bus address

func GenerateMac

func GenerateMac() net.HardwareAddr

func GetHostID

func GetHostID() (string, error)

func GetHostname

func GetHostname() (string, error)

func GetKernelCmdline

func GetKernelCmdline() (string, error)

cat /proc/cmdline BOOT_IMAGE=/vmlinuz-5.4.0-81-generic root=/dev/mapper/ubuntu--vg-ubuntu--lv ro intel_iommu=on iommu=pt vfio_iommu_type1.allow_unsafe_interrupts=1

func GetPciDeviceClass

func GetPciDeviceClass(address string) (string, error)

func GetPciDeviceDevice

func GetPciDeviceDevice(address string) (string, error)

func GetPciDeviceVendor

func GetPciDeviceVendor(address string) (string, error)

func GetPfsMap

func GetPfsMap() (map[string]*Pf, error)

func InPfKindList

func InPfKindList(file string) bool

func InterfaceNameFromAddress

func InterfaceNameFromAddress(address string) string

func IommuGroup

func IommuGroup(address string) string

get the iommu group for a given pci bus address

func IsAllocated

func IsAllocated(allocations []string, iommuGroup string) bool

is the given iommu group allocated to a process?

func IsEthernet

func IsEthernet(address string) bool

func IsPf

func IsPf(address string) bool

func IsVf

func IsVf(address string) bool

func IsVfio

func IsVfio(address string) bool

is the pci device controlled by vfio?

func PopulateVfIndexes

func PopulateVfIndexes(pf *Pf) error

virtfn0 -> ../0000:08:00.1

func ReadFileInt

func ReadFileInt(filename string) (int, error)

read a single int from a file

func ReadFileString

func ReadFileString(filename string) (string, error)

read a single string from a file

func SetNumVfs

func SetNumVfs(address string, num int) error

func UnbindDriver

func UnbindDriver(vfAddress string) error

func VfioAllocations

func VfioAllocations() ([]string, error)

Find all current vfio allocations part of this from mitchellh/go-ps/process_unix.go

func WriteFile

func WriteFile(path string, data []byte) error

Types

type Address

type Address struct {
	Domain   string
	Bus      string
	Slot     string
	Function string
}

func FromNetString

func FromNetString(address string) *Address

func FromString

func FromString(address string) *Address

Given a string address, returns a complete Address struct, filled in with domain, bus, slot and function components. The address string may either be in $BUS:$SLOT.$FUNCTION (BSF) format or it can be a full PCI address that includes the 4-digit $DOMAIN information as well: $DOMAIN:$BUS:$SLOT.$FUNCTION.

func (*Address) String

func (addr *Address) String() string

String() returns the canonical [D]BSF representation of this Address

type Agent

type Agent struct {
	Config         *AgentConfig
	ConfigLocation string
	Supervisor     *supervisor.Supervisor
	// Messenger is the NATS connection to the controller. Start opens it
	// when the configuration carries a controller URL; it stays nil
	// otherwise. Callers attach their own loggers to it with
	// Logger.AttachPublisher(agent.Messenger, LogService, LogPublishMaxPerSec).
	Messenger *messenger.Client
}

Agent represents the host agent runtime that manages network configurations and communicates with the controller.

func NewAgent

func NewAgent(config *AgentConfig) (*Agent, error)

NewAgent creates a new Agent instance with the given configuration.

func (*Agent) ApplyPfConfigs

func (a *Agent) ApplyPfConfigs()

ApplyPfConfigs applies the PF configurations for SR-IOV networking.

func (*Agent) SetConfigLocation

func (a *Agent) SetConfigLocation(location string)

SetConfigLocation sets the path to the configuration file.

func (*Agent) SignalAndWaitAllClosed

func (a *Agent) SignalAndWaitAllClosed()

SignalAndWaitAllClosed signals all routines to close, waits for them, and then closes the controller connection.

func (*Agent) Start

func (a *Agent) Start()

Start begins the agent's main routines: it connects to the controller and starts publishing the agent's log events there.

type AgentConfig

type AgentConfig struct {
	AccountID string `json:"account_id"`
	HostID    string `json:"host_id"`

	// NATS credentials
	JWT  string `json:"jwt"`
	Seed string `json:"seed"`

	// TLS credentials
	Certificate pki.Certificate `json:"certificate"`
	PrivateKey  pki.PrivateKey  `json:"private_key"`
	CA          pki.Certificate `json:"ca"`

	// Controller connection
	ControllerURL string `json:"controller_url"`

	// PF configurations for SR-IOV
	PfConfigs []PfConfig `json:"pf_configs"`
}

AgentConfig represents the configuration for the host agent. This includes credentials for connecting to the controller and optional PF (physical function) configurations for SR-IOV networking.

func AgentConfigFromFile

func AgentConfigFromFile(filename string) (*AgentConfig, error)

AgentConfigFromFile loads an AgentConfig from a JSON file.

type BusCount

type BusCount struct {
	Bus   string
	Count int
}

type BusCountList

type BusCountList []BusCount

func (BusCountList) Len

func (b BusCountList) Len() int

func (BusCountList) Less

func (b BusCountList) Less(i, j int) bool

func (BusCountList) Swap

func (b BusCountList) Swap(i, j int)

type DriverInfo

type DriverInfo struct {
	Name            string `json:"name"`
	DriverVersion   string `json:"driver_version"`
	FirmwareVersion string `json:"firmware_version"`
}

func KernelDeviceDriver

func KernelDeviceDriver(interfaceName string) (DriverInfo, error)

type Host

type Host struct {
	HostID        string `json:"host_id"`
	Hostname      string `json:"hostname"`
	OS            string `json:"os"`
	Kernel        string `json:"kernel"`
	Core          string `json:"core"`
	Platform      string `json:"platform"`
	CPUs          int    `json:"cpus"`
	CPUVendor     string `json:"cpu_vendor"`
	CPUModel      string `json:"cpu_model"`
	Distribution  string `json:"distribution"`
	DistributorID string `json:"distributor_id"`
	Release       string `json:"release"`
	Codename      string `json:"codename"`
	Pfs           Pfs    `json:"pfs"`
}

func GetHost

func GetHost() (*Host, error)

type Pf

type Pf struct {
	Address          string   `json:"address"`
	Index            int      `json:"index"`
	HostID           string   `json:"host_id"`
	Hostname         string   `json:"hostname"`
	Vendor           string   `json:"vendor"`
	VendorID         string   `json:"vendor_id"`
	Device           string   `json:"device"`
	DeviceID         string   `json:"device_id"`
	HasIPAddress     bool     `json:"has_ip_address"`
	IPAddresses      []string `json:"ip_addresses"` // ip_addr/netmask
	MacAddress       string   `json:"mac_address"`
	Driver           string   `json:"driver"`
	DriverVersion    string   `json:"driver_version"`
	FwVersion        string   `json:"fw_version"`
	InterfaceName    string   `json:"interface_name"`
	File             string   `json:"file"`
	BondMember       uint16   `json:"bond_member"`
	HasSubinterfaces bool     `json:"has_subinterfaces"` // could be dot1q, macvlan, etc.
	TotalVfs         int      `json:"total_vfs"`
	NumVfs           int      `json:"num_vfs"`
	Vfs              Vfs      `json:"vfs"`
}

func GetPf

func GetPf(address string) (Pf, error)

should we look at getting information fron netlink vs. traversing directory structures?

func GetPfByAddress

func GetPfByAddress(address string) (*Pf, error)

func GetPfs

func GetPfs() ([]*Pf, error)

func PfFromVfAddress

func PfFromVfAddress(address string) Pf

func VfPf

func VfPf(address string) Pf

get the PF for a given VF address

func (*Pf) Features

func (pf *Pf) Features() (map[string]bool, error)

func (*Pf) GetVfsConfig

func (pf *Pf) GetVfsConfig() error

func (*Pf) ID

func (pf *Pf) ID() string

func (*Pf) IPAddressesJoin

func (pf *Pf) IPAddressesJoin() string

func (*Pf) LinkSetUp

func (pf *Pf) LinkSetUp() error

func (*Pf) LinkState

func (pf *Pf) LinkState() (uint32, error)

func (*Pf) PopulateLinkAttrs

func (pf *Pf) PopulateLinkAttrs() error

func (*Pf) PopulateVfIndexes

func (pf *Pf) PopulateVfIndexes() error

func (*Pf) SetNumVfs

func (pf *Pf) SetNumVfs(num int) error

func (*Pf) SetVfMacAddresses

func (pf *Pf) SetVfMacAddresses() []error

handle (socket) for the network requests on a specific network namespace.

func (pf *Pf) SetVfMacAddressesNetlink() error

func (*Pf) Stats

func (pf *Pf) Stats() (map[string]uint64, error)

type PfConfig

type PfConfig struct {
	Address string `json:"address"`
	NumVfs  int    `json:"num_vfs"`
	Vfio    bool   `json:"vfio"`
}

type PfPolicy

type PfPolicy struct {
	PfSelector *PfSelector `json:"pf_selector"`
	OnReboot   bool        `json:"on_reboot"`
	MaxVfs     bool        `json:"max_vfs"`
	NumVfs     int         `json:"num_vfs"`
	// result of a state change to PLAN
	// host_id: pf_id: before|after
	PfPlan map[string]map[string]map[string]*Pf `json:"pf_plan"`
}

the host does not need to know id or version

func NewPfPolicy

func NewPfPolicy(pfSelectorOpts *PfSelectorOptions, pfPolicyOpts *PfPolicyOptions) (*PfPolicy, error)

func (*PfPolicy) Apply

func (pfPolicy *PfPolicy) Apply(hostID string) error

func (*PfPolicy) ApplyConcrete

func (pfPolicy *PfPolicy) ApplyConcrete(hostID string) (*[]PfConfig, error)

agent uses to calculate concrete from logical provided from server

func (*PfPolicy) Plan

func (pfPolicy *PfPolicy) Plan() error

type PfPolicyOptions

type PfPolicyOptions struct {
	OnReboot bool `json:"on_reboot"`
	MaxVfs   bool `json:"max_vfs"`
	NumVfs   int  `json:"num_vfs"`
}

type PfSelector

type PfSelector struct {
	Kind         string           `json:"kind"`
	VendorRegexp string           `json:"vendor_regexp"`
	Selected     *map[string][]Pf `json:"selected"` // by host_id
}

func NewPfSelector

func NewPfSelector(options *PfSelectorOptions) (*PfSelector, error)

func (*PfSelector) Select

func (pfSelector *PfSelector) Select(hosts *[]Host) error

this is used by host server to select from a slice of hosts that have already been selected by the host selector

func (*PfSelector) SelectLocalhost

func (pfSelector *PfSelector) SelectLocalhost() error

this is used by the agent locally to select pfs based on the selector configuration

type PfSelectorOptions

type PfSelectorOptions struct {
	Kind         string `json:"kind"`
	VendorRegexp string `json:"vendor_regexp"`
}

type Pfs

type Pfs []*Pf

type Vf

type Vf struct {
	PfAddress     string   `json:"pf_address"`
	Index         int      `json:"index"`
	PfIndex       int      `json:"pf_index"`
	Hostname      string   `json:"hostname"`
	HostID        string   `json:"host_id"`
	Address       string   `json:"address"`
	Vendor        string   `json:"vendor"`
	VendorID      string   `json:"vendor_id"`
	Device        string   `json:"device"`
	DeviceID      string   `json:"device_id"`
	MacAddress    string   `json:"mac_address"`
	IPAddresses   []string `json:"ip_addresses"`
	Driver        string   `json:"driver"`
	HostDriver    string   `json:"host_driver"`
	InterfaceName string   `json:"interface_name"`
	IommuGroup    string   `json:"iommu_group"`
	Allocated     bool     `json:"allocated"`
}

func GetVf

func GetVf(address string) (Vf, error)

func (*Vf) BindHostDriver

func (vf *Vf) BindHostDriver() error

func (*Vf) BindVfio

func (vf *Vf) BindVfio() error

make sure IOUMMU is enabled in kernel via grub: GRUB_CMDLINE_LINUX_DEFAULT="intel_iommu=on iommu=pt vfio_iommu_type1.allow_unsafe_interrupts=1"

func (*Vf) Bus

func (vf *Vf) Bus() string

func (*Vf) DeviceIDInt

func (vf *Vf) DeviceIDInt() *big.Int

func (*Vf) GetIPAddresses

func (vf *Vf) GetIPAddresses() error

func (*Vf) GetMacAddress

func (vf *Vf) GetMacAddress() error

this does not work if the vf is vfio-pci - does not have an interace name as it's not managed by the kernel driver

func (*Vf) ID

func (vf *Vf) ID() string

func (*Vf) IPAddressesJoin

func (vf *Vf) IPAddressesJoin() string

func (*Vf) UnbindDriver

func (vf *Vf) UnbindDriver() error

func (*Vf) VendorIDInt

func (vf *Vf) VendorIDInt() *big.Int

type Vfs

type Vfs []*Vf

func GetVfs

func GetVfs() (Vfs, error)

func GetVfsVendor

func GetVfsVendor(vendorName string) (Vfs, error)

func (*Vfs) ByPfAddress

func (vfs *Vfs) ByPfAddress(pfAddress string) Vfs

func (*Vfs) ByVendors

func (vfs *Vfs) ByVendors(vendorNames []string) Vfs

func (*Vfs) GetAllocations

func (vfs *Vfs) GetAllocations() error

func (*Vfs) NextVf

func (vfs *Vfs) NextVf(vendorName string) *Vf

Get the next available vf by vendor. will allocate evenly across pfs

func (*Vfs) NextVfByPf

func (vfs *Vfs) NextVfByPf(pfAddress string) *Vf

Get the next available vf by pf address

func (*Vfs) NumPfs

func (vfs *Vfs) NumPfs() int

Jump to

Keyboard shortcuts

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