Пример #1
0
func controllerMain(c *cli.Context) {
	if len(c.Args()) < 2 || c.Args().First() == "help" {
		cli.ShowCommandHelpAndExit(c, "controller", 1) // last argument is exit code
	}
	if c.Args().First() == "get" {
		newArgs := c.Args().Tail()
		switch newArgs.First() {
		case "mem":
			memstats, err := controller.GetMemStats(newArgs.Tail().First())
			if err != nil {
				Fatalln(err)
			}
			Println(string(memstats))
		case "sysinfo":
			sysinfo, err := controller.GetSysInfo(newArgs.Tail().First())
			if err != nil {
				Fatalln(err)
			}
			Println(string(sysinfo))
		case "auth":
			keys, err := controller.GetAuthKeys(newArgs.Tail().First())
			if err != nil {
				Fatalln(err)
			}
			Println(string(keys))
		}
	}
	if c.Args().First() == "set" {
		Fatalln("Not supported yet")
	}
}
Пример #2
0
func runController(c *cli.Context) {
	if len(c.Args()) < 2 || c.Args().First() == "help" {
		cli.ShowCommandHelpAndExit(c, "controller", 1) // last argument is exit code
	}
	switch c.Args().First() {
	case "mem":
		memstats, err := controller.GetMemStats(c.Args().Tail().First())
		if err != nil {
			Fatalln(err)
		}
		Println(string(memstats))
	case "sysinfo":
		sysinfo, err := controller.GetSysInfo(c.Args().Tail().First())
		if err != nil {
			Fatalln(err)
		}
		Println(string(sysinfo))
	case "auth":
		keys, err := controller.GetAuthKeys(c.Args().Tail().First())
		if err != nil {
			Fatalln(err)
		}
		Println(string(keys))
	}
}
Пример #3
0
func runController(c *cli.Context) {
	_, err := user.Current()
	if err != nil {
		Fatalf("Unable to determine current user. Reason: %s\n", err)
	}
	if len(c.Args()) < 2 || c.Args().First() == "help" {
		cli.ShowCommandHelpAndExit(c, "controller", 1) // last argument is exit code
	}
	switch c.Args().First() {
	case "disks":
		disks, err := controller.GetDisks(c.Args().Tail().First())
		if err != nil {
			Fatalln(err)
		}
		Println(disks)
	case "mem":
		memstats, err := controller.GetMemStats(c.Args().Tail().First())
		if err != nil {
			Fatalln(err)
		}
		Println(string(memstats))
	case "sysinfo":
		sysinfo, err := controller.GetSysInfo(c.Args().Tail().First())
		if err != nil {
			Fatalln(err)
		}
		Println(string(sysinfo))
	case "auth":
		keys, err := controller.GetAuthKeys(c.Args().Tail().First())
		if err != nil {
			Fatalln(err)
		}
		Println(string(keys))
	case "donut":
		if len(c.Args()) <= 2 || c.Args().First() == "help" {
			cli.ShowCommandHelpAndExit(c, "controller", 1) // last argument is exit code
		}
		hostname, _ := os.Hostname()
		err := controller.SetDonut(c.Args().Tail().First(), hostname, c.Args().Tail().Tail())
		if err != nil {
			Fatalln(err)
		}
	}
}