예제 #1
0
func (c AppList) Show(result []byte, context *cmd.Context) error {
	var apps []app
	err := json.Unmarshal(result, &apps)
	if err != nil {
		return err
	}
	table := cmd.NewTable()
	table.Headers = cmd.Row([]string{"Application", "Units State Summary", "Address", "Ready?"})
	for _, app := range apps {
		var startedUnits int
		var total int
		for _, unit := range app.Units {
			if unit.Name != "" {
				total++
				if unit.State == "started" {
					startedUnits += 1
				}
			}
		}
		summary := fmt.Sprintf("%d of %d units in-service", startedUnits, total)
		table.AddRow(cmd.Row([]string{app.Name, summary, app.Addr(), app.IsReady()}))
	}
	table.Sort()
	context.Stdout.Write(table.Bytes())
	return nil
}
func (c ServiceInfo) BuildPlansTable(serviceName string, ctx *cmd.Context, client *cmd.Client) error {
	ctx.Stdout.Write([]byte("\nPlans\n"))
	url, err := cmd.GetURL(fmt.Sprintf("/services/%s/plans", serviceName))
	if err != nil {
		return err
	}
	request, err := http.NewRequest("GET", url, nil)
	if err != nil {
		return err
	}
	resp, err := client.Do(request)
	if err != nil {
		return err
	}
	defer resp.Body.Close()
	result, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return err
	}
	var plans []map[string]string
	err = json.Unmarshal(result, &plans)
	if err != nil {
		return err
	}
	if len(plans) > 0 {
		table := cmd.NewTable()
		for _, plan := range plans {
			data := []string{plan["name"], plan["description"]}
			table.AddRow(cmd.Row(data))
		}
		table.Headers = cmd.Row([]string{"Name", "Description"})
		ctx.Stdout.Write(table.Bytes())
	}
	return nil
}
예제 #3
0
파일: services.go 프로젝트: JoeyFan/tsuru
func (c *ServiceInfo) Run(ctx *cmd.Context, client cmd.Doer) error {
	serviceName := ctx.Args[0]
	url := cmd.GetUrl("/services/" + serviceName)
	request, err := http.NewRequest("GET", url, nil)
	if err != nil {
		return err
	}
	resp, err := client.Do(request)
	if err != nil {
		return err
	}
	defer resp.Body.Close()
	result, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return err
	}
	var instances []ServiceInstanceModel
	err = json.Unmarshal(result, &instances)
	if err != nil {
		return err
	}
	ctx.Stdout.Write([]byte(fmt.Sprintf("Info for \"%s\"\n", serviceName)))
	if len(instances) > 0 {
		table := cmd.NewTable()
		table.Headers = cmd.Row([]string{"Instances", "Apps"})
		for _, instance := range instances {
			apps := strings.Join(instance.Apps, ", ")
			table.AddRow(cmd.Row([]string{instance.Name, apps}))
		}
		ctx.Stdout.Write(table.Bytes())
	}
	return nil
}
예제 #4
0
파일: apps.go 프로젝트: elimisteve/tsuru
func (c *AppList) Show(result []byte, context *cmd.Context) error {
	var apps []AppModel
	err := json.Unmarshal(result, &apps)
	if err != nil {
		return err
	}
	table := cmd.NewTable()
	table.Headers = cmd.Row([]string{"Application", "State", "Ip"})
	for _, app := range apps {
		table.AddRow(cmd.Row([]string{app.Name, app.State, app.Ip}))
	}
	context.Stdout.Write(table.Bytes())
	return nil
}
func (c ServiceInfo) BuildInstancesTable(serviceName string, ctx *cmd.Context, client *cmd.Client) error {
	url, err := cmd.GetURL("/services/" + serviceName)
	if err != nil {
		return err
	}
	request, err := http.NewRequest("GET", url, nil)
	if err != nil {
		return err
	}
	resp, err := client.Do(request)
	if err != nil {
		return err
	}
	defer resp.Body.Close()
	result, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return err
	}
	var instances []ServiceInstanceModel
	err = json.Unmarshal(result, &instances)
	if err != nil {
		return err
	}
	ctx.Stdout.Write([]byte(fmt.Sprintf("Info for \"%s\"\n\n", serviceName)))
	if len(instances) > 0 {
		ctx.Stdout.Write([]byte("Instances\n"))
		table := cmd.NewTable()
		extraHeaders := c.ExtraHeaders(instances)
		for _, instance := range instances {
			apps := strings.Join(instance.Apps, ", ")
			data := []string{instance.Name, apps}
			for _, h := range extraHeaders {
				data = append(data, instance.Info[h])
			}
			table.AddRow(cmd.Row(data))
		}
		headers := []string{"Instances", "Apps"}
		headers = append(headers, extraHeaders...)
		table.Headers = cmd.Row(headers)
		ctx.Stdout.Write(table.Bytes())
	}
	return nil
}
예제 #6
0
파일: apps.go 프로젝트: nihao/tsuru
func (a *app) String() string {
	format := `Application: %s
Repository: %s
Platform: %s
Teams: %s
Address: %s
`
	teams := strings.Join(a.Teams, ", ")
	units := cmd.NewTable()
	units.Headers = cmd.Row([]string{"Unit", "State"})
	for _, unit := range a.Units {
		units.AddRow(cmd.Row([]string{unit.Name, unit.State}))
	}
	args := []interface{}{a.Name, a.Repository, a.Platform, teams, a.Addr()}
	if len(a.Units) > 0 {
		format += "Units:\n%s"
		args = append(args, units)
	}
	return fmt.Sprintf(format, args...)
}