Skip to content

Commit 0936057

Browse files
allmightyspiffGitHub Enterprise
authored andcommitted
Merge pull request #698 from Edson-Rios/issue697
Updated command - ibmcloud sl account bandwidth-pools
2 parents c48fe3c + 77ee8f7 commit 0936057

4 files changed

Lines changed: 38 additions & 15 deletions

File tree

plugin/commands/account/bandwidth_pools.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,21 +42,19 @@ func (cmd *BandwidthPoolsCommand) Run(args []string) error {
4242

4343
outputFormat := cmd.GetOutputFlag()
4444

45-
if outputFormat == "JSON" {
46-
return utils.PrintPrettyJSON(cmd.UI, pools)
47-
}
48-
4945
table := cmd.UI.Table([]string{
5046
T("ID"),
51-
T("Pool Name"),
47+
T("Name"),
5248
T("Region"),
53-
T("Servers"),
49+
T("Devices"),
5450
T("Allocation"),
5551
T("Current Usage"),
5652
T("Projected Usage"),
53+
T("Cost"),
5754
})
55+
5856
for _, pool := range pools {
59-
curr_usage, proj_usage, allocation := "-", "-", "-"
57+
curr_usage, proj_usage, allocation, cost := "-", "-", "-", "-"
6058
if pool.BillingCyclePublicBandwidthUsage != nil {
6159
curr_usage = fmt.Sprintf("%.2f GB", float64(*pool.BillingCyclePublicBandwidthUsage.AmountOut))
6260
}
@@ -66,6 +64,9 @@ func (cmd *BandwidthPoolsCommand) Run(args []string) error {
6664
if pool.TotalBandwidthAllocated != nil {
6765
allocation = fmt.Sprintf("%d GB", uint(*pool.TotalBandwidthAllocated))
6866
}
67+
if pool.BillingItem != nil {
68+
cost = fmt.Sprintf("$%d", uint(*pool.BillingItem.NextInvoiceTotalRecurringAmount))
69+
}
6970
serverCount, _ := cmd.AccountManager.GetBandwidthPoolServers(*pool.Id)
7071
table.Add(
7172
utils.FormatIntPointer(pool.Id),
@@ -75,10 +76,11 @@ func (cmd *BandwidthPoolsCommand) Run(args []string) error {
7576
allocation,
7677
curr_usage,
7778
proj_usage,
79+
cost,
7880
)
7981
}
8082

81-
table.Print()
83+
utils.PrintTable(cmd.UI, table, outputFormat)
8284

8385
return nil
8486
}

plugin/commands/account/bandwidth_pools_test.go

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,29 @@ var _ = Describe("Account Bandwidth-Pools", func() {
3232
It("Runs without issue", func() {
3333
err := testhelpers.RunCobraCommand(cliCommand.Command)
3434
Expect(err).NotTo(HaveOccurred())
35-
outputs := fakeUI.Outputs()
36-
Expect(outputs).To(ContainSubstring("3361 GB 7.13 GB 7.70 GB"))
35+
Expect(fakeUI.Outputs()).To(ContainSubstring("Name"))
36+
Expect(fakeUI.Outputs()).To(ContainSubstring("MexRegion"))
37+
Expect(fakeUI.Outputs()).To(ContainSubstring("Region"))
38+
Expect(fakeUI.Outputs()).To(ContainSubstring("MEX"))
39+
Expect(fakeUI.Outputs()).To(ContainSubstring("Allocation"))
40+
Expect(fakeUI.Outputs()).To(ContainSubstring("3361 GB"))
41+
Expect(fakeUI.Outputs()).To(ContainSubstring("Current Usage"))
42+
Expect(fakeUI.Outputs()).To(ContainSubstring("7.70 GB"))
43+
Expect(fakeUI.Outputs()).To(ContainSubstring("Cost"))
44+
Expect(fakeUI.Outputs()).To(ContainSubstring("$25"))
3745
})
46+
3847
It("Outputs JSON", func() {
3948
err := testhelpers.RunCobraCommand(cliCommand.Command, "--output=JSON")
4049
Expect(err).NotTo(HaveOccurred())
41-
outputs := fakeUI.Outputs()
42-
Expect(outputs).To(ContainSubstring("\"amountIn\": 7.54252,"))
43-
50+
Expect(fakeUI.Outputs()).To(ContainSubstring(`"ID": "265721",`))
51+
Expect(fakeUI.Outputs()).To(ContainSubstring(`"Name": "TestPool",`))
52+
Expect(fakeUI.Outputs()).To(ContainSubstring(`"Projected Usage": "-",`))
53+
Expect(fakeUI.Outputs()).To(ContainSubstring(`"Cost": "$55"`))
54+
Expect(fakeUI.Outputs()).To(ContainSubstring(`[`))
55+
Expect(fakeUI.Outputs()).To(ContainSubstring(`{`))
56+
Expect(fakeUI.Outputs()).To(ContainSubstring(`}`))
57+
Expect(fakeUI.Outputs()).To(ContainSubstring(`]`))
4458
})
4559
})
4660
})

plugin/managers/account.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,7 @@ func (a accountManager) SummaryByDatacenter() (map[string]map[string]int, error)
8181

8282
// https://sldn.softlayer.com/reference/services/SoftLayer_Account/getBandwidthAllotments/
8383
func (a accountManager) GetBandwidthPools() ([]datatypes.Network_Bandwidth_Version1_Allotment, error) {
84-
mask := "mask[totalBandwidthAllocated,locationGroup, id, name, projectedPublicBandwidthUsage, " +
85-
"billingCyclePublicBandwidthUsage[amountOut,amountIn]]"
84+
mask := "mask[totalBandwidthAllocated,locationGroup, id, name, projectedPublicBandwidthUsage,billingCyclePublicBandwidthUsage[amountOut,amountIn],billingItem[id,nextInvoiceTotalRecurringAmount],outboundPublicBandwidthUsage,serviceProviderId,bandwidthAllotmentTypeId,activeDetailCount]"
8685
pools, err := a.AccountService.Mask(mask).GetBandwidthAllotments()
8786
return pools, err
8887
}

plugin/testfixtures/SoftLayer_Account/getBandwidthAllotments.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
"locationGroupTypeId": 1,
1212
"name": "MEX"
1313
},
14+
"billingItem": {
15+
"id": 123456,
16+
"nextInvoiceTotalRecurringAmount": 25
17+
},
1418
"name": "MexRegion",
1519
"projectedPublicBandwidthUsage": 7.7,
1620
"totalBandwidthAllocated": 3361
@@ -27,6 +31,10 @@
2731
"locationGroupTypeId": 1,
2832
"name": "US/Canada"
2933
},
34+
"billingItem": {
35+
"id": 1234567,
36+
"nextInvoiceTotalRecurringAmount": 55
37+
},
3038
"name": "TestPool",
3139
"totalBandwidthAllocated": 0
3240
}

0 commit comments

Comments
 (0)