func (cmd *showQuota) Run(context *cli.Context) { quotaName := context.Args()[0] cmd.ui.Say(T("Getting quota {{.QuotaName}} info as {{.Username}}...", map[string]interface{}{"QuotaName": quotaName, "Username": cmd.config.Username()})) quota, err := cmd.quotaRepo.FindByName(quotaName) if err != nil { cmd.ui.Failed(err.Error()) } cmd.ui.Ok() var megabytes string if quota.InstanceMemoryLimit == -1 { megabytes = T("unlimited") } else { megabytes = formatters.ByteSize(quota.InstanceMemoryLimit * formatters.MEGABYTE) } servicesLimit := strconv.Itoa(quota.ServicesLimit) if servicesLimit == "-1" { servicesLimit = T("unlimited") } table := terminal.NewTable(cmd.ui, []string{"", ""}) table.Add(T("Total Memory"), formatters.ByteSize(quota.MemoryLimit*formatters.MEGABYTE)) table.Add(T("Instance Memory"), megabytes) table.Add(T("Routes"), fmt.Sprintf("%d", quota.RoutesLimit)) table.Add(T("Services"), servicesLimit) table.Add(T("Paid service plans"), formatters.Allowed(quota.NonBasicServicesAllowed)) table.Print() }
func (cmd ListFeatureFlags) Run(c *cli.Context) { cmd.ui.Say(T("Retrieving status of all flagged features as {{.Username}}...", map[string]interface{}{ "Username": terminal.EntityNameColor(cmd.config.Username())})) flags, err := cmd.flagRepo.List() if err != nil { cmd.ui.Failed(err.Error()) return } cmd.ui.Ok() cmd.ui.Say("") table := terminal.NewTable(cmd.ui, []string{T("Features"), T("State")}) for _, flag := range flags { table.Add( flag.Name, cmd.flagBoolToString(flag.Enabled), ) } table.Print() return }
func (cmd SecurityGroups) Run(context *cli.Context) { cmd.ui.Say(T("Getting security groups as {{.username}}", map[string]interface{}{ "username": terminal.EntityNameColor(cmd.configRepo.Username()), })) securityGroups, err := cmd.securityGroupRepo.FindAll() if err != nil { cmd.ui.Failed(err.Error()) } cmd.ui.Ok() cmd.ui.Say("") if len(securityGroups) == 0 { cmd.ui.Say(T("No security groups")) return } table := terminal.NewTable(cmd.ui, []string{"", T("Name"), T("Organization"), T("Space")}) for index, securityGroup := range securityGroups { if len(securityGroup.Spaces) > 0 { cmd.printSpaces(table, securityGroup, index) } else { table.Add(fmt.Sprintf("#%d", index), securityGroup.Name, "", "") } } table.Print() }
func (cmd MarketplaceServices) Run(c *cli.Context) { var ( serviceOfferings models.ServiceOfferings apiErr error ) if cmd.config.HasSpace() { cmd.ui.Say(T("Getting services from marketplace in org {{.OrgName}} / space {{.SpaceName}} as {{.CurrentUser}}...", map[string]interface{}{ "OrgName": terminal.EntityNameColor(cmd.config.OrganizationFields().Name), "SpaceName": terminal.EntityNameColor(cmd.config.SpaceFields().Name), "CurrentUser": terminal.EntityNameColor(cmd.config.Username()), })) serviceOfferings, apiErr = cmd.serviceRepo.GetServiceOfferingsForSpace(cmd.config.SpaceFields().Guid) } else if !cmd.config.IsLoggedIn() { cmd.ui.Say(T("Getting all services from marketplace...")) serviceOfferings, apiErr = cmd.serviceRepo.GetAllServiceOfferings() } else { cmd.ui.Failed(T("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(T("No service offerings found")) return } table := terminal.NewTable(cmd.ui, []string{T("service"), T("plans"), T("description")}) 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, ", ") table.Add(offering.Label, planNames, offering.Description) } table.Print() return }
func (cmd ShowSecurityGroup) Run(context *cli.Context) { name := context.Args()[0] cmd.ui.Say(T("Getting info for security group {{.security_group}} as {{.username}}", map[string]interface{}{ "security_group": terminal.EntityNameColor(name), "username": terminal.EntityNameColor(cmd.configRepo.Username()), })) securityGroup, err := cmd.securityGroupRepo.Read(name) if err != nil { cmd.ui.Failed(err.Error()) } jsonEncodedBytes, encodingErr := json.MarshalIndent(securityGroup.Rules, "\t", "\t") if encodingErr != nil { cmd.ui.Failed(encodingErr.Error()) } cmd.ui.Ok() table := terminal.NewTable(cmd.ui, []string{"", ""}) table.Add(T("Name"), securityGroup.Name) table.Add(T("Rules"), "") table.Print() cmd.ui.Say("\t" + string(jsonEncodedBytes)) cmd.ui.Say("") if len(securityGroup.Spaces) > 0 { table = terminal.NewTable(cmd.ui, []string{"", T("Organization"), T("Space")}) for index, space := range securityGroup.Spaces { table.Add(fmt.Sprintf("#%d", index), space.Organization.Name, space.Name) } table.Print() } else { cmd.ui.Say(T("No spaces assigned")) } }
func (cmd StagingEnvironmentVariableGroup) Run(c *cli.Context) { cmd.ui.Say(T("Retrieving the contents of the staging environment variable group as {{.Username}}...", map[string]interface{}{ "Username": terminal.EntityNameColor(cmd.config.Username())})) stagingEnvVars, err := cmd.environmentVariableGroupRepo.ListStaging() if err != nil { cmd.ui.Failed(err.Error()) } cmd.ui.Ok() table := terminal.NewTable(cmd.ui, []string{T("Variable Name"), T("Assigned Value")}) for _, envVar := range stagingEnvVars { table.Add(envVar.Name, envVar.Value) } table.Print() }
func (cmd *ShowSpace) Run(c *cli.Context) { space := cmd.spaceReq.GetSpace() cmd.ui.Say(T("Getting info for space {{.TargetSpace}} in org {{.OrgName}} as {{.CurrentUser}}...", map[string]interface{}{ "TargetSpace": terminal.EntityNameColor(space.Name), "OrgName": terminal.EntityNameColor(space.Organization.Name), "CurrentUser": terminal.EntityNameColor(cmd.config.Username()), })) quotaString := cmd.quotaString(space) cmd.ui.Ok() cmd.ui.Say("") table := terminal.NewTable(cmd.ui, []string{terminal.EntityNameColor(space.Name), "", ""}) table.Add("", T("Org:"), terminal.EntityNameColor(space.Organization.Name)) apps := []string{} for _, app := range space.Applications { apps = append(apps, terminal.EntityNameColor(app.Name)) } table.Add("", T("Apps:"), strings.Join(apps, ", ")) domains := []string{} for _, domain := range space.Domains { domains = append(domains, terminal.EntityNameColor(domain.Name)) } table.Add("", T("Domains:"), strings.Join(domains, ", ")) services := []string{} for _, service := range space.ServiceInstances { services = append(services, terminal.EntityNameColor(service.Name)) } table.Add("", T("Services:"), strings.Join(services, ", ")) securityGroups := []string{} for _, group := range space.SecurityGroups { securityGroups = append(securityGroups, terminal.EntityNameColor(group.Name)) } table.Add("", T("Security Groups:"), strings.Join(securityGroups, ", ")) table.Add("", T("Space Quota:"), quotaString) table.Print() }
func (cmd ListServices) Run(c *cli.Context) { cmd.ui.Say(T("Getting services in org {{.OrgName}} / space {{.SpaceName}} as {{.CurrentUser}}...", map[string]interface{}{ "OrgName": terminal.EntityNameColor(cmd.config.OrganizationFields().Name), "SpaceName": terminal.EntityNameColor(cmd.config.SpaceFields().Name), "CurrentUser": 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(T("No services found")) return } table := terminal.NewTable(cmd.ui, []string{T("name"), T("service"), T("plan"), T("bound apps")}) for _, instance := range serviceInstances { var serviceColumn string if instance.IsUserProvided() { serviceColumn = T("user-provided") } else { serviceColumn = instance.ServiceOffering.Label } table.Add( instance.Name, serviceColumn, instance.ServicePlan.Name, strings.Join(instance.ApplicationNames, ", "), ) } table.Print() }
func (cmd ListApps) Run(c *cli.Context) { cmd.ui.Say(T("Getting apps in org {{.OrgName}} / space {{.SpaceName}} as {{.Username}}...", map[string]interface{}{ "OrgName": terminal.EntityNameColor(cmd.config.OrganizationFields().Name), "SpaceName": terminal.EntityNameColor(cmd.config.SpaceFields().Name), "Username": 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(T("No apps found")) return } table := terminal.NewTable(cmd.ui, []string{T("name"), T("requested state"), T("instances"), T("memory"), T("disk"), T("urls"), T("zone")}) for _, application := range apps { var urls []string for _, route := range application.Routes { urls = append(urls, route.URL()) } table.Add( 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, ", "), application.ApplicationFields.ZoneName, ) } table.Print() }
func (cmd *ShowOrg) Run(c *cli.Context) { org := cmd.orgReq.GetOrganization() cmd.ui.Say(T("Getting info for org {{.OrgName}} as {{.Username}}...", map[string]interface{}{ "OrgName": terminal.EntityNameColor(org.Name), "Username": terminal.EntityNameColor(cmd.config.Username())})) cmd.ui.Ok() cmd.ui.Say("") table := terminal.NewTable(cmd.ui, []string{terminal.EntityNameColor(org.Name) + ":", "", ""}) domains := []string{} for _, domain := range org.Domains { domains = append(domains, domain.Name) } spaces := []string{} for _, space := range org.Spaces { spaces = append(spaces, space.Name) } spaceQuotas := []string{} for _, spaceQuota := range org.SpaceQuotas { spaceQuotas = append(spaceQuotas, spaceQuota.Name) } quota := org.QuotaDefinition orgQuota := fmt.Sprintf(T("{{.QuotaName}} ({{.MemoryLimit}}M memory limit, {{.RoutesLimit}} routes, {{.ServicesLimit}} services, paid services {{.NonBasicServicesAllowed}})", map[string]interface{}{ "QuotaName": quota.Name, "MemoryLimit": quota.MemoryLimit, "RoutesLimit": quota.RoutesLimit, "ServicesLimit": quota.ServicesLimit, "NonBasicServicesAllowed": formatters.Allowed(quota.NonBasicServicesAllowed)})) table.Add("", T("domains:"), terminal.EntityNameColor(strings.Join(domains, ", "))) table.Add("", T("quota:"), terminal.EntityNameColor(orgQuota)) table.Add("", T("spaces:"), terminal.EntityNameColor(strings.Join(spaces, ", "))) table.Add("", T("space quotas:"), terminal.EntityNameColor(strings.Join(spaceQuotas, ", "))) table.Print() }
func (cmd ServiceAccess) printTable(brokers []models.ServiceBroker) { for _, serviceBroker := range brokers { cmd.ui.Say(fmt.Sprintf(T("broker: {{.Name}}", map[string]interface{}{"Name": serviceBroker.Name}))) table := terminal.NewTable(cmd.ui, []string{"", T("service"), T("plan"), T("access"), T("orgs")}) for _, service := range serviceBroker.Services { if len(service.Plans) > 0 { for _, plan := range service.Plans { table.Add("", service.Label, plan.Name, cmd.formatAccess(plan.Public, plan.OrgNames), strings.Join(plan.OrgNames, ",")) } } else { table.Add("", service.Label, "", "", "") } } table.Print() cmd.ui.Say("") } return }
func (cmd *ListSpaceQuotas) Run(c *cli.Context) { cmd.ui.Say(T("Getting space quotas as {{.Username}}...", map[string]interface{}{"Username": terminal.EntityNameColor(cmd.config.Username())})) quotas, apiErr := cmd.spaceQuotaRepo.FindByOrg(cmd.config.OrganizationFields().Guid) if apiErr != nil { cmd.ui.Failed(apiErr.Error()) return } cmd.ui.Ok() cmd.ui.Say("") table := terminal.NewTable(cmd.ui, []string{T("name"), T("total memory limit"), T("instance memory limit"), T("routes"), T("service instances"), T("paid service plans")}) var megabytes string for _, quota := range quotas { if quota.InstanceMemoryLimit == -1 { megabytes = T("unlimited") } else { megabytes = formatters.ByteSize(quota.InstanceMemoryLimit * formatters.MEGABYTE) } servicesLimit := strconv.Itoa(quota.ServicesLimit) if servicesLimit == "-1" { servicesLimit = T("unlimited") } table.Add( quota.Name, formatters.ByteSize(quota.MemoryLimit*formatters.MEGABYTE), megabytes, fmt.Sprintf("%d", quota.RoutesLimit), fmt.Sprintf(servicesLimit), formatters.Allowed(quota.NonBasicServicesAllowed), ) } table.Print() }
func (cmd *SpaceQuota) Run(c *cli.Context) { name := c.Args()[0] cmd.ui.Say(T("Getting space quota {{.Quota}} info as {{.Username}}...", map[string]interface{}{ "Quota": terminal.EntityNameColor(name), "Username": terminal.EntityNameColor(cmd.config.Username()), })) spaceQuota, apiErr := cmd.spaceQuotaRepo.FindByName(name) if apiErr != nil { cmd.ui.Failed(apiErr.Error()) return } cmd.ui.Ok() cmd.ui.Say("") var megabytes string table := terminal.NewTable(cmd.ui, []string{"", ""}) table.Add(T("total memory limit"), formatters.ByteSize(spaceQuota.MemoryLimit*formatters.MEGABYTE)) if spaceQuota.InstanceMemoryLimit == -1 { megabytes = T("unlimited") } else { megabytes = formatters.ByteSize(spaceQuota.InstanceMemoryLimit * formatters.MEGABYTE) } servicesLimit := strconv.Itoa(spaceQuota.ServicesLimit) if servicesLimit == "-1" { servicesLimit = T("unlimited") } table.Add(T("instance memory limit"), megabytes) table.Add(T("routes"), fmt.Sprintf("%d", spaceQuota.RoutesLimit)) table.Add(T("services"), servicesLimit) table.Add(T("non basic services"), formatters.Allowed(spaceQuota.NonBasicServicesAllowed)) table.Print() }
func (cmd ListServiceAuthTokens) Run(c *cli.Context) { cmd.ui.Say(T("Getting service auth tokens as {{.CurrentUser}}...", map[string]interface{}{ "CurrentUser": 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{T("label"), T("provider")}) for _, authToken := range authTokens { table.Add(authToken.Label, authToken.Provider) } table.Print() }
func (cmd ShowFeatureFlag) Run(c *cli.Context) { flagName := c.Args()[0] cmd.ui.Say(T("Retrieving status of {{.FeatureFlag}} as {{.Username}}...", map[string]interface{}{ "FeatureFlag": terminal.EntityNameColor(flagName), "Username": terminal.EntityNameColor(cmd.config.Username())})) flag, err := cmd.flagRepo.FindByName(flagName) if err != nil { cmd.ui.Failed(err.Error()) return } cmd.ui.Ok() cmd.ui.Say("") table := terminal.NewTable(cmd.ui, []string{T("Features"), T("State")}) table.Add(flag.Name, cmd.flagBoolToString(flag.Enabled)) table.Print() return }
func (cmd ListStacks) Run(c *cli.Context) { cmd.ui.Say(T("Getting stacks in org {{.OrganizationName}} / space {{.SpaceName}} as {{.Username}}...", map[string]interface{}{"OrganizationName": terminal.EntityNameColor(cmd.config.OrganizationFields().Name), "SpaceName": terminal.EntityNameColor(cmd.config.SpaceFields().Name), "Username": 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{T("name"), T("description")}) for _, stack := range stacks { table.Add(stack.Name, stack.Description) } table.Print() }
func (cmd *ShowApp) ShowApp(app models.Application, orgName, spaceName string) { cmd.ui.Say(T("Showing health and status for app {{.AppName}} in org {{.OrgName}} / space {{.SpaceName}} as {{.Username}}...", map[string]interface{}{ "AppName": terminal.EntityNameColor(app.Name), "OrgName": terminal.EntityNameColor(orgName), "SpaceName": terminal.EntityNameColor(spaceName), "Username": 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(T("requested state:")), ui_helpers.ColoredAppState(application.ApplicationFields)) cmd.ui.Say("%s %s", terminal.HeaderColor(T("instances:")), ui_helpers.ColoredAppInstances(application.ApplicationFields)) cmd.ui.Say(T("{{.Usage}} {{.FormattedMemory}} x {{.InstanceCount}} instances", map[string]interface{}{ "Usage": terminal.HeaderColor(T("usage:")), "FormattedMemory": formatters.ByteSize(application.Memory * formatters.MEGABYTE), "InstanceCount": application.InstanceCount})) var urls []string for _, route := range application.Routes { urls = append(urls, route.URL()) } cmd.ui.Say("%s %s", terminal.HeaderColor(T("urls:")), strings.Join(urls, ", ")) var lastUpdated string if application.PackageUpdatedAt != nil { lastUpdated = application.PackageUpdatedAt.Format("Mon Jan 2 15:04:05 MST 2006") } else { lastUpdated = "unknown" } cmd.ui.Say("%s %s\n", terminal.HeaderColor(T("last uploaded:")), lastUpdated) cmd.ui.Say("%s %s\n", terminal.HeaderColor(T("zone:")), application.ApplicationFields.ZoneName) if appIsStopped { cmd.ui.Say(T("There are no running instances of this app.")) return } table := terminal.NewTable(cmd.ui, []string{"", T("state"), T("since"), T("cpu"), T("memory"), T("disk")}) for index, instance := range instances { table.Add( 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(T("{{.MemUsage}} of {{.MemQuota}}", map[string]interface{}{ "MemUsage": formatters.ByteSize(instance.MemUsage), "MemQuota": formatters.ByteSize(instance.MemQuota)})), fmt.Sprintf(T("{{.DiskUsage}} of {{.DiskQuota}}", map[string]interface{}{ "DiskUsage": formatters.ByteSize(instance.DiskUsage), "DiskQuota": formatters.ByteSize(instance.DiskQuota)})), ) } table.Print() }
func (ui *FakeUI) Table(headers []string) term.Table { return term.NewTable(ui, headers) }