forked from cloudfoundry/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
quota.go
82 lines (68 loc) · 2.41 KB
/
quota.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package quota
import (
"fmt"
"strconv"
. "github.com/cloudfoundry/cli/cf/i18n"
"github.com/cloudfoundry/cli/flags"
"github.com/cloudfoundry/cli/cf/api/quotas"
"github.com/cloudfoundry/cli/cf/command_registry"
"github.com/cloudfoundry/cli/cf/configuration/core_config"
"github.com/cloudfoundry/cli/cf/formatters"
"github.com/cloudfoundry/cli/cf/requirements"
"github.com/cloudfoundry/cli/cf/terminal"
)
type showQuota struct {
ui terminal.UI
config core_config.Reader
quotaRepo quotas.QuotaRepository
}
func init() {
command_registry.Register(&showQuota{})
}
func (cmd *showQuota) MetaData() command_registry.CommandMetadata {
return command_registry.CommandMetadata{
Name: "quota",
Usage: T("CF_NAME quota QUOTA"),
Description: T("Show quota info"),
}
}
func (cmd *showQuota) Requirements(requirementsFactory requirements.Factory, fc flags.FlagContext) (reqs []requirements.Requirement, err error) {
if len(fc.Args()) != 1 {
cmd.ui.Failed(T("Incorrect Usage. Requires an argument\n\n") + command_registry.Commands.CommandUsage("quota"))
}
return []requirements.Requirement{
requirementsFactory.NewLoginRequirement(),
}, nil
}
func (cmd *showQuota) SetDependency(deps command_registry.Dependency, pluginCall bool) command_registry.Command {
cmd.ui = deps.Ui
cmd.config = deps.Config
cmd.quotaRepo = deps.RepoLocator.GetQuotaRepository()
return cmd
}
func (cmd *showQuota) Execute(c flags.FlagContext) {
quotaName := c.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()
}