Esempio n. 1
0
func cmdAppInfo(c *cli.Context) {
	var app string
	var err error

	if len(c.Args()) > 0 {
		app = c.Args()[0]
	} else {
		_, app, err = stdcli.DirApp(c, ".")
	}

	a, err := rackClient(c).GetApp(app)

	if err != nil {
		stdcli.Error(err)
		return
	}

	formation, err := rackClient(c).ListFormation(app)

	if err != nil {
		stdcli.Error(err)
		return
	}

	ps := make([]string, len(formation))
	ports := []string{}

	for i, f := range formation {
		ps[i] = f.Name

		for _, p := range f.Ports {
			ports = append(ports, fmt.Sprintf("%s:%d", f.Name, p))
		}
	}

	sort.Strings(ps)
	sort.Strings(ports)

	fmt.Printf("Name       %s\n", a.Name)
	fmt.Printf("Status     %s\n", a.Status)
	fmt.Printf("Release    %s\n", stdcli.Default(a.Release, "(none)"))
	fmt.Printf("Processes  %s\n", stdcli.Default(strings.Join(ps, " "), "(none)"))

	if a.Balancer != "" {
		fmt.Printf("Hostname   %s\n", a.Balancer)
		fmt.Printf("Ports      %s\n", stdcli.Default(strings.Join(ports, " "), "(none)"))
	}
}
Esempio n. 2
0
File: apps.go Progetto: convox/rack
func cmdAppInfo(c *cli.Context) error {
	_, app, err := stdcli.DirApp(c, ".")
	if err != nil {
		return stdcli.Error(err)
	}

	if len(c.Args()) > 0 {
		app = c.Args()[0]
	}

	a, err := rackClient(c).GetApp(app)
	if err != nil {
		return stdcli.Error(err)
	}

	formation, err := rackClient(c).ListFormation(app)
	if err != nil {
		return stdcli.Error(err)
	}

	ps := make([]string, len(formation))
	endpoints := []string{}

	for i, f := range formation {
		ps[i] = f.Name

		for _, port := range f.Ports {
			endpoints = append(endpoints, fmt.Sprintf("%s:%d (%s)", f.Balancer, port, f.Name))
		}
	}

	sort.Strings(ps)

	info := stdcli.NewInfo()

	info.Add("Name", a.Name)
	info.Add("Status", a.Status)
	info.Add("Release", stdcli.Default(a.Release, "(none)"))
	info.Add("Processes", stdcli.Default(strings.Join(ps, " "), "(none)"))
	info.Add("Endpoints", strings.Join(endpoints, "\n           "))

	info.Print()

	return nil
}