Skip to content

Commit

Permalink
move plugin network creation into weaveutil
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rade committed Jan 15, 2016
1 parent 9578798 commit e2a2842
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 33 deletions.
29 changes: 0 additions & 29 deletions prog/plugin/main.go
Expand Up @@ -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"
Expand All @@ -25,7 +23,6 @@ func main() {
nameserver string
meshAddress string
logLevel string
meshNetworkName string
noMulticastRoute bool
)

Expand All @@ -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()
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 change: 1 addition & 0 deletions prog/weaveutil/main.go
Expand Up @@ -16,6 +16,7 @@ func init() {
"create-datapath": createDatapath,
"delete-datapath": deleteDatapath,
"add-datapath-interface": addDatapathInterface,
"create-plugin-network": createPluginNetwork,
"remove-plugin-network": removePluginNetwork,
}
}
Expand Down
31 changes: 31 additions & 0 deletions prog/weaveutil/plugin_network.go
Expand Up @@ -7,6 +7,37 @@ 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>")
Expand Down
2 changes: 0 additions & 2 deletions site/plugin.md
Expand Up @@ -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

Expand Down
7 changes: 5 additions & 2 deletions weave
Expand Up @@ -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() {
Expand Down

0 comments on commit e2a2842

Please sign in to comment.