Merge pull request #1944 from weaveworks/issues/1940-remove-proxy-weaveps-dep
Use netlink instead of shelling out to `weave ps`
This commit is contained in:
commit
1d3c80ab49
10 files changed
+183
-64
No files matched your search
@@ -14,6 +14,7 @@ import (
|
||||
var (
|
||||
version = "(unreleased version)"
|
||||
defaultDockerHost = "unix:///var/run/docker.sock"
|
||||
defaultProcPath = "/proc"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@@ -68,6 +69,11 @@ func main() {
|
||||
c.DockerHost = dockerHost
|
||||
}
|
||||
|
||||
c.ProcPath = defaultProcPath
|
||||
if procPath := os.Getenv("PROCFS"); procPath != "" {
|
||||
c.ProcPath = procPath
|
||||
}
|
||||
|
||||
p, err := proxy.NewProxy(c)
|
||||
if err != nil {
|
||||
Log.Fatalf("Could not start proxy: %s", err)
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/fsouza/go-dockerclient"
|
||||
"github.com/weaveworks/weave/common"
|
||||
)
|
||||
|
||||
func containerAddrs(args []string) error {
|
||||
if len(args) < 2 {
|
||||
cmdUsage("container-addrs", "<procPath> <bridgeName> [containerID ...]")
|
||||
}
|
||||
|
||||
procPath := args[0]
|
||||
bridgeName := args[1]
|
||||
|
||||
c, err := docker.NewVersionedClientFromEnv("1.18")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, containerID := range args[2:] {
|
||||
netDevs, err := getNetDevs(procPath, bridgeName, c, containerID)
|
||||
if err != nil {
|
||||
if _, ok := err.(*docker.NoSuchContainer); ok {
|
||||
continue
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
for _, netDev := range netDevs {
|
||||
fmt.Printf("%12s %s", containerID, netDev.MAC.String())
|
||||
for _, cidr := range netDev.CIDRs {
|
||||
prefixLength, _ := cidr.Mask.Size()
|
||||
fmt.Printf(" %v/%v", cidr.IP, prefixLength)
|
||||
}
|
||||
fmt.Println()
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func getNetDevs(procPath, bridgeName string, c *docker.Client, containerID string) ([]common.NetDev, error) {
|
||||
if containerID == "weave:expose" {
|
||||
return common.GetBridgeNetDev(procPath, bridgeName)
|
||||
}
|
||||
|
||||
container, err := c.InspectContainer(containerID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return common.GetWeaveNetDevs(procPath, container.State.Pid)
|
||||
}
|
||||
@@ -18,6 +18,7 @@ func init() {
|
||||
"add-datapath-interface": addDatapathInterface,
|
||||
"create-plugin-network": createPluginNetwork,
|
||||
"remove-plugin-network": removePluginNetwork,
|
||||
"container-addrs": containerAddrs,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user