Skip to content

Commit

Permalink
lxd/device/nic/ovn: Call InstanceDevicePortStart when adding port
Browse files Browse the repository at this point in the history
So that the logical port and its config is setup in OVN DB at create time
rather than at start time.

This way OVN's dynamic IP allocations are long-lived for the duration of
the instance rather than potentially changing when the instance is rebooted.

Fixes #11658

Signed-off-by: Thomas Parrott <[email protected]>
  • Loading branch information
tomponline committed Aug 8, 2024
1 parent e403824 commit b540b89
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion lxd/device/nic_ovn.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,41 @@ func (d *nicOVN) checkAddressConflict() error {

// Add is run when a device is added to a non-snapshot instance whether or not the instance is running.
func (d *nicOVN) Add() error {
return d.network.InstanceDevicePortAdd(d.inst.LocalConfig()["volatile.uuid"], d.name, d.config)
networkVethFillFromVolatile(d.config, d.volatileGet())

// Load uplink network config.
uplinkNetworkName := d.network.Config()["network"]

var err error
var uplink *api.Network

err = d.state.DB.Cluster.Transaction(context.TODO(), func(ctx context.Context, tx *db.ClusterTx) error {
_, uplink, _, err = tx.GetNetworkInAnyState(ctx, api.ProjectDefaultName, uplinkNetworkName)

return err
})
if err != nil {
return fmt.Errorf("Failed to load uplink network %q: %w", uplinkNetworkName, err)
}

err = d.network.InstanceDevicePortAdd(d.inst.LocalConfig()["volatile.uuid"], d.name, d.config)
if err != nil {
return err
}

// Add new OVN logical switch port for instance.
_, err = d.network.InstanceDevicePortStart(&network.OVNInstanceNICSetupOpts{
InstanceUUID: d.inst.LocalConfig()["volatile.uuid"],
DNSName: d.inst.Name(),
DeviceName: d.name,
DeviceConfig: d.config,
UplinkConfig: uplink.Config,
}, nil)
if err != nil {
return fmt.Errorf("Failed setting up OVN port: %w", err)
}

return nil
}

// PreStartCheck checks the managed parent network is available (if relevant).
Expand Down

0 comments on commit b540b89

Please sign in to comment.