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 672
/
main.go
98 lines (88 loc) · 2.35 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/* weaveutil: collection of operations required by weave script */
package main
import (
"fmt"
"os"
"path/filepath"
"strings"
weavenet "github.com/weaveworks/weave/net"
)
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,
"check-datapath": checkDatapath,
"add-datapath-interface": addDatapathInterface,
"create-plugin-network": createPluginNetwork,
"remove-plugin-network": removePluginNetwork,
"container-addrs": containerAddrs,
"process-addrs": processAddrs,
"attach-container": attach,
"detach-container": detach,
"configure-arp": configureARP,
"check-iface": checkIface,
"del-iface": delIface,
"setup-iface": setupIface,
"list-netdevs": listNetDevs,
"cni-net": cniNet,
"cni-ipam": cniIPAM,
"expose-nat": exposeNAT,
"bridge-ip": bridgeIP,
"unique-id": uniqueID,
}
}
func main() {
// force re-exec of this binary
selfPath, err := filepath.EvalSymlinks("/proc/self/exe")
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
weavenet.WeaveUtilCmd = selfPath
// If no args passed, act as CNI plugin based on executable name
switch {
case len(os.Args) == 1 && strings.HasSuffix(os.Args[0], "weave-ipam"):
cniIPAM(os.Args)
os.Exit(0)
case len(os.Args) == 1 && strings.HasSuffix(os.Args[0], "weave-net"):
cniNet(os.Args)
os.Exit(0)
}
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)
}