Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow us to check additional networks on native when the default is used #447

Merged
merged 1 commit into from
May 18, 2017
Merged
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
55 changes: 54 additions & 1 deletion util/provider/native.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,65 @@ func (native Native) Start() error {
if !native.hasNetwork() {
display.StartTask("Setting up custom docker network...")

config, _ := models.LoadConfig()
config, err := models.LoadConfig()
if err != nil {
return err
}

// if we are using the default network configuration
// then we are free to try getting one that works without confirming with the user any changes
if config.NativeNetworkSpace == "172.20.0.1/16" {
// create the values we will need outside the loop
var oct int
var newNetSpace string

for i := 0; i < 10; i++ {
// get the value of the 2nd octet and use I to increment it
// to allow different networks to be used
fmt.Sscanf(config.NativeNetworkSpace, "172.%d.0.1/16", &oct)
newNetSpace = fmt.Sprintf("172.%d.0.1/16", oct + i)

ip, ipNet, err := net.ParseCIDR(newNetSpace)
if err != nil {
return err
}

cmd := exec.Command("docker", "network", "create", "--driver=bridge", fmt.Sprintf("--subnet=%s", ipNet.String()), "--opt=\"com.docker.network.driver.mtu=1450\"", "--opt=\"com.docker.network.bridge.name=redd0\"", fmt.Sprintf("--gateway=%s", ip.String()), "nanobox")

cmd.Stdout = display.NewStreamer(" ")
cmd.Stderr = display.NewStreamer(" ")

err = cmd.Run()

if err == nil {
break
}
}

// if we did all the loops and still have an error. we need to report it
if err != nil {
display.ErrorTask()
display.NetworkCreateError("native-network-space", config.NativeNetworkSpace)
return err
}

// with no errors we will return here
if newNetSpace != config.NativeNetworkSpace {
config.NativeNetworkSpace = newNetSpace
config.Save()
}

display.StopTask()
return nil

}

ip, ipNet, err := net.ParseCIDR(config.NativeNetworkSpace)
if err != nil {
return err
}


cmd := exec.Command("docker", "network", "create", "--driver=bridge", fmt.Sprintf("--subnet=%s", ipNet.String()), "--opt=\"com.docker.network.driver.mtu=1450\"", "--opt=\"com.docker.network.bridge.name=redd0\"", fmt.Sprintf("--gateway=%s", ip.String()), "nanobox")

cmd.Stdout = display.NewStreamer(" ")
Expand Down