func setup_network(host client.Anchor, id int) bool { // ids ip_base := "10.0.0." + strconv.Itoa(id) eth0 := "eth0" eth00 := "eth0.1" br0 := "br_poc" tap0 := "tap_poc" orquit := " || exit 1" // commands commands := []string{} commands = append(commands, "ip link add link "+eth0+" "+eth00+" type vlan id 1") commands = append(commands, "ip link set "+eth00+" up") commands = append(commands, "brctl addbr "+br0) commands = append(commands, "ip link set "+br0+" up") commands = append(commands, "ip addr add "+ip_base+"/24 dev "+br0) commands = append(commands, "ip tuntap add dev "+tap0+" mode tap multi_queue") commands = append(commands, "ip link set "+tap0+" up") commands = append(commands, "brctl addif "+br0+" "+tap0+" "+eth00) for _, v := range commands { cmd := v + orquit _, err := runShell(host, cmd) debug("[%s] "+cmd, host.ServerID()) if err != nil { debug("[%s] %s ", host.ServerID(), err) } } return false }
func check_prereqs(host client.Anchor, ps []string) (ret bool) { ret = false for _, v := range ps { out, err := runShell(host, "which "+v) if err != nil || len(out) == 0 { debug("[%s] missing prereq %s ", host.ServerID(), v) ret = true } } return }
func start_server(host client.Anchor, id int) bool { debug("[%s] starting server ", host.ServerID()) job := host.Walk([]string{"iperf", "server"}) proc, _ := job.MakeProc(client.Cmd{ Path: "/bin/sh", Dir: "/tmp", Args: []string{"-c", "iperf -s"}, Scrub: true, }) phase := proc.Peek().Phase debug("[%s] iperf server "+phase, host.ServerID()) go func() { debug("TEST OUTPUT START:") for { if b, err := ioutil.ReadAll(proc.Stdout()); err == nil { debug("out[%s]", string(b)) } } }() io.Copy(proc.Stdin(), bytes.NewBufferString("\r\n")) proc.Stdin().Close() // Must close the standard input of the shell process. return false }
func runShellStdin(host client.Anchor, cmd, stdin string) (string, error) { defer func() { if recover() != nil { abort("connection to host lost") } }() job := host.Walk([]string{"shelljob", strconv.Itoa(rand.Int())}) proc, _ := job.MakeProc(client.Cmd{ Path: "/bin/sh", Dir: "/tmp", Args: []string{"-c", cmd}, Scrub: true, }) go func() { io.Copy(proc.Stdin(), bytes.NewBufferString(stdin)) proc.Stdin().Close() // Must close the standard input of the shell process. }() proc.Stderr().Close() // Close to indicate discarding standard error var buf bytes.Buffer io.Copy(&buf, proc.Stdout()) stat, _ := proc.Wait() return buf.String(), stat.Exit }