Nets map[string]*Net
Nodes map[string]*Node
Links []*Link
+ Cmds []string
}
type Net struct {
case "link":
usage = `"link" <node> <node> <net-name>`
err = parseConfigLink(&cfg, xs[1:])
+ case "cmd":
+ usage = `"cmd" <string-passed-to-sh-c>`
+ err = parseConfigCmd(&cfg, xs[1:])
default:
- usage = `"net" | "node" | "link"`
+ usage = `"net" | "node" | "link" | "cmd"`
err = fmt.Errorf("unknown option %q", xs[0])
}
if err != nil {
return nil
}
+func parseConfigCmd(cfg *Config, args []string) error {
+ if len(args) < 1 {
+ return fmt.Errorf("not enough arguments")
+ }
+
+ cfg.Cmds = append(cfg.Cmds, strings.Join(args, " "))
+ return nil
+}
+
// vi: set noet ts=4 sw=4 sts=4:
ip("-n", nsa, "link", "set", la, "up")
ip("-n", nsb, "link", "set", lb, "up")
}
+
+ log.Printf("Starting cmds ...")
+ for _, node := range cfg.Nodes {
+ log.Printf(" For node %q", node.Name)
+ ns := node.Name
+ for _, cmd := range cfg.Cmds {
+ ip("netns", "exec", ns, "sh", "-c", cmd, "argv0", ns)
+ }
+ }
}
func ip(args ...string) {