move fastdp helpers into weaveutil

so the weave script can invoke them w/o having to run a container
This commit is contained in:
Matthias Radestock committed 2016-01-02 14:00:44 +00:00
1 parent 4ebcd355f6
commit 419f2ff71b
4 files changed
+53 -42

No files matched your search

+2 -37
View File
@@ -16,7 +16,6 @@ import (
. "github.com/weaveworks/weave/common"
"github.com/weaveworks/weave/common/docker"
"github.com/weaveworks/weave/common/odp"
"github.com/weaveworks/weave/ipam"
"github.com/weaveworks/weave/mesh"
"github.com/weaveworks/weave/nameserver"
@@ -37,12 +36,7 @@ func main() {
runtime.GOMAXPROCS(procs)
var (
// flags that cause immediate exit
justVersion bool
createDatapath bool
deleteDatapath bool
addDatapathInterface string
justVersion bool
config mesh.Config
networkConfig weave.NetworkConfig
protocolMinVersion int
@@ -79,10 +73,6 @@ func main() {
}
mflag.BoolVar(&justVersion, []string{"#version", "-version"}, false, "print version and exit")
mflag.BoolVar(&createDatapath, []string{"-create-datapath"}, false, "create ODP datapath and exit")
mflag.BoolVar(&deleteDatapath, []string{"-delete-datapath"}, false, "delete ODP datapath and exit")
mflag.StringVar(&addDatapathInterface, []string{"-add-datapath-iface"}, "", "add a network interface to the ODP datapath and exit")
mflag.IntVar(&config.Port, []string{"#port", "-port"}, mesh.Port, "router port")
mflag.IntVar(&protocolMinVersion, []string{"-min-protocol-version"}, mesh.ProtocolMinVersion, "minimum weave protocol version")
mflag.StringVar(&ifaceName, []string{"#iface", "-iface"}, "", "name of interface to capture/inject from (disabled if blank)")
@@ -124,34 +114,9 @@ func main() {
SetLogLevel(logLevel)
switch {
case justVersion:
if justVersion {
fmt.Printf("weave router %s\n", version)
os.Exit(0)
case createDatapath:
odpSupported, err := odp.CreateDatapath(datapathName)
if !odpSupported {
if err != nil {
Log.Error(err)
}
// When the kernel lacks ODP support, exit
// with a special status to distinguish it for
// the weave script.
os.Exit(17)
}
checkFatal(err)
os.Exit(0)
case deleteDatapath:
checkFatal(odp.DeleteDatapath(datapathName))
os.Exit(0)
case addDatapathInterface != "":
checkFatal(odp.AddDatapathInterface(datapathName, addDatapathInterface))
os.Exit(0)
}
Log.Println("Command line options:", options())
+39
View File
@@ -0,0 +1,39 @@
// various fastdp operations
package main
import (
"fmt"
"os"
"github.com/weaveworks/weave/common/odp"
)
func createDatapath(args []string) error {
if len(args) != 1 {
cmdUsage("create-datapath", "<datapath>")
}
odpSupported, err := odp.CreateDatapath(args[0])
if !odpSupported {
if err != nil {
fmt.Fprintln(os.Stderr, err)
}
// When the kernel lacks ODP support, exit with a special
// status to distinguish it for the weave script.
os.Exit(17)
}
return err
}
func deleteDatapath(args []string) error {
if len(args) != 1 {
cmdUsage("delete-datapath", "<datapath>")
}
return odp.DeleteDatapath(args[0])
}
func addDatapathInterface(args []string) error {
if len(args) != 2 {
cmdUsage("add-datapath-interface", "<datapath> <interface>")
}
return odp.AddDatapathInterface(args[0], args[1])
}
+6 -3
View File
@@ -10,9 +10,12 @@ var commands map[string]func([]string) error
func init() {
commands = map[string]func([]string) error{
"help": help,
"netcheck": netcheck,
"docker-tls-args": dockerTLSArgs,
"help": help,
"netcheck": netcheck,
"docker-tls-args": dockerTLSArgs,
"create-datapath": createDatapath,
"delete-datapath": deleteDatapath,
"add-datapath-interface": addDatapathInterface,
}
}
+6 -2
View File
@@ -445,7 +445,11 @@ random_mac() {
######################################################################
fastdp_op() {
docker run --rm --privileged --net=host $IMAGE $COVERAGE_ARGS --$1 --datapath=$2
if command_exists weaveutil ; then
weaveutil "$@"
else
docker run --rm --privileged --net=host --entrypoint=/usr/bin/weaveutil $EXEC_IMAGE "$@"
fi
}
# Detect the current bridge/datapath state. When invoked, the values of
@@ -764,7 +768,7 @@ connect_container_to_bridge() {
}
add_iface_fastdp() {
fastdp_op add-datapath-iface=$1 $DATAPATH
fastdp_op add-datapath-interface $DATAPATH $1
}
add_iface_bridge() {