Skip to content

Commit cd33614

Browse files
allmightyspiffGitHub Enterprise
authored andcommitted
Merge pull request #709 from Brian-Flores/issue708
Add `upgrades` option in `ibmcloud sl account orders`
2 parents 647e2ee + be9a6ba commit cd33614

5 files changed

Lines changed: 179 additions & 0 deletions

File tree

plugin/commands/account/orders.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ type OrdersCommand struct {
2121
AccountManager managers.AccountManager
2222
Command *cobra.Command
2323
Limit int
24+
Upgrades bool
2425
}
2526

2627
func NewOrdersCommand(sl *metadata.SoftlayerCommand) *OrdersCommand {
@@ -37,6 +38,7 @@ func NewOrdersCommand(sl *metadata.SoftlayerCommand) *OrdersCommand {
3738
},
3839
}
3940
cobraCmd.Flags().IntVar(&thisCmd.Limit, "limit", 100, T("How many results to get in one api call."))
41+
cobraCmd.Flags().BoolVar(&thisCmd.Upgrades, "upgrades", false, T("Show upgrades orders."))
4042
thisCmd.Command = cobraCmd
4143
return thisCmd
4244
}
@@ -51,6 +53,15 @@ func (cmd *OrdersCommand) Run(args []string) error {
5153
}
5254
PrintOrders(orders, cmd.UI, outputFormat)
5355

56+
if cmd.Upgrades {
57+
mask = "mask[id,maintenanceStartTimeUtc,statusId,createDate,ticketId]"
58+
upgrades, err := cmd.AccountManager.GetUpgradeRequests(mask, cmd.Limit)
59+
if err != nil {
60+
return errors.NewAPIError(T("Failed to get Upgrade Requests."), err.Error(), 2)
61+
}
62+
PrintUpgrades(upgrades, cmd.UI, outputFormat)
63+
}
64+
5465
return nil
5566
}
5667

@@ -84,3 +95,26 @@ func PrintOrders(orders []datatypes.Billing_Order, ui terminal.UI, outputFormat
8495

8596
utils.PrintTableWithTitle(ui, table, bufEvent, "Orders", outputFormat)
8697
}
98+
99+
func PrintUpgrades(upgrades []datatypes.Product_Upgrade_Request, ui terminal.UI, outputFormat string) {
100+
bufEvent := new(bytes.Buffer)
101+
table := terminal.NewTable(bufEvent, []string{
102+
T("Id"),
103+
T("Maintance Window"),
104+
T("Status"),
105+
T("Created Date"),
106+
T("Case"),
107+
})
108+
109+
for _, upgrade := range upgrades {
110+
table.Add(
111+
utils.FormatIntPointer(upgrade.Id),
112+
utils.FormatSLTimePointer(upgrade.MaintenanceStartTimeUtc),
113+
utils.FormatIntPointer(upgrade.StatusId),
114+
utils.FormatSLTimePointer(upgrade.CreateDate),
115+
utils.FormatIntPointer(upgrade.TicketId),
116+
)
117+
}
118+
119+
utils.PrintTableWithTitle(ui, table, bufEvent, "Upgrade orders", outputFormat)
120+
}

plugin/commands/account/orders_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,26 @@ var _ = Describe("Account list Orders", func() {
5959
Expect(fakeUI.Outputs()).To(ContainSubstring(`"Item": "1 x 2.0 GHz or higher Core,1 x 2.0 GHz or higher Core,1 GB,Reboot / Remote Conso...""`))
6060
})
6161
})
62+
63+
Context("Account orders, correct use with upgrades", func() {
64+
It("return account orders and upgrades", func() {
65+
err := testhelpers.RunCobraCommand(cliCommand.Command, "--limit", "10", "--upgrades")
66+
Expect(err).NotTo(HaveOccurred())
67+
Expect(fakeUI.Outputs()).To(ContainSubstring("123456789"))
68+
Expect(fakeUI.Outputs()).To(ContainSubstring("APPROVED"))
69+
Expect(fakeUI.Outputs()).To(ContainSubstring("test.test@ibm.com"))
70+
Expect(fakeUI.Outputs()).To(ContainSubstring("2022-04-26T19:50:06Z"))
71+
Expect(fakeUI.Outputs()).To(ContainSubstring("0.000000"))
72+
Expect(fakeUI.Outputs()).To(ContainSubstring("1 x 2.0 GHz or higher Core,1 x 2.0 GHz or higher Core,1 GB,Reboot / Remote Conso..."))
73+
Expect(fakeUI.Outputs()).To(ContainSubstring("91954410"))
74+
Expect(fakeUI.Outputs()).To(ContainSubstring("123456_test.test@ibm.com"))
75+
Expect(fakeUI.Outputs()).To(ContainSubstring("2022-04-26T19:39:17Z"))
76+
Expect(fakeUI.Outputs()).To(ContainSubstring("3237486"))
77+
Expect(fakeUI.Outputs()).To(ContainSubstring("3"))
78+
Expect(fakeUI.Outputs()).To(ContainSubstring("152510472"))
79+
Expect(fakeUI.Outputs()).To(ContainSubstring("3229998"))
80+
Expect(fakeUI.Outputs()).To(ContainSubstring("152452042"))
81+
})
82+
})
6283
})
6384
})

plugin/managers/account.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ type AccountManager interface {
3131
GetPostProvisioningHooks(mask string) ([]datatypes.Provisioning_Hook, error)
3232
CreateProvisioningScript(template datatypes.Provisioning_Hook) (datatypes.Provisioning_Hook, error)
3333
DeleteProvisioningScript(idProvisioningScript int) (resp bool, err error)
34+
GetUpgradeRequests(mask string, limit int) ([]datatypes.Product_Upgrade_Request, error)
3435
}
3536

3637
type accountManager struct {
@@ -379,3 +380,11 @@ func (a accountManager) DeleteProvisioningScript(idProvisioningScript int) (resp
379380
provisioningHook := services.GetProvisioningHookService(a.Session)
380381
return provisioningHook.Id(idProvisioningScript).DeleteObject()
381382
}
383+
384+
/*
385+
Gets account's associated upgrade requests.
386+
https://sldn.softlayer.com/reference/services/SoftLayer_Account/getUpgradeRequests/
387+
*/
388+
func (a accountManager) GetUpgradeRequests(mask string, limit int) ([]datatypes.Product_Upgrade_Request, error) {
389+
return a.AccountService.Limit(limit).Mask(mask).GetUpgradeRequests()
390+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
[
2+
{
3+
"accountId": 307608,
4+
"createDate": "2023-03-01T19:39:51-06:00",
5+
"employeeId": null,
6+
"guestId": null,
7+
"hardwareId": null,
8+
"id": 3237486,
9+
"maintenanceStartTimeUtc": "2023-03-01T19:39:51-06:00",
10+
"modifyDate": "2023-03-01T19:39:53-06:00",
11+
"orderId": 103127604,
12+
"orderTotal": "0",
13+
"proratedTotal": "0",
14+
"statusId": 3,
15+
"ticketId": 152510472,
16+
"userId": 167758
17+
},
18+
{
19+
"accountId": 307608,
20+
"createDate": "2023-02-27T19:41:26-06:00",
21+
"employeeId": null,
22+
"guestId": null,
23+
"hardwareId": null,
24+
"id": 3229998,
25+
"maintenanceStartTimeUtc": "2023-02-27T19:41:26-06:00",
26+
"modifyDate": "2023-02-27T19:41:29-06:00",
27+
"orderId": 103029352,
28+
"orderTotal": "0",
29+
"proratedTotal": "0",
30+
"statusId": 3,
31+
"ticketId": 152452042,
32+
"userId": 167758
33+
}
34+
]

plugin/testhelpers/fake_account_manager.go

Lines changed: 81 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)