This repository has been archived by the owner on Jun 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 665
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1847 from weaveworks/1613-weaveutil
extract script utilities into single binary; LGTM
- Loading branch information
Showing
10 changed files
with
161 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* weaveutil: collection of operations required by weave script */ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
) | ||
|
||
var commands map[string]func([]string) error | ||
|
||
func init() { | ||
commands = map[string]func([]string) error{ | ||
"help": help, | ||
"netcheck": netcheck, | ||
"docker-tls-args": dockerTLSArgs, | ||
"create-datapath": createDatapath, | ||
"delete-datapath": deleteDatapath, | ||
"add-datapath-interface": addDatapathInterface, | ||
} | ||
} | ||
|
||
func main() { | ||
if len(os.Args) < 2 { | ||
usage() | ||
os.Exit(1) | ||
} | ||
cmd, found := commands[os.Args[1]] | ||
if !found { | ||
usage() | ||
os.Exit(1) | ||
} | ||
if err := cmd(os.Args[2:]); err != nil { | ||
fmt.Fprintln(os.Stderr, err) | ||
os.Exit(1) | ||
} | ||
} | ||
|
||
func help(args []string) error { | ||
if len(args) > 0 { | ||
cmdUsage("help", "") | ||
} | ||
usage() | ||
return nil | ||
} | ||
|
||
func usage() { | ||
fmt.Fprintln(os.Stderr, "usage: weaveutil <command> <arg>...") | ||
fmt.Fprintln(os.Stderr) | ||
fmt.Fprintln(os.Stderr, "where <command> is one of:") | ||
fmt.Fprintln(os.Stderr) | ||
for cmd := range commands { | ||
fmt.Fprintln(os.Stderr, cmd) | ||
} | ||
} | ||
|
||
func cmdUsage(cmd string, usage string) { | ||
fmt.Fprintf(os.Stderr, "usage: weaveutil %s %s\n", cmd, usage) | ||
os.Exit(1) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* netcheck: check whether a given network or address overlaps with any existing routes */ | ||
package main | ||
|
||
import ( | ||
"net" | ||
|
||
weavenet "github.com/weaveworks/weave/net" | ||
) | ||
|
||
func netcheck(args []string) error { | ||
if len(args) < 1 { | ||
cmdUsage("netcheck", "<cidr> [<interface-to-ignore> ...]") | ||
} | ||
addr, ipnet, err := net.ParseCIDR(args[0]) | ||
if err != nil { | ||
return err | ||
} | ||
ignoreIfaceNames := make(map[string]struct{}) | ||
for _, ifName := range args[1:] { | ||
ignoreIfaceNames[ifName] = struct{}{} | ||
} | ||
if ipnet.IP.Equal(addr) { | ||
err = weavenet.CheckNetworkFree(ipnet, ignoreIfaceNames) | ||
} else { | ||
err = weavenet.CheckAddressOverlap(addr, ignoreIfaceNames) | ||
} | ||
return err | ||
} |
Oops, something went wrong.