move plugin network creation into weaveutil

Note that we remove the ability to set the weavemesh network name, or
disabling it altogether. This was always poorly support, since the
removal operation only ever operated on the default name. The option
was also not listed in the usage, though it was in the docs.
This commit is contained in:
Matthias Radestock committed 2016-01-15 08:52:57 +00:00
1 parent 9578798ec0
commit 31b303a419
5 files changed
+36 -33

No files matched your search

-29
View File
@@ -5,10 +5,8 @@ import (
"fmt"
"net"
"os"
"strings"
"github.com/docker/libnetwork/ipamapi"
go_docker "github.com/fsouza/go-dockerclient"
. "github.com/weaveworks/weave/common"
"github.com/weaveworks/weave/common/docker"
ipamplugin "github.com/weaveworks/weave/plugin/ipam"
@@ -25,7 +23,6 @@ func main() {
nameserver string
meshAddress string
logLevel string
meshNetworkName string
noMulticastRoute bool
)
@@ -34,7 +31,6 @@ func main() {
flag.StringVar(&address, "socket", "/run/docker/plugins/weave.sock", "socket on which to listen")
flag.StringVar(&nameserver, "nameserver", "", "nameserver to provide to containers")
flag.StringVar(&meshAddress, "meshsocket", "/run/docker/plugins/weavemesh.sock", "socket on which to listen in mesh mode")
flag.StringVar(&meshNetworkName, "mesh-network-name", "weave", "network name to create in mesh mode")
flag.BoolVar(&noMulticastRoute, "no-multicast-route", false, "do not add a multicast route to network endpoints")
flag.Parse()
@@ -72,10 +68,6 @@ func main() {
defer meshListener.Close()
}
if meshNetworkName != "" {
createNetwork(dockerClient, meshNetworkName, meshAddress)
}
err = <-endChan
if err != nil {
Log.Errorf("Error from listener: %s", err)
@@ -116,24 +108,3 @@ func listenAndServe(dockerClient *docker.Client, address, nameserver string, noM
return listener, nil
}
func createNetwork(dockerClient *docker.Client, networkName, address string) {
if _, err := dockerClient.Client.NetworkInfo(networkName); err == nil {
Log.Printf("Docker network '%s' already exists", networkName)
} else if _, ok := err.(*go_docker.NoSuchNetwork); ok {
driverName := strings.TrimSuffix(address, ".sock")
if i := strings.LastIndex(driverName, "/"); i >= 0 {
driverName = driverName[i+1:]
}
options := go_docker.CreateNetworkOptions{
Name: networkName,
CheckDuplicate: true,
Driver: driverName,
IPAM: go_docker.IPAMOptions{Driver: driverName},
}
_, err := dockerClient.Client.CreateNetwork(options)
if err != nil {
Log.Fatalf("Error creating network: %s", err)
}
}
}
+1
View File
@@ -16,6 +16,7 @@ func init() {
"create-datapath": createDatapath,
"delete-datapath": deleteDatapath,
"add-datapath-interface": addDatapathInterface,
"create-plugin-network": createPluginNetwork,
"remove-plugin-network": removePluginNetwork,
}
}
+30
View File
@@ -7,6 +7,36 @@ import (
"github.com/fsouza/go-dockerclient"
)
func createPluginNetwork(args []string) error {
if len(args) != 2 {
cmdUsage("create-plugin-network", "<network-name> <driver-name>")
}
networkName := args[0]
driverName := args[1]
d, err := newDockerClient()
if err != nil {
return err
}
_, err = d.NetworkInfo(networkName)
if err == nil {
return nil
}
if _, ok := err.(*docker.NoSuchNetwork); !ok {
return nil // TODO is this right?
}
_, err = d.CreateNetwork(
docker.CreateNetworkOptions{
Name: networkName,
CheckDuplicate: true,
Driver: driverName,
IPAM: docker.IPAMOptions{Driver: driverName},
})
if err != 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>")
-2
View File
@@ -73,8 +73,6 @@ The plugin command-line arguments are:
* `--log-level=debug|info|warning|error`, which tells the plugin
how much information to emit for debugging.
* `--mesh-network-name=<name>`: set it to blank to disable creation
of a default network, or a name of your own choice.
* `--no-multicast-route`: stop weave adding a static IP route for
multicast traffic on its interface
+5 -2
View File
@@ -1683,12 +1683,15 @@ launch_plugin_if_not_running() {
# Any other kind of error code from check_not_running is a failure.
[ $retval -gt 0 ] && return $retval
PLUGIN_CONTAINER=$(docker run --privileged -d --name=$PLUGIN_CONTAINER_NAME \
if ! PLUGIN_CONTAINER=$(docker run --privileged -d --name=$PLUGIN_CONTAINER_NAME \
--restart=always \
--net=host \
$(docker_sock_options) \
-v /run/docker/plugins:/run/docker/plugins \
$PLUGIN_IMAGE "$@")
$PLUGIN_IMAGE "$@") ; then
return 1
fi
util_op create-plugin-network weave weavemesh
}
plugin_disabled() {