func subnetsDel(cmd *cobra.Command, args []string) { c := cli.NewClient(server) if len(args) == 0 { args = cli.Read(os.Stdin) } if len(args)%2 != 0 { log.WithField("num", len(args)).Fatal("expected an even amount of args") } for i := 0; i < len(args); i += 2 { hv := args[i] cli.AssertID(hv) subnet := args[i+1] cli.AssertID(subnet) deleted := deleteSubnet(c, hv, subnet) deleted.Print(jsonout) } }
func job(cmd *cobra.Command, ids []string) { c := cli.NewClient(server) if len(ids) == 0 { ids = cli.Read(os.Stdin) } for _, id := range ids { cli.AssertID(id) job := getJob(c, id) job.Print(jsonout) } }
func del(cmd *cobra.Command, ids []string) { c := cli.NewClient(server) if len(ids) == 0 { ids = cli.Read(os.Stdin) } for _, id := range ids { cli.AssertID(id) j := deleteGuest(c, id) j.Print(jsonout) } }
func del(cmd *cobra.Command, ids []string) { c := cli.NewClient(getServerURL()) if len(ids) == 0 { ids = cli.Read(os.Stdin) } for _, id := range ids { cli.AssertID(id) image, _ := c.Delete("image", "images/"+id) cli.JMap(image).Print(jsonout) } }
func generateActionHandler(action string) func(*cobra.Command, []string) { return func(cmd *cobra.Command, ids []string) { c := cli.NewClient(server) if len(ids) == 0 { ids = cli.Read(os.Stdin) } for _, id := range ids { cli.AssertID(id) j := guestAction(c, id, action) j.Print(jsonout) } } }
func modify(cmd *cobra.Command, args []string) { c := cli.NewClient(server) if len(args) == 0 { args = cli.Read(os.Stdin) } if len(args)%2 != 0 { log.WithField("num", len(args)).Fatal("expected an even number of args") } for i := 0; i < len(args); i += 2 { id := args[i] cli.AssertID(id) spec := args[i+1] cli.AssertSpec(spec) guest := modifyGuest(c, id, spec) guest.Print(jsonout) } }
func subnetsModify(cmd *cobra.Command, args []string) { c := cli.NewClient(server) if len(args) == 0 { args = cli.Read(os.Stdin) } if len(args)%2 != 0 { log.WithField("num", len(args)).Fatal("expected an even amount of args") } for i := 0; i < len(args); i += 2 { id := args[i] cli.AssertID(id) spec := args[i+1] cli.AssertSpec(spec) subnet := modifySubnets(c, id, spec) printTreeMap(id, "subnet", subnet) } }
func list(cmd *cobra.Command, args []string) { c := cli.NewClient(server) guests := []cli.JMap{} if len(args) == 0 { if termutil.Isatty(os.Stdin.Fd()) { guests = getGuests(c) sort.Sort(cli.JMapSlice(guests)) } else { args = cli.Read(os.Stdin) } } if len(guests) == 0 { for _, id := range args { cli.AssertID(id) guests = append(guests, getGuest(c, id)) } } for _, guest := range guests { guest.Print(jsonout) } }
func subnets(cmd *cobra.Command, ids []string) { c := cli.NewClient(server) if len(ids) == 0 { if termutil.Isatty(os.Stdin.Fd()) { for _, hv := range getHVs(c) { ids = append(ids, hv["id"].(string)) } } else { ids = cli.Read(os.Stdin) sort.Strings(ids) } } else { for _, id := range ids { cli.AssertID(id) } } for _, id := range ids { subnet, _ := c.Get("subnet", "hypervisors/"+id+"/subnets") printTreeMap(id, "subnet", subnet) } }
func guests(cmd *cobra.Command, ids []string) { c := cli.NewClient(server) if len(ids) == 0 { if termutil.Isatty(os.Stdin.Fd()) { for _, hv := range getHVs(c) { ids = append(ids, hv["id"].(string)) } } else { ids = cli.Read(os.Stdin) sort.Strings(ids) } } else { for _, id := range ids { cli.AssertID(id) } } for _, id := range ids { guests := getGuests(c, id) printTreeSlice(id, "guests", guests) } }
func list(cmd *cobra.Command, args []string) { c := cli.NewClient(server) hvs := []cli.JMap{} if len(args) == 0 { if termutil.Isatty(os.Stdin.Fd()) { hvs = getHVs(c) sort.Sort(cli.JMapSlice(hvs)) } else { args = cli.Read(os.Stdin) } } if len(hvs) == 0 { for _, id := range args { cli.AssertID(id) hvs = append(hvs, getHV(c, id)) } } for _, hv := range hvs { hv.Print(jsonout) } }
func list(cmd *cobra.Command, args []string) { c := cli.NewClient(getServerURL()) images := []cli.JMap{} if len(args) == 0 { if termutil.Isatty(os.Stdin.Fd()) { images = getImages(c) sort.Sort(cli.JMapSlice(images)) } else { args = cli.Read(os.Stdin) } } if len(images) == 0 { for _, id := range args { cli.AssertID(id) image, _ := c.Get("image", "images/"+id) images = append(images, image) } } for _, image := range images { image.Print(jsonout) } }