Ejemplo n.º 1
0
func (cmd *ListQuotas) Run(c *cli.Context) {
	cmd.ui.Say("Getting quotas as %s...", terminal.EntityNameColor(cmd.config.Username()))

	quotas, apiErr := cmd.quotaRepo.FindAll()

	if apiErr != nil {
		cmd.ui.Failed(apiErr.Error())
		return
	}
	cmd.ui.Ok()
	cmd.ui.Say("")

	table := terminal.NewTable(cmd.ui, []string{"name", "memory limit", "routes", "service instances", "paid service plans"})
	rows := [][]string{}

	for _, quota := range quotas {
		rows = append(rows, []string{
			quota.Name,
			formatters.ByteSize(quota.MemoryLimit * formatters.MEGABYTE),
			fmt.Sprintf("%d", quota.RoutesLimit),
			fmt.Sprintf("%d", quota.ServicesLimit),
			formatters.Allowed(quota.NonBasicServicesAllowed),
		})
	}

	table.Print(rows)
}
Ejemplo n.º 2
0
func (cmd ListStacks) Run(c *cli.Context) {
	cmd.ui.Say("Getting stacks in org %s / space %s as %s...",
		terminal.EntityNameColor(cmd.config.OrganizationFields().Name),
		terminal.EntityNameColor(cmd.config.SpaceFields().Name),
		terminal.EntityNameColor(cmd.config.Username()),
	)

	stacks, apiErr := cmd.stacksRepo.FindAll()
	if apiErr != nil {
		cmd.ui.Failed(apiErr.Error())
		return
	}

	cmd.ui.Ok()
	cmd.ui.Say("")

	table := terminal.NewTable(cmd.ui, []string{"name", "description"})
	rows := [][]string{}

	for _, stack := range stacks {
		rows = append(rows, []string{
			stack.Name,
			stack.Description,
		})
	}

	table.Print(rows)
}
Ejemplo n.º 3
0
func (cmd MarketplaceServices) Run(c *cli.Context) {
	var (
		serviceOfferings models.ServiceOfferings
		apiErr           error
	)

	if cmd.config.HasSpace() {
		cmd.ui.Say("Getting services from marketplace in org %s / space %s as %s...",
			terminal.EntityNameColor(cmd.config.OrganizationFields().Name),
			terminal.EntityNameColor(cmd.config.SpaceFields().Name),
			terminal.EntityNameColor(cmd.config.Username()),
		)
		serviceOfferings, apiErr = cmd.serviceRepo.GetServiceOfferingsForSpace(cmd.config.SpaceFields().Guid)
	} else if !cmd.config.IsLoggedIn() {
		cmd.ui.Say("Getting all services from marketplace...")
		serviceOfferings, apiErr = cmd.serviceRepo.GetAllServiceOfferings()
	} else {
		cmd.ui.Failed("Cannot list marketplace services without a targeted space")
	}

	if apiErr != nil {
		cmd.ui.Failed(apiErr.Error())
		return
	}

	cmd.ui.Ok()
	cmd.ui.Say("")

	if len(serviceOfferings) == 0 {
		cmd.ui.Say("No service offerings found")
		return
	}

	table := terminal.NewTable(cmd.ui, []string{"service", "plans", "description"})
	rows := [][]string{}

	sort.Sort(serviceOfferings)
	for _, offering := range serviceOfferings {
		planNames := ""

		for _, plan := range offering.Plans {
			if plan.Name == "" {
				continue
			}
			planNames = planNames + ", " + plan.Name
		}

		planNames = strings.TrimPrefix(planNames, ", ")

		rows = append(rows, []string{
			offering.Label,
			planNames,
			offering.Description,
		})
	}

	table.Print(rows)
	return
}
Ejemplo n.º 4
0
Archivo: apps.go Proyecto: nota-ja/cli
func (cmd ListApps) Run(c *cli.Context) {
	cmd.ui.Say("Getting apps in org %s / space %s as %s...",
		terminal.EntityNameColor(cmd.config.OrganizationFields().Name),
		terminal.EntityNameColor(cmd.config.SpaceFields().Name),
		terminal.EntityNameColor(cmd.config.Username()),
	)

	apps, apiErr := cmd.appSummaryRepo.GetSummariesInCurrentSpace()

	if apiErr != nil {
		cmd.ui.Failed(apiErr.Error())
		return
	}

	cmd.ui.Ok()
	cmd.ui.Say("")

	if len(apps) == 0 {
		cmd.ui.Say("No apps found")
		return
	}

	table := terminal.NewTable(cmd.ui, []string{
		"name",
		"requested state",
		"instances",
		"memory",
		"disk",
		"urls",
	})

	rows := [][]string{}

	for _, application := range apps {
		var urls []string
		for _, route := range application.Routes {
			urls = append(urls, route.URL())
		}

		rows = append(rows, []string{
			application.Name,
			ui_helpers.ColoredAppState(application.ApplicationFields),
			ui_helpers.ColoredAppInstances(application.ApplicationFields),
			formatters.ByteSize(application.Memory * formatters.MEGABYTE),
			formatters.ByteSize(application.DiskQuota * formatters.MEGABYTE),
			strings.Join(urls, ", "),
		})
	}

	table.Print(rows)
}
Ejemplo n.º 5
0
func (cmd ListServices) Run(c *cli.Context) {
	cmd.ui.Say("Getting services in org %s / space %s as %s...",
		terminal.EntityNameColor(cmd.config.OrganizationFields().Name),
		terminal.EntityNameColor(cmd.config.SpaceFields().Name),
		terminal.EntityNameColor(cmd.config.Username()),
	)

	serviceInstances, apiErr := cmd.serviceSummaryRepo.GetSummariesInCurrentSpace()

	if apiErr != nil {
		cmd.ui.Failed(apiErr.Error())
		return
	}

	cmd.ui.Ok()
	cmd.ui.Say("")

	if len(serviceInstances) == 0 {
		cmd.ui.Say("No services found")
		return
	}

	table := terminal.NewTable(cmd.ui, []string{"name", "service", "plan", "bound apps"})
	rows := [][]string{}

	for _, instance := range serviceInstances {
		var serviceColumn string

		if instance.IsUserProvided() {
			serviceColumn = "user-provided"
		} else {
			serviceColumn = instance.ServiceOffering.Label
		}

		rows = append(rows, []string{
			instance.Name,
			serviceColumn,
			instance.ServicePlan.Name,
			strings.Join(instance.ApplicationNames, ", "),
		})
	}

	table.Print(rows)
}
Ejemplo n.º 6
0
Archivo: quota.go Proyecto: nota-ja/cli
func (cmd *showQuota) Run(context *cli.Context) {
	quotaName := context.Args()[0]
	cmd.ui.Say("Getting quota %s info as %s...", quotaName, cmd.config.Username())

	quota, err := cmd.quotaRepo.FindByName(quotaName)
	if err != nil {
		cmd.ui.Failed(err.Error())
	}

	cmd.ui.Ok()

	table := terminal.NewTable(cmd.ui, []string{"", ""})
	table.Print([][]string{
		[]string{"Memory", formatters.ByteSize(quota.MemoryLimit * formatters.MEGABYTE)},
		[]string{"Routes", fmt.Sprintf("%d", quota.RoutesLimit)},
		[]string{"Services", fmt.Sprintf("%d", quota.ServicesLimit)},
		[]string{"Paid service plans", formatters.Allowed(quota.NonBasicServicesAllowed)},
	})
}
Ejemplo n.º 7
0
func (cmd ListServiceAuthTokens) Run(c *cli.Context) {
	cmd.ui.Say("Getting service auth tokens as %s...", terminal.EntityNameColor(cmd.config.Username()))
	authTokens, apiErr := cmd.authTokenRepo.FindAll()
	if apiErr != nil {
		cmd.ui.Failed(apiErr.Error())
		return
	}
	cmd.ui.Ok()
	cmd.ui.Say("")

	table := terminal.NewTable(cmd.ui, []string{"label", "provider"})
	rows := [][]string{}

	for _, authToken := range authTokens {
		rows = append(rows, []string{authToken.Label, authToken.Provider})
	}

	table.Print(rows)
}
Ejemplo n.º 8
0
Archivo: ui.go Proyecto: knolleary/cli
func (ui *FakeUI) Table(headers []string) term.Table {
	return term.NewTable(ui, headers)
}
Ejemplo n.º 9
0
Archivo: app.go Proyecto: nota-ja/cli
func (cmd *ShowApp) ShowApp(app models.Application) {

	cmd.ui.Say("Showing health and status for app %s in org %s / space %s as %s...",
		terminal.EntityNameColor(app.Name),
		terminal.EntityNameColor(cmd.config.OrganizationFields().Name),
		terminal.EntityNameColor(cmd.config.SpaceFields().Name),
		terminal.EntityNameColor(cmd.config.Username()),
	)

	application, apiErr := cmd.appSummaryRepo.GetSummary(app.Guid)

	appIsStopped := (application.State == "stopped")
	if err, ok := apiErr.(errors.HttpError); ok {
		if err.ErrorCode() == errors.APP_STOPPED || err.ErrorCode() == errors.APP_NOT_STAGED {
			appIsStopped = true
		}
	}

	if apiErr != nil && !appIsStopped {
		cmd.ui.Failed(apiErr.Error())
		return
	}

	var instances []models.AppInstanceFields
	instances, apiErr = cmd.appInstancesRepo.GetInstances(app.Guid)
	if apiErr != nil && !appIsStopped {
		cmd.ui.Failed(apiErr.Error())
		return
	}

	cmd.ui.Ok()
	cmd.ui.Say("\n%s %s", terminal.HeaderColor("requested state:"), ui_helpers.ColoredAppState(application.ApplicationFields))
	cmd.ui.Say("%s %s", terminal.HeaderColor("instances:"), ui_helpers.ColoredAppInstances(application.ApplicationFields))
	cmd.ui.Say("%s %s x %d instances", terminal.HeaderColor("usage:"), formatters.ByteSize(application.Memory*formatters.MEGABYTE), application.InstanceCount)

	var urls []string
	for _, route := range application.Routes {
		urls = append(urls, route.URL())
	}

	cmd.ui.Say("%s %s\n", terminal.HeaderColor("urls:"), strings.Join(urls, ", "))

	if appIsStopped {
		cmd.ui.Say("There are no running instances of this app.")
		return
	}

	table := terminal.NewTable(cmd.ui, []string{"", "state", "since", "cpu", "memory", "disk"})
	rows := [][]string{}

	for index, instance := range instances {
		rows = append(rows, []string{
			fmt.Sprintf("#%d", index),
			ui_helpers.ColoredInstanceState(instance),
			instance.Since.Format("2006-01-02 03:04:05 PM"),
			fmt.Sprintf("%.1f%%", instance.CpuUsage*100),
			fmt.Sprintf("%s of %s", formatters.ByteSize(instance.MemUsage), formatters.ByteSize(instance.MemQuota)),
			fmt.Sprintf("%s of %s", formatters.ByteSize(instance.DiskUsage), formatters.ByteSize(instance.DiskQuota)),
		})
	}

	table.Print(rows)
}