net

package
v0.0.2-beta.1 Latest Latest
Warning

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

Go to latest
Published: May 19, 2026 License: MPL-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// FingerprintAttributeKeyPrefix is the key prefix to use when creating and
	// adding attributes during the fingerprint process.
	FingerprintAttributeKeyPrefix = "driver.virt.network."

	// NetworkStateActive is string representation to declare a network is in
	// active state. This is translated from "true" using the go-libvirt SDK
	// and 1 from the raw libvirt API when query if the network is active.
	NetworkStateActive = "active"

	// NetworkStateInactive is string representation to declare a network is in
	// inactive state. This is translated from "false" using the go-libvirt SDK
	// and 0 from the raw libvirt API when query if the network is active.
	NetworkStateInactive = "inactive"
)

Variables

This section is empty.

Functions

func IsActiveString

func IsActiveString(active bool) string

IsActiveString converts the boolean response from the IsActive call of libvirt network to a human-readable string. This string copies the vocabulary used by virsh for consistency.

func NetworkInterfaceHCLSpec

func NetworkInterfaceHCLSpec() *hclspec.Spec

NetworkInterfaceHCLSpec returns the HCL specification for a virtual machines network interface object.

Types

type MacvtapMode

type MacvtapMode string

MacvtapMode represents the operating mode of a macvtap interface.

const (
	// MacvtapModeBridge allows the VM to communicate with other VMs on the
	// same host and with the external network, but not with the host itself.
	MacvtapModeBridge MacvtapMode = "bridge"

	// MacvtapModePrivate isolates the VM so it can only communicate with the
	// external network. Communication with the host and other VMs on the same
	// lower device is blocked.
	MacvtapModePrivate MacvtapMode = "private"

	// MacvtapModeVEPA (Virtual Ethernet Port Aggregator) forwards all traffic
	// to an external switch that is responsible for hairpin routing between
	// VMs on the same host.
	MacvtapModeVEPA MacvtapMode = "vepa"

	// MacvtapModePassthrough passes a single lower device exclusively to the
	// VM, giving it direct access to the physical interface. The lower device
	// is set into promiscuous mode.
	MacvtapModePassthrough MacvtapMode = "passthrough"
)

type Net

type Net interface {
	// Init performs any initialization that may be required by the virtualization
	// network sub-system.
	Init() error

	// Fingerprint interrogates the host system and populates the attribute
	// mapping with relevant network information. Any errors performing this
	// should be logged by the implementor, but not considered terminal, which
	// explains the lack of error response. Each entry should use
	// FingerprintAttributeKeyPrefix as a base.
	Fingerprint(map[string]*structs.Attribute)

	// VMStartedBuild performs any network configuration required once the
	// driver has successfully started a VM. Any error returned will be
	// considered terminal to the start of the VM and therefore halt any
	// further progress and result in the task being restarted.
	VMStartedBuild(*VMStartedBuildRequest) (*VMStartedBuildResponse, error)

	// VMTerminatedTeardown performs all the network teardown required to clean
	// the host and any systems of configuration specific to the task. If an
	// error is encountered, Nomad will retry the stop/kill process, so all
	// implementations must be able to support this and not enter death spirals
	// when an error occurs.
	VMTerminatedTeardown(*VMTerminatedTeardownRequest) (*VMTerminatedTeardownResponse, error)
}

Net is the interface that defines the virtualization network sub-system. It should be the only link from the main driver and compute functionality, into the network. This helps encapsulate the logic making future development easier, even allowing for this code to be moved into its own application if desired.

type NetworkInterfaceBridgeConfig

type NetworkInterfaceBridgeConfig struct {

	// Name is the name of the bridge interface to use. This relates to the
	// output seen from commands such as "ip addr show" or "virsh net-info".
	Name string `codec:"name"`

	// Ports contains a list of port labels which will be exposed on the host
	// via mapping to the network interface. These labels must exist within the
	// job specification network block.
	Ports []string `codec:"ports"`
}

NetworkInterfaceBridgeConfig is the network object when a VM is attached to a bridged network interface.

func (*NetworkInterfaceBridgeConfig) Equal

Equal returns if the given NetworkInterfaceBridgeConfig is equal.

type NetworkInterfaceConfig

type NetworkInterfaceConfig struct {
	Bridge  *NetworkInterfaceBridgeConfig  `codec:"bridge"`
	Macvtap *NetworkInterfaceMacvtapConfig `codec:"macvtap"`
}

NetworkInterfaceConfig contains all the possible network interface options that a VM currently supports via the Nomad driver.

func (*NetworkInterfaceConfig) Equal

Equal returns if the given NetworkInterfaceConfig is equal.

type NetworkInterfaceMacvtapConfig

type NetworkInterfaceMacvtapConfig struct {

	// Device is the name of the lower (physical or virtual) network device
	// that the macvtap interface will be created on top of. This should match
	// an interface visible in "ip addr show" output (e.g. "eth0", "ens3").
	Device string `codec:"device"`

	// Mode controls the traffic isolation policy of the macvtap interface.
	// Accepted values are: "bridge", "private", "vepa", and "passthrough".
	// Defaults to "bridge" when not specified.
	Mode MacvtapMode `codec:"mode"`
}

NetworkInterfaceMacvtapConfig is the network object when a VM is attached to a macvtap interface.

func (*NetworkInterfaceMacvtapConfig) Equal

Equal returns if the given NetworkInterfaceMacvtapConfig is equal.

type NetworkInterfacesConfig

type NetworkInterfacesConfig []*NetworkInterfaceConfig

NetworkInterfacesConfig is the list of network interfaces that should be added to a VM. Currently, the driver only supports a single entry which is validated within the Validate function.

Due to its type, callers will need to dereference the object before performing iteration.

func (NetworkInterfacesConfig) ConfigurableOnly

func (n NetworkInterfacesConfig) ConfigurableOnly() NetworkInterfacesConfig

ConfigurableOnly returns a new NetworkInterfacesConfig containing only configurable interfaces. This is used to filter out interface types such as macvtap that manage their own network identity and have no interaction with Nomad's host-side port mapping machinery.

func (NetworkInterfacesConfig) Equal

Equal returns if the given NetworkInterfacesConfig is equal.

func (*NetworkInterfacesConfig) Validate

func (n *NetworkInterfacesConfig) Validate() error

Validate ensures the NetworkInterfaces is a valid object supported by the driver. Any error returned here should be considered terminal for a task and stop the process execution.

type TeardownSpec

type TeardownSpec struct {

	// IPTablesRules specifies the rules used to build the initial VM
	// networking. Each entry is a rule, the rule is a list of strings which
	// mimics how iptables is called.
	//   i[0] is the table name.
	//   i[1] is the chain name.
	//   i[2:] is the rule args.
	IPTablesRules [][]string

	// DHCPReservation specifies the reservation string used for registering
	// a DHCP address for a virtual machine.
	DHCPReservation string

	// Network is the name of the network used and which provided the
	// DHCP lease.
	Network string
}

TeardownSpec contains a specification which will be stored in the task handle and used when stopping/killing the task. It should include information which either expedites the process or is critical to the process.

func (*TeardownSpec) Equal

func (t *TeardownSpec) Equal(rhs *TeardownSpec) bool

Equal returns if the given TeardownSpec is equal.

type VMStartedBuildRequest

type VMStartedBuildRequest struct {
	VMName    string
	Hostname  string
	NetConfig NetworkInterfacesConfig
	Resources *drivers.Resources
	Hwaddrs   []string
}

VMStartedBuildRequest is the request object used to ask the network sub-system to perform its configuration, once a VM has been started.

func (*VMStartedBuildRequest) Equal

Equal returns if the given VMStartBuildRequest is equal. NOTE: ignores Resources value

type VMStartedBuildResponse

type VMStartedBuildResponse struct {

	// DriverNetwork is the object returned to Nomad once the task is started
	// and is used to populate service discovery. The network sub-system should
	// fill in all details; the driver will not do this and simply pass the
	// object straight onto Nomad.
	DriverNetwork *drivers.DriverNetwork

	// TeardownSpec contains a specification which will be stored in the task
	// handle and used when stopping/killing the task. It should include
	// information which either expedites the process or is critical to the
	// process.
	TeardownSpec *TeardownSpec
}

VMStartedBuildResponse is the response sent object once the network sub-system has performed its configuration for a running VM.

type VMTerminatedTeardownRequest

type VMTerminatedTeardownRequest struct {
	TeardownSpec *TeardownSpec
}

VMTerminatedTeardownRequest is the request object used to ask the network sub-system to perform its teardown of a VMs network configuration.

func (*VMTerminatedTeardownRequest) Equal

Equal returns if the given VMTerminatedTeardownRequest is equal.

type VMTerminatedTeardownResponse

type VMTerminatedTeardownResponse struct{}

VMTerminatedTeardownResponse is the response object returned when the network sub-system has performed its teardown of a VMs network configuration.

Jump to

Keyboard shortcuts

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