Skip to content

Commit

Permalink
org-quota and space-quota now show log volume
Browse files Browse the repository at this point in the history
* code currently assumes responses with log limits. Consider
  backward compatibility before shipping.

Signed-off-by: Carson Long <lcarson@vmware.com>
  • Loading branch information
mkocher authored and ctlong committed Jul 20, 2022
1 parent 9f4d281 commit ab8feab
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 1 deletion.
2 changes: 2 additions & 0 deletions command/v7/org_quota_command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ var _ = Describe("Org Quota Command", func() {
TotalMemory: &types.NullInt{IsSet: true, Value: 2048},
InstanceMemory: &types.NullInt{IsSet: true, Value: 1024},
TotalAppInstances: &types.NullInt{IsSet: true, Value: 2},
TotalLogVolume: &types.NullInt{IsSet: true, Value: 512},
},
Services: resources.ServiceLimit{
TotalServiceInstances: &types.NullInt{IsSet: false},
Expand Down Expand Up @@ -138,6 +139,7 @@ var _ = Describe("Org Quota Command", func() {
Expect(testUI.Out).To(Say(`paid service plans:\s+disallowed`))
Expect(testUI.Out).To(Say(`app instances:\s+2`))
Expect(testUI.Out).To(Say(`route ports:\s+unlimited`))
Expect(testUI.Out).To(Say(`log volume per second:\s+512B`))
})
})
})
17 changes: 16 additions & 1 deletion command/v7/shared/quota_displayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import (
)

const (
MEGABYTE = 1024 * 1024
KILOBYTE = 1024
MEGABYTE = 1024 * KILOBYTE
GIGABYTE = 1024 * MEGABYTE
TERABYTE = 1024 * GIGABYTE
)
Expand Down Expand Up @@ -60,6 +61,7 @@ func (displayer QuotaDisplayer) DisplaySingleQuota(quota resources.Quota) {
{displayer.ui.TranslateText("paid service plans:"), displayer.presentBooleanValue(*quota.Services.PaidServicePlans)},
{displayer.ui.TranslateText("app instances:"), displayer.presentQuotaValue(*quota.Apps.TotalAppInstances)},
{displayer.ui.TranslateText("route ports:"), displayer.presentQuotaValue(*quota.Routes.TotalReservedPorts)},
{displayer.ui.TranslateText("log volume per second:"), displayer.presentQuotaBytesValue(*quota.Apps.TotalLogVolume)},
}

displayer.ui.DisplayKeyValueTable("", quotaTable, 3)
Expand All @@ -81,6 +83,14 @@ func (displayer QuotaDisplayer) presentQuotaValue(limit types.NullInt) string {
}
}

func (displayer QuotaDisplayer) presentQuotaBytesValue(limit types.NullInt) string {
if !limit.IsSet {
return "unlimited"
} else {
return addMemoryUnits(float64(limit.Value))
}
}

func (displayer QuotaDisplayer) presentQuotaMemoryValue(limit types.NullInt) string {
if !limit.IsSet {
return "unlimited"
Expand All @@ -103,6 +113,11 @@ func addMemoryUnits(bytes float64) string {
case bytes >= MEGABYTE:
unit = "M"
value /= MEGABYTE
case bytes >= KILOBYTE:
unit = "K"
value /= KILOBYTE
case bytes >= 1:
unit = "B"
case bytes == 0:
return "0"
}
Expand Down
2 changes: 2 additions & 0 deletions command/v7/space_quota_command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ var _ = Describe("Space Quota Command", func() {
TotalMemory: &types.NullInt{IsSet: true, Value: 2048},
InstanceMemory: &types.NullInt{IsSet: true, Value: 1024},
TotalAppInstances: &types.NullInt{IsSet: true, Value: 2},
TotalLogVolume: &types.NullInt{IsSet: true, Value: 512},
},
Services: resources.ServiceLimit{
TotalServiceInstances: &types.NullInt{IsSet: false},
Expand Down Expand Up @@ -135,6 +136,7 @@ var _ = Describe("Space Quota Command", func() {
Expect(testUI.Out).To(Say(`paid service plans:\s+disallowed`))
Expect(testUI.Out).To(Say(`app instances:\s+2`))
Expect(testUI.Out).To(Say(`route ports:\s+unlimited`))
Expect(testUI.Out).To(Say(`log volume per second:\s+512B`))
})
})
})
1 change: 1 addition & 0 deletions integration/v7/global/org_quota_command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ var _ = Describe("org-quota command", func() {
Eventually(session).Should(Say(`paid service plans:\s+allowed`))
Eventually(session).Should(Say(`app instances:\s+unlimited`))
Eventually(session).Should(Say(`route ports:\s+100`))
Eventually(session).Should(Say(`log volume per second:\s+unlimited`))

Eventually(session).Should(Exit(0))
})
Expand Down
1 change: 1 addition & 0 deletions integration/v7/isolated/space_quota_command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ var _ = Describe("space-quota command", func() {
Eventually(session).Should(Say(`paid service plans:\s+allowed`))
Eventually(session).Should(Say(`app instances:\s+unlimited`))
Eventually(session).Should(Say(`route ports:\s+0`))
Eventually(session).Should(Say(`log volume per second:\s+unlimited`))

Eventually(session).Should(Exit(0))
})
Expand Down

0 comments on commit ab8feab

Please sign in to comment.