Beispiel #1
0
func listUnits(cmd *cobra.Command, args []string) {
	t, servers := transportAndHosts(args...)

	data, errors := gcmd.Executor{
		On: servers,
		Group: func(on ...gcmd.Locator) gcmd.JobRequest {
			return &cjobs.ListContainersRequest{}
		},
		Output:    os.Stdout,
		Transport: t,
	}.Gather()

	combined := cjobs.ListServerContainersResponse{}
	for i := range data {
		// if r, ok := data[i].(*cjobs.ListServerContainersResponse); ok {
		// 	combined.Append(&r.ListContainersResponse)
		// } else
		if j, ok := data[i].(*cjobs.ListContainersResponse); ok {
			combined.Append(j)
		}
	}
	combined.Sort()
	combined.WriteTableTo(os.Stdout)
	if len(errors) > 0 {
		for i := range errors {
			fmt.Fprintf(os.Stderr, "Error: %s\n", errors[i])
		}
		os.Exit(1)
	}
	os.Exit(0)
}
Beispiel #2
0
func (ctx *CommandContext) listUnits(c *cobra.Command, args []string) {
	t, servers := ctx.transportAndHosts(args...)

	data, errors := cmd.Executor{
		On: servers,
		Group: func(on ...cmd.Locator) cmd.JobRequest {
			return &cjobs.ListContainersRequest{IncludeInactive: ctx.all}
		},
		Output:    os.Stdout,
		Transport: t,
	}.Gather()

	combined := cjobs.ListServerContainersResponse{}
	for i := range data {
		// if r, ok := data[i].(*cjobs.ListServerContainersResponse); ok {
		// 	combined.Append(&r.ListContainersResponse)
		// } else
		if j, ok := data[i].(*cjobs.ListContainersResponse); ok {
			combined.Append(j)
		}
	}
	combined.Sort()
	if ctx.quiet {
		for i := range combined.Containers {
			c := &combined.Containers[i]
			if c.Server != "" {
				fmt.Fprintf(os.Stdout, "%s/%s\n", c.Server, c.Id)
			} else {
				fmt.Fprintf(os.Stdout, "%s\n", c.Id)
			}
		}
	} else {
		combined.WriteTableTo(os.Stdout)
	}
	if len(errors) > 0 {
		for i := range errors {
			fmt.Fprintf(os.Stderr, "Error: %s\n", errors[i])
		}
		os.Exit(1)
	}
	os.Exit(0)
}