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" )})
0 commit comments