Skip to content

Commit

Permalink
Merge pull request juju#5004 from tych0/use-right-bridge-for-lxdif
Browse files Browse the repository at this point in the history
lxd provider: use right bind address for LXD

Prevents:

ERROR cannot find network interface "lxcbr0": route ip+net: no such network interface
ERROR invalid config: route ip+net: no such network interface

when the user doesn't have a lxcbr0 (i.e. doesn't have lxc1 installed).

Signed-off-by: Tycho Andersen <[email protected]>

(Review request: http://reviews.vapour.ws/r/4446/)
  • Loading branch information
jujubot committed Apr 6, 2016
2 parents 2b25b1e + 7eefe4e commit 1d10d81
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 21 deletions.
16 changes: 0 additions & 16 deletions container/lxd/lxd.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ package lxd

import (
"fmt"
"os"

"github.com/juju/errors"
"github.com/juju/loggo"
Expand Down Expand Up @@ -268,18 +267,3 @@ func (manager *containerManager) createNetworkProfile(profile string, networkCon

return nil
}

// GetDefaultBridgeName returns the name of the default bridge for lxd.
func GetDefaultBridgeName() (string, error) {
_, err := os.Lstat("/sys/class/net/lxdbr0/bridge")
if err == nil {
return "lxdbr0", nil
}

/* if it was some unknown error, return that */
if !os.IsNotExist(err) {
return "", err
}

return "lxcbr0", nil
}
7 changes: 4 additions & 3 deletions tools/lxdclient/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import (
"github.com/juju/errors"
"github.com/juju/utils"
lxdshared "github.com/lxc/lxd/shared"

"github.com/juju/juju/container/lxc"
)

const (
Expand Down Expand Up @@ -192,7 +190,10 @@ func (r Remote) UsingTCP() (Remote, error) {
// TODO: jam 2016-02-25 This should be updated for systems that are
// space aware, as we may not be just using the default LXC
// bridge.
netIF := lxc.DefaultLxcBridge
netIF, err := GetDefaultBridgeName()
if err != nil {
return r, errors.Trace(err)
}
addr, err := utils.GetAddressForInterface(netIF)
if err != nil {
return r, errors.Trace(err)
Expand Down
16 changes: 16 additions & 0 deletions tools/lxdclient/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package lxdclient

import (
"bytes"
"os"

"github.com/juju/errors"
"github.com/juju/utils/series"
Expand Down Expand Up @@ -60,3 +61,18 @@ func IsRunningLocally() (bool, error) {

return running, nil
}

// GetDefaultBridgeName returns the name of the default bridge for lxd.
func GetDefaultBridgeName() (string, error) {
_, err := os.Lstat("/sys/class/net/lxdbr0/bridge")
if err == nil {
return "lxdbr0", nil
}

/* if it was some unknown error, return that */
if !os.IsNotExist(err) {
return "", err
}

return "lxcbr0", nil
}
11 changes: 11 additions & 0 deletions tools/lxdclient/utils_go12.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright 2016 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.

// +build !go1.3

package lxdclient

func GetDefaultBridgeName() (string, error) {
/* lxd not supported in go1.2 */
return "lxcbr0", nil
}
5 changes: 3 additions & 2 deletions worker/provisioner/lxd-broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/juju/juju/container/lxd"
"github.com/juju/juju/environs"
"github.com/juju/juju/instance"
"github.com/juju/juju/tools/lxdclient"
)

var lxdLogger = loggo.GetLogger("juju.provisioner.lxd")
Expand Down Expand Up @@ -56,7 +57,7 @@ func (broker *lxdBroker) StartInstance(args environs.StartInstanceParams) (*envi
bridgeDevice := broker.agentConfig.Value(agent.LxcBridge)
if bridgeDevice == "" {
var err error
bridgeDevice, err = lxd.GetDefaultBridgeName()
bridgeDevice, err = lxdclient.GetDefaultBridgeName()
if err != nil {
return nil, errors.Trace(err)
}
Expand Down Expand Up @@ -150,7 +151,7 @@ func (broker *lxdBroker) MaintainInstance(args environs.StartInstanceParams) err
bridgeDevice := broker.agentConfig.Value(agent.LxdBridge)
if bridgeDevice == "" {
var err error
bridgeDevice, err = lxd.GetDefaultBridgeName()
bridgeDevice, err = lxdclient.GetDefaultBridgeName()
if err != nil {
return err
}
Expand Down

0 comments on commit 1d10d81

Please sign in to comment.