Add weaveutil process-addrs
Fetches addresses for every veth that is in a network namespace and attached to the specified bridge. Works by iterating over every process.
This commit is contained in:
1 parent
71491138aa
commit
50a8dc1383
2 files changed
+41
No files matched your search
@@ -20,6 +20,7 @@ func init() {
|
|||||||
"create-plugin-network": createPluginNetwork,
|
"create-plugin-network": createPluginNetwork,
|
||||||
"remove-plugin-network": removePluginNetwork,
|
"remove-plugin-network": removePluginNetwork,
|
||||||
"container-addrs": containerAddrs,
|
"container-addrs": containerAddrs,
|
||||||
|
"process-addrs": processAddrs,
|
||||||
"attach-container": attach,
|
"attach-container": attach,
|
||||||
"detach-container": detach,
|
"detach-container": detach,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,40 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
"github.com/weaveworks/weave/common"
|
||||||
|
weavenet "github.com/weaveworks/weave/net"
|
||||||
|
)
|
||||||
|
|
||||||
|
func processAddrs(args []string) error {
|
||||||
|
if len(args) < 1 {
|
||||||
|
cmdUsage("process-addrs", "<bridgeName>")
|
||||||
|
}
|
||||||
|
bridgeName := args[0]
|
||||||
|
|
||||||
|
pred, err := common.ConnectedToBridgePredicate(bridgeName)
|
||||||
|
if err != nil {
|
||||||
|
if err == weavenet.ErrLinkNotFound {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
pids, err := common.AllPids("/proc")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// NB: Because network namespaces (netns) are changed many times inside the loop,
|
||||||
|
// it's NOT safe to exec any code depending on the root netns without
|
||||||
|
// wrapping with WithNetNS*.
|
||||||
|
for _, pid := range pids {
|
||||||
|
netDevs, err := common.GetNetDevsWithPredicate(pid, pred)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
printNetDevs(strconv.Itoa(pid), netDevs)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
Reference in new issue
Block a user