Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,7 @@ jobs:
- stable
- tip
suite:
- cluster
- standalone_core
- standalone_container
- standalone_network
- standalone_storage
backend:
- dir
os:
Expand Down
7 changes: 7 additions & 0 deletions doc/api-extensions.md
Original file line number Diff line number Diff line change
Expand Up @@ -2974,3 +2974,10 @@ Adds support for selecting an SR-IOV network interface by vendor ID, product ID,
## `network_zones_dns_contact`

Adds a `dns.contact` configuration key to network zones.

## `nic_attached_connected`

This introduces two new properties for NICs:

* `attached`, behaving like the `attached` key for disk and USB devices;
* `connected`, setting the up/down link state for the NIC (when supported).
122 changes: 121 additions & 1 deletion doc/config_options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -443,13 +443,29 @@ With VMs, this option supports mounting file system disk devices and paths withi

<!-- config group devices-infiniband end -->
<!-- config group devices-nic_bridged start -->
```{config:option} attached devices-nic_bridged
:default: "`true`"
:required: "no"
:shortdesc: "Whether the NIC is plugged in or not"
:type: "bool"

```

```{config:option} boot.priority devices-nic_bridged
:managed: "no"
:shortdesc: "Boot priority for VMs (higher value boots first)"
:type: "integer"

```

```{config:option} connected devices-nic_bridged
:default: "`true`"
:required: "no"
:shortdesc: "Whether the NIC is connected to the host network"
:type: "bool"

```

```{config:option} host_name devices-nic_bridged
:default: "randomly assigned"
:managed: "no"
Expand Down Expand Up @@ -668,6 +684,14 @@ With VMs, this option supports mounting file system disk devices and paths withi

<!-- config group devices-nic_bridged end -->
<!-- config group devices-nic_ipvlan start -->
```{config:option} attached devices-nic_ipvlan
:default: "`true`"
:required: "no"
:shortdesc: "Whether the NIC is plugged in or not"
:type: "bool"

```

```{config:option} gvrp devices-nic_ipvlan
:default: "false"
:shortdesc: "Register VLAN using GARP VLAN Registration Protocol"
Expand Down Expand Up @@ -755,13 +779,29 @@ With VMs, this option supports mounting file system disk devices and paths withi

<!-- config group devices-nic_ipvlan end -->
<!-- config group devices-nic_macvlan start -->
```{config:option} attached devices-nic_macvlan
:default: "`true`"
:required: "no"
:shortdesc: "Whether the NIC is plugged in or not"
:type: "bool"

```

```{config:option} boot.priority devices-nic_macvlan
:managed: "no"
:shortdesc: "Boot priority for VMs (higher value boots first)"
:type: "integer"

```

```{config:option} connected devices-nic_macvlan
:default: "`true`"
:required: "no"
:shortdesc: "Whether the NIC is connected to the host network (VM only)"
:type: "bool"

```

```{config:option} gvrp devices-nic_macvlan
:default: "false"
:managed: "no"
Expand Down Expand Up @@ -841,13 +881,29 @@ With VMs, this option supports mounting file system disk devices and paths withi

```

```{config:option} attached devices-nic_ovn
:default: "`true`"
:required: "no"
:shortdesc: "Whether the NIC is plugged in or not"
:type: "bool"

```

```{config:option} boot.priority devices-nic_ovn
:managed: "no"
:shortdesc: "Boot priority for VMs (higher value boots first)"
:type: "integer"

```

```{config:option} connected devices-nic_ovn
:default: "`true`"
:required: "no"
:shortdesc: "Whether the NIC is connected to the host network (container support requires setting `acceleration` to `none`)"
:type: "bool"

```

```{config:option} host_name devices-nic_ovn
:default: "randomly assigned"
:managed: "no"
Expand Down Expand Up @@ -1035,12 +1091,28 @@ With VMs, this option supports mounting file system disk devices and paths withi

<!-- config group devices-nic_ovn end -->
<!-- config group devices-nic_p2p start -->
```{config:option} boot.priotiry devices-nic_p2p
```{config:option} attached devices-nic_p2p
:default: "`true`"
:required: "no"
:shortdesc: "Whether the NIC is plugged in or not"
:type: "bool"

```

```{config:option} boot.priority devices-nic_p2p
:shortdesc: "Boot priority for VMs (higher value boots first)"
:type: "integer"

```

```{config:option} connected devices-nic_p2p
:default: "`true`"
:required: "no"
:shortdesc: "Whether the NIC is connected to the host network"
:type: "bool"

```

```{config:option} host_name devices-nic_p2p
:default: "randomly assigned"
:shortdesc: "The name of the interface on the host"
Expand Down Expand Up @@ -1120,13 +1192,29 @@ With VMs, this option supports mounting file system disk devices and paths withi

<!-- config group devices-nic_p2p end -->
<!-- config group devices-nic_physical start -->
```{config:option} attached devices-nic_physical
:default: "`true`"
:required: "no"
:shortdesc: "Whether the NIC is plugged in or not"
:type: "bool"

```

```{config:option} boot.priority devices-nic_physical
:managed: "no"
:shortdesc: "Boot priority for VMs (higher value boots first)"
:type: "integer"

```

```{config:option} connected devices-nic_physical
:default: "`true`"
:required: "no"
:shortdesc: "Whether the NIC is connected to the host network (VM only)"
:type: "bool"

```

```{config:option} gvrp devices-nic_physical
:default: "false"
:managed: "no"
Expand Down Expand Up @@ -1189,6 +1277,22 @@ With VMs, this option supports mounting file system disk devices and paths withi

<!-- config group devices-nic_physical end -->
<!-- config group devices-nic_routed start -->
```{config:option} attached devices-nic_routed
:default: "`true`"
:required: "no"
:shortdesc: "Whether the NIC is plugged in or not"
:type: "bool"

```

```{config:option} connected devices-nic_routed
:default: "`true`"
:required: "no"
:shortdesc: "Whether the NIC is connected to the host network"
:type: "bool"

```

```{config:option} gvrp devices-nic_routed
:default: "false"
:shortdesc: "Register VLAN using GARP VLAN Registration Protocol"
Expand Down Expand Up @@ -1375,13 +1479,29 @@ The custom policy routing table ID to add IPv6 static routes to (in addition to

<!-- config group devices-nic_routed end -->
<!-- config group devices-nic_sriov start -->
```{config:option} attached devices-nic_sriov
:default: "`true`"
:required: "no"
:shortdesc: "Whether the NIC is plugged in or not"
:type: "bool"

```

```{config:option} boot.priority devices-nic_sriov
:managed: "no"
:shortdesc: "Boot priority for VMs (higher value boots first)"
:type: "integer"

```

```{config:option} connected devices-nic_sriov
:default: "`true`"
:required: "no"
:shortdesc: "Whether the NIC is connected to the host network (VM only)"
:type: "bool"

```

```{config:option} hwaddr devices-nic_sriov
:default: "randomly assigned"
:managed: "no"
Expand Down
11 changes: 11 additions & 0 deletions internal/server/device/device_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,14 @@ func (d *deviceCommon) generateHostName(prefix string, hwaddr string) (string, e
// Handle instances.nic.host_name random mode or where no MAC address supplied.
return network.RandomDevName(prefix), nil
}

// setNICLink sets the link status (connected/disconnected) for the given NIC.
func (d *deviceCommon) setNICLink() error {
runConf := deviceConfig.RunConfig{}
runConf.NetworkInterface = []deviceConfig.RunConfigItem{
{Key: "devName", Value: d.name},
{Key: "connected", Value: d.config["connected"]},
}

return d.inst.DeviceEventHandler(&runConf)
}
8 changes: 4 additions & 4 deletions internal/server/device/device_utils_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -611,12 +611,12 @@ func networkSetupHostVethLimits(d *deviceCommon, oldConfig deviceConfig.Device,

// networkClearHostVethLimits clears any network rate limits to the veth device specified in the config.
func networkClearHostVethLimits(d *deviceCommon) error {
err := d.state.Firewall.InstanceClearNetPrio(d.inst.Project().Name, d.inst.Name(), d.config["host_name"])
if err != nil {
return err
// Detached NICs cannot be cleaned up this way.
if !util.IsTrueOrEmpty(d.config["attached"]) {
return nil
}

return nil
return d.state.Firewall.InstanceClearNetPrio(d.inst.Project().Name, d.inst.Name(), d.config["host_name"])
}

// networkValidGateway validates the gateway value.
Expand Down
2 changes: 2 additions & 0 deletions internal/server/device/nic.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ func nicValidationRules(requiredFields []string, optionalFields []string, instCo
"vendorid": validate.Optional(validate.IsDeviceID),
"productid": validate.Optional(validate.IsDeviceID),
"pci": validate.IsPCIAddress,
"attached": validate.Optional(validate.IsBool),
"connected": validate.Optional(validate.IsBool),
}

validators := map[string]func(value string) error{}
Expand Down
33 changes: 32 additions & 1 deletion internal/server/device/nic_bridged.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,24 @@ func (d *nicBridged) validateConfig(instConf instance.ConfigReader) error {
// managed: no
// shortdesc: Override the bus for the device (can be `virtio` or `usb`) (VM only)
"io.bus",

// gendoc:generate(entity=devices, group=nic_bridged, key=attached)
//
// ---
// type: bool
// default: `true`
// required: no
// shortdesc: Whether the NIC is plugged in or not
"attached",

// gendoc:generate(entity=devices, group=nic_bridged, key=connected)
//
// ---
// type: bool
// default: `true`
// required: no
// shortdesc: Whether the NIC is connected to the host network
"connected",
}

// checkWithManagedNetwork validates the device's settings against the managed network.
Expand Down Expand Up @@ -693,7 +711,7 @@ func (d *nicBridged) UpdatableFields(oldDevice Type) []string {
return []string{}
}

return []string{"limits.ingress", "limits.egress", "limits.max", "limits.priority", "ipv4.routes", "ipv6.routes", "ipv4.routes.external", "ipv6.routes.external", "ipv4.address", "ipv6.address", "security.mac_filtering", "security.ipv4_filtering", "security.ipv6_filtering", "security.acls", "security.acls.default.egress.action", "security.acls.default.egress.logged", "security.acls.default.ingress.action", "security.acls.default.ingress.logged"}
return []string{"limits.ingress", "limits.egress", "limits.max", "limits.priority", "ipv4.routes", "ipv6.routes", "ipv4.routes.external", "ipv6.routes.external", "ipv4.address", "ipv6.address", "security.mac_filtering", "security.ipv4_filtering", "security.ipv6_filtering", "security.acls", "security.acls.default.egress.action", "security.acls.default.egress.logged", "security.acls.default.ingress.action", "security.acls.default.ingress.logged", "connected"}
}

// Add is run when a device is added to a non-snapshot instance whether or not the instance is running.
Expand Down Expand Up @@ -726,6 +744,11 @@ func (d *nicBridged) PreStartCheck() error {

// Start is run when the device is added to a running instance or instance is starting up.
func (d *nicBridged) Start() (*deviceConfig.RunConfig, error) {
// Ignore detached NICs.
if !util.IsTrueOrEmpty(d.config["attached"]) {
return nil, nil
}

err := d.validateEnvironment()
if err != nil {
return nil, err
Expand Down Expand Up @@ -916,6 +939,7 @@ func (d *nicBridged) Start() (*deviceConfig.RunConfig, error) {
{Key: "flags", Value: "up"},
{Key: "link", Value: peerName},
{Key: "hwaddr", Value: d.config["hwaddr"]},
{Key: "connected", Value: d.config["connected"]},
}

if d.config["io.bus"] == "usb" {
Expand Down Expand Up @@ -1049,6 +1073,13 @@ func (d *nicBridged) Update(oldDevices deviceConfig.Devices, isRunning bool) err
return err
}

if isRunning {
err = d.setNICLink()
if err != nil {
return err
}
}

reverter.Success()

return nil
Expand Down
14 changes: 14 additions & 0 deletions internal/server/device/nic_ipvlan.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,15 @@ func (d *nicIPVLAN) validateConfig(instConf instance.ConfigReader) error {
// default: false
// shortdesc: Register VLAN using GARP VLAN Registration Protocol
"gvrp",

// gendoc:generate(entity=devices, group=nic_ipvlan, key=attached)
//
// ---
// type: bool
// default: `true`
// required: no
// shortdesc: Whether the NIC is plugged in or not
"attached",
}

rules := nicValidationRules(requiredFields, optionalFields, instConf)
Expand Down Expand Up @@ -301,6 +310,11 @@ func (d *nicIPVLAN) validateEnvironment() error {

// Start is run when the instance is starting up (IPVLAN doesn't support hot plugging).
func (d *nicIPVLAN) Start() (*deviceConfig.RunConfig, error) {
// Ignore detached NICs.
if !util.IsTrueOrEmpty(d.config["attached"]) {
return nil, nil
}

err := d.validateEnvironment()
if err != nil {
return nil, err
Expand Down
Loading
Loading