Repository: softlayer/softlayer-python
Pull request #1218 (2020-01-27 15:02:14)

fix the issue 1217 about globalip create ipv6
https://github.com/softlayer/softlayer-python/issues/1217


Patch:
diff --git a/SoftLayer/CLI/globalip/create.py b/SoftLayer/CLI/globalip/create.py
index a47c1eb7..339d290c 100644
--- a/SoftLayer/CLI/globalip/create.py
+++ b/SoftLayer/CLI/globalip/create.py
@@ -10,7 +10,7 @@
 
 
 @click.command()
-@click.option('--v6', '--ipv6', is_flag=True, help='Order a IPv6 IP')
+@click.option('-v6', '--ipv6', is_flag=True, help='Order a IPv6 IP')
 @click.option('--test', help='test order')
 @environment.pass_env
 def cli(env, ipv6, test):
diff --git a/SoftLayer/CLI/virt/detail.py b/SoftLayer/CLI/virt/detail.py
index 131117df..bf93a834 100644
--- a/SoftLayer/CLI/virt/detail.py
+++ b/SoftLayer/CLI/virt/detail.py
@@ -126,15 +126,14 @@ def cli(env, identifier, passwords=False, price=False):
 def _bw_table(bw_data):
     """Generates a bandwidth useage table"""
     table = formatting.Table(['Type', 'In GB', 'Out GB', 'Allotment'])
-    for bw_point in bw_data.get('usage'):
+    for bw_point in bw_data.get('useage'):
         bw_type = 'Private'
         allotment = 'N/A'
         if bw_point['type']['alias'] == 'PUBLIC_SERVER_BW':
             bw_type = 'Public'
-            if not bw_data.get('allotment'):
+            allotment = utils.lookup(bw_data, 'allotment', 'amount')
+            if allotment is None:
                 allotment = '-'
-            else:
-                allotment = utils.lookup(bw_data, 'allotment', 'amount')
 
         table.add_row([bw_type, bw_point['amountIn'], bw_point['amountOut'], allotment])
     return table
diff --git a/SoftLayer/managers/vs.py b/SoftLayer/managers/vs.py
index b1391bc3..24a264b7 100644
--- a/SoftLayer/managers/vs.py
+++ b/SoftLayer/managers/vs.py
@@ -1074,10 +1074,8 @@ def get_bandwidth_allocation(self, instance_id):
         a_mask = "mask[allocation[amount]]"
         allotment = self.client.call('Virtual_Guest', 'getBandwidthAllotmentDetail', id=instance_id, mask=a_mask)
         u_mask = "mask[amountIn,amountOut,type]"
-        usage = self.client.call('Virtual_Guest', 'getBillingCycleBandwidthUsage', id=instance_id, mask=u_mask)
-        if allotment:
-            return {'allotment': allotment.get('allocation'), 'usage': usage}
-        return {'allotment': allotment, 'usage': usage}
+        useage = self.client.call('Virtual_Guest', 'getBillingCycleBandwidthUsage', id=instance_id, mask=u_mask)
+        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/CLI/modules/vs/vs_tests.py b/tests/CLI/modules/vs/vs_tests.py
index 2c79f42b..3e57cb20 100644
--- a/tests/CLI/modules/vs/vs_tests.py
+++ b/tests/CLI/modules/vs/vs_tests.py
@@ -205,17 +205,6 @@ def test_detail_vs_empty_tag(self):
             ['example-tag'],
         )
 
-    def test_detail_vs_empty_allotment(self):
-        mock = self.set_mock('SoftLayer_Virtual_Guest', 'getBandwidthAllotmentDetail')
-        mock.return_value = None
-        result = self.run_command(['vs', 'detail', '100'])
-
-        self.assert_no_fail(result)
-        self.assertEqual(
-            json.loads(result.output)['Bandwidth'][0]['Allotment'],
-            '-',
-        )
-
     def test_detail_vs_dedicated_host_not_found(self):
         ex = SoftLayerAPIError('SoftLayer_Exception', 'Not found')
         mock = self.set_mock('SoftLayer_Virtual_DedicatedHost', 'getObject')
diff --git a/tests/managers/vs/vs_tests.py b/tests/managers/vs/vs_tests.py
index 47fcaf20..14d41966 100644
--- a/tests/managers/vs/vs_tests.py
+++ b/tests/managers/vs/vs_tests.py
@@ -902,26 +902,12 @@ def test_get_bandwidth_allocation(self):
         self.assert_called_with('SoftLayer_Virtual_Guest', 'getBandwidthAllotmentDetail', identifier=1234)
         self.assert_called_with('SoftLayer_Virtual_Guest', 'getBillingCycleBandwidthUsage', identifier=1234)
         self.assertEqual(result['allotment']['amount'], '250')
-        self.assertEqual(result['usage'][0]['amountIn'], '.448')
+        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 = None
+        mock.return_value = {}
 
         result = self.vs.get_bandwidth_allocation(1234)
 
         self.assertEqual(None, result['allotment'])
-
-    def test_get_bandwidth_allocation_with_allotment(self):
-        mock = self.set_mock('SoftLayer_Virtual_Guest', 'getBandwidthAllotmentDetail')
-        mock.return_value = {
-            "allocationId": 11111,
-            "id": 22222,
-            "allocation": {
-                "amount": "2000"
-            }
-        }
-
-        result = self.vs.get_bandwidth_allocation(1234)
-
-        self.assertEqual(2000, int(result['allotment']['amount']))