Skip to content

Commit d1060d6

Browse files
finishing up vlan tag features
1 parent 4c57c5f commit d1060d6

7 files changed

Lines changed: 112 additions & 63 deletions

File tree

plugin/commands/hardware/detail.go

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77

88
"github.com/IBM-Cloud/ibm-cloud-cli-sdk/bluemix/terminal"
99
"github.com/spf13/cobra"
10-
10+
"github.ibm.com/SoftLayer/softlayer-cli/plugin/errors"
1111
slErr "github.ibm.com/SoftLayer/softlayer-cli/plugin/errors"
1212
. "github.ibm.com/SoftLayer/softlayer-cli/plugin/i18n"
1313
"github.ibm.com/SoftLayer/softlayer-cli/plugin/managers"
@@ -55,9 +55,24 @@ func (cmd *DetailCommand) Run(args []string) error {
5555

5656
outputFormat := cmd.GetOutputFlag()
5757

58-
hardware, err := cmd.HardwareManager.GetHardwareFast(hardwareId)
58+
hardware, err := cmd.HardwareManager.GetHardware(hardwareId, "")
59+
if err != nil {
60+
return errors.NewAPIError(T("Failed to get hardware server: {{.ID}}.\n", map[string]interface{}{"ID": hardwareId}), err.Error(), 2)
61+
}
62+
63+
hardDrives, err := cmd.HardwareManager.GetHardDrives(hardwareId)
5964
if err != nil {
60-
return slErr.NewAPIError(T("Failed to get hardware server: {{.ID}}.\n", map[string]interface{}{"ID": hardwareId}), err.Error(), 2)
65+
return err
66+
}
67+
68+
bandwidthAllotmentDetail, err := cmd.HardwareManager.GetBandwidthAllotmentDetail(hardwareId, "")
69+
if err != nil {
70+
return err
71+
}
72+
73+
billingCycleBandwidthUsage, err := cmd.HardwareManager.GetBillingCycleBandwidthUsage(hardwareId, "")
74+
if err != nil {
75+
return err
6176
}
6277

6378
if outputFormat == "JSON" {
@@ -79,10 +94,10 @@ func (cmd *DetailCommand) Run(args []string) error {
7994
table.Add(T("CPU cores"), utils.FormatUIntPointer(hardware.ProcessorPhysicalCoreAmount))
8095
table.Add(T("Memory"), utils.FormatUIntPointer(hardware.MemoryCapacity)+"G")
8196

82-
if len(hardware.HardDrives) > 0 {
97+
if len(hardDrives) > 0 {
8398
buf := new(bytes.Buffer)
8499
hardDriveTable := terminal.NewTable(buf, []string{T("Name"), T("Capacity"), T("Serial #")})
85-
for _, hardDrive := range hardware.HardDrives {
100+
for _, hardDrive := range hardDrives {
86101
name := *hardDrive.HardwareComponentModel.Manufacturer + " " + *hardDrive.HardwareComponentModel.Name
87102
capacity := fmt.Sprintf(
88103
"%.2f %s",
@@ -155,6 +170,9 @@ func (cmd *DetailCommand) Run(args []string) error {
155170
for _, component := range hardware.NetworkComponents {
156171
if component.PrimaryIpAddress != nil {
157172
uplink := component.UplinkComponent
173+
if uplink == nil {
174+
continue
175+
}
158176
for _, trunk := range uplink.NetworkVlanTrunks {
159177
t_vlan := trunk.NetworkVlan
160178
vlanTable.Add(
@@ -171,18 +189,18 @@ func (cmd *DetailCommand) Run(args []string) error {
171189
table.Add("Vlans", buf.String())
172190
}
173191

174-
if len(hardware.BillingCycleBandwidthUsage) > 0 {
192+
if len(billingCycleBandwidthUsage) > 0 {
175193
buf := new(bytes.Buffer)
176194
bandwithTable := terminal.NewTable(buf, []string{T("Type"), T("In GB"), T("Out GB"), T("Allotment")})
177-
for _, billingCycle := range hardware.BillingCycleBandwidthUsage {
195+
for _, billingCycle := range billingCycleBandwidthUsage {
178196
bw_type := "Private"
179197
allotment := "N/A"
180198
if *billingCycle.Type.Alias == "PUBLIC_SERVER_BW" {
181199
bw_type = "Public"
182-
if hardware.BandwidthAllotmentDetail.Allocation == nil {
200+
if bandwidthAllotmentDetail.Allocation == nil {
183201
allotment = "-"
184202
} else {
185-
allotment = utils.FormatSLFloatPointerToInt(hardware.BandwidthAllotmentDetail.Allocation.Amount)
203+
allotment = utils.FormatSLFloatPointerToInt(bandwidthAllotmentDetail.Allocation.Amount)
186204
}
187205
}
188206
bandwithTable.Add(
@@ -248,13 +266,11 @@ func (cmd *DetailCommand) Run(args []string) error {
248266
}
249267
}
250268

251-
// For some reason, the API response here has a hardwareComponent for EACH firmware, each with the whole list of firmwares
252-
// There should be a better way to get this from the API.
253269
if cmd.Components {
254270
components, err := cmd.HardwareManager.GetHardwareComponents(hardwareId)
255271
componentIds := []int{}
256272
if err != nil {
257-
return slErr.NewAPIError(T("Failed to get components\n"), err.Error(), 2)
273+
return errors.NewAPIError(T("Failed to get components\n"), err.Error(), 2)
258274
}
259275
buf := new(bytes.Buffer)
260276
componentTable := terminal.NewTable(buf, []string{T("Name"), T("Firmware version"), T("Firmware build date"), T("Type")})

plugin/commands/hardware/detail_test.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,11 @@ var _ = Describe("hardware detail", func() {
101101
Expect(fakeUI.Outputs()).To(ContainSubstring("Owner SL123456"))
102102
Expect(fakeUI.Outputs()).To(ContainSubstring("Note My golang note"))
103103
Expect(fakeUI.Outputs()).To(ContainSubstring("Public 0.232080 0.101300 20000"))
104-
Expect(fakeUI.Outputs()).To(ContainSubstring("RAM Micron / 8GB DDR4 1Rx8 / 2400 ECC NON Reg"))
104+
Expect(fakeUI.Outputs()).To(ContainSubstring("RAM Hynix / 16GB DDR4 "))
105105
})
106106
It("Price, Passwords, and Components", func() {
107107
err := testhelpers.RunCobraCommand(cliCommand.Command, "1234", "--passwords", "--price", "--components")
108108
Expect(err).NotTo(HaveOccurred())
109-
Expect(fakeUI.Outputs()).To(ContainSubstring("Administrator ThisPasswordISFake"))
110109
Expect(fakeUI.Outputs()).To(ContainSubstring("root FakePassword"))
111110
Expect(fakeUI.Outputs()).To(ContainSubstring("SN06 2023-02-19T06:00:07Z HARD_DRIVE"))
112111
Expect(fakeUI.Outputs()).To(ContainSubstring("Lenovo / 3943PAJ / Systemx3250-M6 / Intel Xeon SingleProc SATA / 1"))
@@ -115,6 +114,12 @@ var _ = Describe("hardware detail", func() {
115114
Expect(fakeUI.Outputs()).To(ContainSubstring("Datacenter dal10"))
116115
Expect(fakeUI.Outputs()).To(ContainSubstring("ID 218027"))
117116
})
117+
It("Trunkable Vlans", func() {
118+
err := testhelpers.RunCobraCommand(cliCommand.Command, "1001")
119+
Expect(err).NotTo(HaveOccurred())
120+
Expect(fakeUI.Outputs()).To(ContainSubstring("PUBLIC 974 3249384 dal10.fcr01.974 Trunked"))
121+
Expect(fakeUI.Outputs()).To(ContainSubstring("PRIVATE 886 2848186 - Primary"))
122+
})
118123
})
119124

120125
Context("Issue #649", func() {

plugin/commands/hardware/vlan_trunkable_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
"github.ibm.com/SoftLayer/softlayer-cli/plugin/testhelpers"
1313
)
1414

15-
var _ = Describe("VLAN-REMOVE Tests", func() {
15+
var _ = Describe("VLAN-TRUNKABLE Tests", func() {
1616
var (
1717
fakeUI *terminal.FakeUI
1818
cliCommand *hardware.VlanTrunkableCommand

plugin/managers/hardware.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ const (
2020
DEFAULT_SERVER_MASK = "mask[" + DEFAULT_HARDWARE_MASK + ",mask(SoftLayer_Hardware_Server)[activeTransaction[id,transactionStatus[name,friendlyName]]]]"
2121
DETAIL_HARDWARE_MASK = "id,globalIdentifier,fullyQualifiedDomainName,hostname,domain,provisionDate,hardwareStatus,processorPhysicalCoreAmount," +
2222
"memoryCapacity,notes,privateNetworkOnlyFlag,primaryBackendIpAddress,primaryIpAddress,networkManagementIpAddress,userData,datacenter," +
23-
"networkComponents[id,status,speed,maxSpeed,name,ipmiMacAddress,ipmiIpAddress,macAddress,primaryIpAddress,port," +
23+
"networkComponents[id,status,speed,maxSpeed,name,ipmiMacAddress,ipmiIpAddress,macAddress,primaryIpAddress,port,uplinkComponent[id,networkVlanTrunks[networkVlan]]," +
2424
"primarySubnet[id,netmask,broadcastAddress,networkIdentifier,gateway],uplinkComponent[networkVlanTrunks[networkVlan[networkSpace,vlanNumber,id,fullyQualifiedName]]]]" +
2525
",hardwareChassis[id,name],activeTransaction[id,transactionStatus[friendlyName,name]]," +
2626
"operatingSystem[softwareLicense[softwareDescription[manufacturer,name,version,referenceCode]],passwords[username,password]]," +
2727
"billingItem[id,nextInvoiceTotalRecurringAmount,children[nextInvoiceTotalRecurringAmount],nextInvoiceChildren[description,categoryCode,nextInvoiceTotalRecurringAmount],orderItem.order.userRecord[username]]," +
28-
"hourlyBillingFlag,tagReferences[id,tag[name,id]],networkVlans[id,vlanNumber,networkSpace],remoteManagementAccounts[username,password],lastTransaction[transactionGroup],activeComponents"
28+
"hourlyBillingFlag,tagReferences[id,tag[name,id]],networkVlans[id,vlanNumber,networkSpace,fullyQualifiedName],remoteManagementAccounts[username,password],lastTransaction[transactionGroup],activeComponents"
2929

3030
KEY_SIZES = "sizes"
3131
KEY_OS = "operating_systems"
@@ -304,7 +304,7 @@ func (hw hardwareServerManager) GetHardwareFast(hardwareId int) (datatypes.Hardw
304304
}()
305305
go func() {
306306
defer wg.Done()
307-
mask := "id,nextInvoiceTotalRecurringAmount,nextInvoiceChildren[id,nextInvoiceTotalRecurringAmount]," +
307+
mask := "id,nextInvoiceTotalRecurringAmount,nextInvoiceChildren[id,description,categoryCode,nextInvoiceTotalRecurringAmount]," +
308308
"orderItem[id,order[id,userRecord[id,username]]]"
309309
billingItem, err := hw.HardwareService.Id(hardwareId).Mask(mask).GetBillingItem()
310310
all_err = errors.Join(all_err, err)

plugin/resources/i18n_resources.go

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

0 commit comments

Comments
 (0)