Port OSS changes for Enterprise Quota accounting (#10481)
This commit is contained in:
parent
52d881f567
commit
98a9a9052f
|
@ -264,6 +264,7 @@ func parseQuotaResource(result *api.Resources, list *ast.ObjectList) error {
|
|||
valid := []string{
|
||||
"cpu",
|
||||
"memory",
|
||||
"memory_max",
|
||||
}
|
||||
if err := helper.CheckHCLKeys(listVal, valid); err != nil {
|
||||
return multierror.Prefix(err, "resources ->")
|
||||
|
|
|
@ -109,17 +109,18 @@ func (c *QuotaInitCommand) Run(args []string) int {
|
|||
}
|
||||
|
||||
var defaultHclQuotaSpec = strings.TrimSpace(`
|
||||
name = "default-quota"
|
||||
name = "default-quota"
|
||||
description = "Limit the shared default namespace"
|
||||
|
||||
# Create a limit for the global region. Additional limits may
|
||||
# be specified in-order to limit other regions.
|
||||
limit {
|
||||
region = "global"
|
||||
region_limit {
|
||||
cpu = 2500
|
||||
memory = 1000
|
||||
}
|
||||
region = "global"
|
||||
region_limit {
|
||||
cpu = 2500
|
||||
memory = 1000
|
||||
memory_max = 1000
|
||||
}
|
||||
}
|
||||
`)
|
||||
|
||||
|
@ -132,7 +133,8 @@ var defaultJsonQuotaSpec = strings.TrimSpace(`
|
|||
"Region": "global",
|
||||
"RegionLimit": {
|
||||
"CPU": 2500,
|
||||
"MemoryMB": 1000
|
||||
"MemoryMB": 1000,
|
||||
"MemoryMaxMB": 1000
|
||||
}
|
||||
}
|
||||
]
|
||||
|
|
|
@ -158,7 +158,7 @@ func formatQuotaLimits(spec *api.QuotaSpec, usages map[string]*api.QuotaUsage) s
|
|||
sort.Sort(api.QuotaLimitSort(spec.Limits))
|
||||
|
||||
limits := make([]string, len(spec.Limits)+1)
|
||||
limits[0] = "Region|CPU Usage|Memory Usage|Network Usage"
|
||||
limits[0] = "Region|CPU Usage|Memory Usage|Memory Max Usage|Network Usage"
|
||||
i := 0
|
||||
for _, specLimit := range spec.Limits {
|
||||
i++
|
||||
|
@ -183,18 +183,20 @@ func formatQuotaLimits(spec *api.QuotaSpec, usages map[string]*api.QuotaUsage) s
|
|||
if !ok {
|
||||
cpu := fmt.Sprintf("- / %s", formatQuotaLimitInt(specLimit.RegionLimit.CPU))
|
||||
memory := fmt.Sprintf("- / %s", formatQuotaLimitInt(specLimit.RegionLimit.MemoryMB))
|
||||
memoryMax := fmt.Sprintf("- / %s", formatQuotaLimitInt(specLimit.RegionLimit.MemoryMaxMB))
|
||||
net := fmt.Sprintf("- / %s", formatQuotaLimitInt(&specBits))
|
||||
limits[i] = fmt.Sprintf("%s|%s|%s|%s", specLimit.Region, cpu, memory, net)
|
||||
limits[i] = fmt.Sprintf("%s|%s|%s|%s|%s", specLimit.Region, cpu, memory, memoryMax, net)
|
||||
continue
|
||||
}
|
||||
|
||||
cpu := fmt.Sprintf("%d / %s", *used.RegionLimit.CPU, formatQuotaLimitInt(specLimit.RegionLimit.CPU))
|
||||
memory := fmt.Sprintf("%d / %s", *used.RegionLimit.MemoryMB, formatQuotaLimitInt(specLimit.RegionLimit.MemoryMB))
|
||||
memoryMax := fmt.Sprintf("%d / %s", *used.RegionLimit.MemoryMaxMB, formatQuotaLimitInt(specLimit.RegionLimit.MemoryMaxMB))
|
||||
net := fmt.Sprintf("- / %s", formatQuotaLimitInt(&specBits))
|
||||
if len(used.RegionLimit.Networks) == 1 {
|
||||
net = fmt.Sprintf("%d / %s", *used.RegionLimit.Networks[0].MBits, formatQuotaLimitInt(&specBits))
|
||||
}
|
||||
limits[i] = fmt.Sprintf("%s|%s|%s|%s", specLimit.Region, cpu, memory, net)
|
||||
limits[i] = fmt.Sprintf("%s|%s|%s|%s|%s", specLimit.Region, cpu, memory, memoryMax, net)
|
||||
}
|
||||
|
||||
return formatList(limits)
|
||||
|
|
Loading…
Reference in New Issue