forked from cloudfoundry/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
space_quota.go
75 lines (62 loc) · 2.58 KB
/
space_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
package models
import (
"encoding/json"
"strconv"
"code.cloudfoundry.org/cli/cf/formatters"
. "code.cloudfoundry.org/cli/cf/i18n"
)
type SpaceQuota struct {
GUID string `json:"guid,omitempty"`
Name string `json:"name"`
MemoryLimit int64 `json:"memory_limit"` // in Megabytes
InstanceMemoryLimit int64 `json:"instance_memory_limit"` // in Megabytes
RoutesLimit int `json:"total_routes"`
ServicesLimit int `json:"total_services"`
NonBasicServicesAllowed bool `json:"non_basic_services_allowed"`
OrgGUID string `json:"organization_guid"`
AppInstanceLimit int `json:"app_instance_limit"`
ReservedRoutePortsLimit json.Number `json:"total_reserved_route_ports,omitempty"`
}
const UnlimitedDisplay = "unlimited"
func (q SpaceQuota) FormattedMemoryLimit() string {
return formatters.ByteSize(q.MemoryLimit * formatters.MEGABYTE)
}
func (q SpaceQuota) FormattedInstanceMemoryLimit() string {
if q.InstanceMemoryLimit == -1 {
return T(UnlimitedDisplay)
}
return formatters.ByteSize(q.InstanceMemoryLimit * formatters.MEGABYTE)
}
func (q SpaceQuota) FormattedAppInstanceLimit() string {
appInstanceLimit := T(UnlimitedDisplay)
if q.AppInstanceLimit != -1 { //TODO - figure out how to use resources.UnlimitedAppInstances
appInstanceLimit = strconv.Itoa(q.AppInstanceLimit)
}
return appInstanceLimit
}
func (q SpaceQuota) FormattedServicesLimit() string {
servicesLimit := T(UnlimitedDisplay)
if q.ServicesLimit != -1 {
servicesLimit = strconv.Itoa(q.ServicesLimit)
}
return servicesLimit
}
func (q SpaceQuota) FormattedRoutePortsLimit() string {
reservedRoutePortsLimit := T(UnlimitedDisplay)
if q.ReservedRoutePortsLimit != "-1" {
reservedRoutePortsLimit = string(q.ReservedRoutePortsLimit)
}
return reservedRoutePortsLimit
}
type SpaceQuotaResponse struct {
GUID string `json:"guid,omitempty"`
Name string `json:"name"`
MemoryLimit int64 `json:"memory_limit"` // in Megabytes
InstanceMemoryLimit int64 `json:"instance_memory_limit"` // in Megabytes
RoutesLimit int `json:"total_routes"`
ServicesLimit int `json:"total_services"`
NonBasicServicesAllowed bool `json:"non_basic_services_allowed"`
OrgGUID string `json:"organization_guid"`
AppInstanceLimit json.Number `json:"app_instance_limit"`
ReservedRoutePortsLimit json.Number `json:"total_reserved_route_ports"`
}