Skip to content

Commit

Permalink
Merge pull request #518 from stgraber/network
Browse files Browse the repository at this point in the history
  • Loading branch information
tych0 authored Feb 22, 2024
2 parents 26e60ad + f04ede8 commit e02f2a5
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions internal/server/network/ovs/ovs_actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"os/exec"
"strings"
"sync"
"time"

ovsdbClient "github.com/ovn-org/libovsdb/client"
ovsdbModel "github.com/ovn-org/libovsdb/model"
Expand All @@ -15,6 +16,7 @@ import (
"github.com/lxc/incus/internal/server/ip"
ovsSwitch "github.com/lxc/incus/internal/server/network/ovs/schema/ovs"
"github.com/lxc/incus/shared/subprocess"
"github.com/lxc/incus/shared/util"
)

// ovnBridgeMappingMutex locks access to read/write external-ids:ovn-bridge-mappings.
Expand Down Expand Up @@ -47,7 +49,7 @@ func (o *VSwitch) BridgeExists(bridgeName string) (bool, error) {
func (o *VSwitch) BridgeAdd(bridgeName string, mayExist bool, hwaddr net.HardwareAddr, mtu uint32) error {
ctx := context.TODO()

// Interface
// Create interface.
iface := ovsSwitch.Interface{
UUID: "interface",
Name: bridgeName,
Expand All @@ -63,7 +65,7 @@ func (o *VSwitch) BridgeAdd(bridgeName string, mayExist bool, hwaddr net.Hardwar
return err
}

// Port
// Create port.
port := ovsSwitch.Port{
UUID: "port",
Name: bridgeName,
Expand All @@ -75,7 +77,7 @@ func (o *VSwitch) BridgeAdd(bridgeName string, mayExist bool, hwaddr net.Hardwar
return err
}

// Bridge
// Create bridge.
bridge := ovsSwitch.Bridge{
UUID: "bridge",
Name: bridgeName,
Expand Down Expand Up @@ -103,7 +105,7 @@ func (o *VSwitch) BridgeAdd(bridgeName string, mayExist bool, hwaddr net.Hardwar
}
}

// Switch entry
// Create switch entry.
ovsRow := ovsSwitch.OpenvSwitch{
UUID: o.rootUUID,
}
Expand Down Expand Up @@ -131,7 +133,16 @@ func (o *VSwitch) BridgeAdd(bridgeName string, mayExist bool, hwaddr net.Hardwar
return err
}

return nil
// Wait for kernel interface to appear.
for i := 0; i < 50; i++ {
time.Sleep(100 * time.Millisecond)

if util.PathExists(fmt.Sprintf("/sys/class/net/%s", bridgeName)) {
return nil
}
}

return fmt.Errorf("Bridge interface failed to appear")
}

// BridgeDelete deletes a bridge.
Expand Down

0 comments on commit e02f2a5

Please sign in to comment.