示例#1
0
文件: govm.go 项目: arbrix/govm
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
}
示例#2
0
文件: main.go 项目: hmahmood/govmomi
func main() {
	os.Exit(cli.Run(os.Args[1:]))
}