Beispiel #1
0
func (a *App) handleListVm(ctx *echo.Context) error {
	//get data from Stdout
	rescueStdout := os.Stdout
	r, w, _ := os.Pipe()
	os.Stdout = w

	res := cli.Run([]string{"ls", a.vmPath})

	w.Close()
	out, _ := ioutil.ReadAll(r)
	os.Stdout = rescueStdout
	if res != 0 {
		return fmt.Errorf("%s (%d)", out, res)
	}
	log.Printf("get by api: %s\n", out)
	vms := []string{}
	for _, vmAlias := range strings.Split(string(out), "\n") {
		if len(vmAlias) > len(a.vmPath) {
			vms = append(vms, vmAlias[len(a.vmPath):])
		}
	}
	replyJson(ctx, vms)
	return nil
}
Beispiel #2
0
func main() {
	os.Exit(cli.Run(os.Args[1:]))
}