Repository: softlayer/softlayer-python

Issue:
Hardware/Virtual server detail will break if they are in reclaim status
```
slcli vm detail XXXXX
also slcli hw detail XXX
    return callback(*args, **kwargs)
  File "/Users/***/venv/src/softlayer/SoftLayer/CLI/virt/detail.py", line 95, in cli
    bandwidth = vsi.get_bandwidth_allocation(vs_id)
  File "/Users/***/venv/src/softlayer/SoftLayer/managers/vs.py", line 1070, in get_bandwidth_allocation
    return {'allotment': allotment['allocation'], 'useage': useage}
TypeError: string indices must be integers, not str

Feel free to report this error as it is likely a bug:
    https://github.com/softlayer/softlayer-python/issues
The following snippet should be able to reproduce the error

```
**Please triple-check to make sure that you have properly masked out user credentials like usernames, passwords and API keys before submitting your issue**

### Expected Behavior

### Actual Behavior

### Environment Information
Operating System: Mac OSX 10.14
softlayer-python version (`slcli --version`):
v 5.7.2

Discussion:

Patch:
diff --git a/SoftLayer/CLI/hardware/detail.py b/SoftLayer/CLI/hardware/detail.py
index e254ad33..3a55f1b6 100644
--- a/SoftLayer/CLI/hardware/detail.py
+++ b/SoftLayer/CLI/hardware/detail.py
@@ -99,7 +99,9 @@ def _bw_table(bw_data):
         allotment = 'N/A'
         if bw_point['type']['alias'] == 'PUBLIC_SERVER_BW':
             bw_type = 'Public'
-            allotment = bw_data['allotment'].get('amount', '-')
+            allotment = utils.lookup(bw_data, 'allotment', 'amount')
+            if allotment is None:
+                allotment = '-'
 
         table.add_row([bw_type, bw_point['amountIn'], bw_point['amountOut'], allotment])
     return table
diff --git a/SoftLayer/CLI/virt/detail.py b/SoftLayer/CLI/virt/detail.py
index 53ae7e04..bf93a834 100644
--- a/SoftLayer/CLI/virt/detail.py
+++ b/SoftLayer/CLI/virt/detail.py
@@ -131,7 +131,9 @@ def _bw_table(bw_data):
         allotment = 'N/A'
         if bw_point['type']['alias'] == 'PUBLIC_SERVER_BW':
             bw_type = 'Public'
-            allotment = bw_data['allotment'].get('amount', '-')
+            allotment = utils.lookup(bw_data, 'allotment', 'amount')
+            if allotment is None:
+                allotment = '-'
 
         table.add_row([bw_type, bw_point['amountIn'], bw_point['amountOut'], allotment])
     return table
diff --git a/SoftLayer/managers/hardware.py b/SoftLayer/managers/hardware.py
index f5b01646..fb85c328 100644
--- a/SoftLayer/managers/hardware.py
+++ b/SoftLayer/managers/hardware.py
@@ -698,7 +698,7 @@ def get_bandwidth_allocation(self, instance_id):
         allotment = self.client.call('Hardware_Server', 'getBandwidthAllotmentDetail', id=instance_id, mask=a_mask)
         u_mask = "mask[amountIn,amountOut,type]"
         useage = self.client.call('Hardware_Server', 'getBillingCycleBandwidthUsage', id=instance_id, mask=u_mask)
-        return {'allotment': allotment['allocation'], 'useage': useage}
+        return {'allotment': allotment.get('allocation'), 'useage': useage}
 
 
 def _get_extra_price_id(items, key_name, hourly, location):
diff --git a/SoftLayer/managers/vs.py b/SoftLayer/managers/vs.py
index 85bbdf9d..de845096 100644
--- a/SoftLayer/managers/vs.py
+++ b/SoftLayer/managers/vs.py
@@ -1067,7 +1067,7 @@ def get_bandwidth_allocation(self, instance_id):
         allotment = self.client.call('Virtual_Guest', 'getBandwidthAllotmentDetail', id=instance_id, mask=a_mask)
         u_mask = "mask[amountIn,amountOut,type]"
         useage = self.client.call('Virtual_Guest', 'getBillingCycleBandwidthUsage', id=instance_id, mask=u_mask)
-        return {'allotment': allotment['allocation'], 'useage': useage}
+        return {'allotment': allotment.get('allocation'), 'useage': useage}
 
     # pylint: disable=inconsistent-return-statements
     def _get_price_id_for_upgrade(self, package_items, option, value, public=True):


Test patch:
diff --git a/tests/managers/hardware_tests.py b/tests/managers/hardware_tests.py
index 120f6060..7cff1130 100644
--- a/tests/managers/hardware_tests.py
+++ b/tests/managers/hardware_tests.py
@@ -448,6 +448,14 @@ def test_get_bandwidth_allocation(self):
         self.assertEqual(result['allotment']['amount'], '250')
         self.assertEqual(result['useage'][0]['amountIn'], '.448')
 
+    def test_get_bandwidth_allocation_no_allotment(self):
+        mock = self.set_mock('SoftLayer_Hardware_Server', 'getBandwidthAllotmentDetail')
+        mock.return_value = {}
+
+        result = self.hardware.get_bandwidth_allocation(1234)
+
+        self.assertEqual(None, result['allotment'])
+
 
 class HardwareHelperTests(testing.TestCase):
     def test_get_extra_price_id_no_items(self):
diff --git a/tests/managers/vs/vs_tests.py b/tests/managers/vs/vs_tests.py
index 2816f8b0..14d41966 100644
--- a/tests/managers/vs/vs_tests.py
+++ b/tests/managers/vs/vs_tests.py
@@ -903,3 +903,11 @@ def test_get_bandwidth_allocation(self):
         self.assert_called_with('SoftLayer_Virtual_Guest', 'getBillingCycleBandwidthUsage', identifier=1234)
         self.assertEqual(result['allotment']['amount'], '250')
         self.assertEqual(result['useage'][0]['amountIn'], '.448')
+
+    def test_get_bandwidth_allocation_no_allotment(self):
+        mock = self.set_mock('SoftLayer_Virtual_Guest', 'getBandwidthAllotmentDetail')
+        mock.return_value = {}
+
+        result = self.vs.get_bandwidth_allocation(1234)
+
+        self.assertEqual(None, result['allotment'])