Move plugin network creation from shell script to Go
In the process, use the default subnet instead of the whole IP allocation range.
This commit is contained in:
1 parent
eab5ec206a
commit
d2cbb2749e
6 files changed
+34
-60
No files matched your search
@@ -431,6 +431,12 @@ func main() {
|
||||
if enablePlugin || enablePluginV2 {
|
||||
go plugin.Start(httpAddr, dockerCli, pluginSocket, pluginMeshSocket, !noDNS, enablePluginV2)
|
||||
}
|
||||
if enablePlugin {
|
||||
Log.Println("Creating default 'weave' network")
|
||||
options := map[string]interface{}{plugin.MulticastOption: "true"}
|
||||
// TODO: the driver name should be extracted from pluginMeshSocket
|
||||
dockerCli.EnsureNetwork("weave", "weavemesh", defaultSubnet.String(), options)
|
||||
}
|
||||
|
||||
if bridgeConfig.AWSVPC {
|
||||
// Run this on its own goroutine because the allocator can block
|
||||
|
||||
@@ -23,7 +23,6 @@ func init() {
|
||||
"delete-datapath": deleteDatapath,
|
||||
"check-datapath": checkDatapath,
|
||||
"add-datapath-interface": addDatapathInterface,
|
||||
"create-plugin-network": createPluginNetwork,
|
||||
"remove-plugin-network": removePluginNetwork,
|
||||
"container-addrs": containerAddrs,
|
||||
"process-addrs": processAddrs,
|
||||
|
||||
@@ -7,44 +7,8 @@ import (
|
||||
|
||||
"github.com/docker/docker/client"
|
||||
docker "github.com/fsouza/go-dockerclient"
|
||||
|
||||
"github.com/weaveworks/weave/plugin/net"
|
||||
)
|
||||
|
||||
func createPluginNetwork(args []string) error {
|
||||
if len(args) != 3 {
|
||||
cmdUsage("create-plugin-network", "<network-name> <driver-name> <default-subnet>")
|
||||
}
|
||||
networkName := args[0]
|
||||
driverName := args[1]
|
||||
subnet := args[2]
|
||||
d, err := newDockerClient()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = d.CreateNetwork(
|
||||
docker.CreateNetworkOptions{
|
||||
Name: networkName,
|
||||
CheckDuplicate: true,
|
||||
Driver: driverName,
|
||||
IPAM: docker.IPAMOptions{
|
||||
Driver: driverName,
|
||||
Config: []docker.IPAMConfig{{Subnet: subnet}},
|
||||
},
|
||||
Options: map[string]interface{}{plugin.MulticastOption: "true"},
|
||||
})
|
||||
if err != docker.ErrNetworkAlreadyExists && err != nil {
|
||||
// Despite appearances to the contrary, CreateNetwork does
|
||||
// sometimes(always?) *not* return ErrNetworkAlreadyExists
|
||||
// when the network already exists. Hence we need to check for
|
||||
// this explicitly.
|
||||
if _, err2 := d.NetworkInfo(networkName); err2 != nil {
|
||||
return fmt.Errorf("unable to create network: %s", err)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func removePluginNetwork(args []string) error {
|
||||
if len(args) != 1 {
|
||||
cmdUsage("remove-plugin-network", "<network-name>")
|
||||
|
||||
Reference in new issue
Block a user