示例#1
0
文件: main.go 项目: jmcadden/farmer
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
}
示例#2
0
文件: main.go 项目: jmcadden/farmer
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
}
示例#3
0
文件: main.go 项目: jmcadden/farmer
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
}