Repository: softlayer/softlayer-python
Pull request #1208 (2020-01-13 21:53:04)

Functionality for VolumeLimit per DataCenter
feature/VolumeLimit Added the functionality for Volume Limit per Datacenter.


Patch:
diff --git a/SoftLayer/CLI/block/limit.py b/SoftLayer/CLI/block/limit.py
new file mode 100644
index 00000000..13d22c8c
--- /dev/null
+++ b/SoftLayer/CLI/block/limit.py
@@ -0,0 +1,31 @@
+"""List number of block storage volumes limit per datacenter."""
+# :license: MIT, see LICENSE for more details.
+
+import click
+import SoftLayer
+from SoftLayer.CLI import environment
+from SoftLayer.CLI import formatting
+
+DEFAULT_COLUMNS = [
+    'Datacenter',
+    'MaximumAvailableCount',
+    'ProvisionedCount'
+]
+
+
+@click.command()
+@click.option('--sortby', help='Column to sort by', default='Datacenter')
+@environment.pass_env
+def cli(env, sortby):
+    """List number of block storage volumes limit per datacenter."""
+    block_manager = SoftLayer.BlockStorageManager(env.client)
+    block_volumes = block_manager.list_block_volume_limit()
+
+    table = formatting.KeyValueTable(DEFAULT_COLUMNS)
+    table.sortby = sortby
+    for volume in block_volumes:
+        datacenter_name = volume['datacenterName']
+        maximum_available_count = volume['maximumAvailableCount']
+        provisioned_count = volume['provisionedCount']
+        table.add_row([datacenter_name, maximum_available_count, provisioned_count])
+    env.fout(table)
diff --git a/SoftLayer/CLI/file/limit.py b/SoftLayer/CLI/file/limit.py
new file mode 100644
index 00000000..34dca756
--- /dev/null
+++ b/SoftLayer/CLI/file/limit.py
@@ -0,0 +1,31 @@
+"""List number of file storage volumes limit per datacenter."""
+# :license: MIT, see LICENSE for more details.
+
+import click
+import SoftLayer
+from SoftLayer.CLI import environment
+from SoftLayer.CLI import formatting
+
+DEFAULT_COLUMNS = [
+    'Datacenter',
+    'MaximumAvailableCount',
+    'ProvisionedCount'
+]
+
+
+@click.command()
+@click.option('--sortby', help='Column to sort by', default='Datacenter')
+@environment.pass_env
+def cli(env, sortby):
+    """List number of block storage volumes limit per datacenter."""
+    file_manager = SoftLayer.FileStorageManager(env.client)
+    file_volumes = file_manager.list_file_volume_limit()
+
+    table = formatting.KeyValueTable(DEFAULT_COLUMNS)
+    table.sortby = sortby
+    for volume in file_volumes:
+        datacenter_name = volume['datacenterName']
+        maximum_available_count = volume['maximumAvailableCount']
+        provisioned_count = volume['provisionedCount']
+        table.add_row([datacenter_name, maximum_available_count, provisioned_count])
+    env.fout(table)
diff --git a/SoftLayer/CLI/routes.py b/SoftLayer/CLI/routes.py
index 5c37541d..cb81c5c5 100644
--- a/SoftLayer/CLI/routes.py
+++ b/SoftLayer/CLI/routes.py
@@ -102,6 +102,7 @@
     ('block:volume-modify', 'SoftLayer.CLI.block.modify:cli'),
     ('block:volume-order', 'SoftLayer.CLI.block.order:cli'),
     ('block:volume-set-lun-id', 'SoftLayer.CLI.block.lun:cli'),
+    ('block:volume-limits', 'SoftLayer.CLI.block.limit:cli'),
 
     ('event-log', 'SoftLayer.CLI.event_log'),
     ('event-log:get', 'SoftLayer.CLI.event_log.get:cli'),
@@ -132,6 +133,7 @@
     ('file:volume-list', 'SoftLayer.CLI.file.list:cli'),
     ('file:volume-modify', 'SoftLayer.CLI.file.modify:cli'),
     ('file:volume-order', 'SoftLayer.CLI.file.order:cli'),
+    ('file:volume-limits', 'SoftLayer.CLI.file.limit:cli'),
 
     ('firewall', 'SoftLayer.CLI.firewall'),
     ('firewall:add', 'SoftLayer.CLI.firewall.add:cli'),
diff --git a/SoftLayer/fixtures/SoftLayer_Network_Storage.py b/SoftLayer/fixtures/SoftLayer_Network_Storage.py
index 8a0c9772..3c8d335e 100644
--- a/SoftLayer/fixtures/SoftLayer_Network_Storage.py
+++ b/SoftLayer/fixtures/SoftLayer_Network_Storage.py
@@ -226,3 +226,9 @@
 
 enableSnapshots = True
 disableSnapshots = True
+
+getVolumeCountLimits = {
+    'datacenterName': 'global',
+    'maximumAvailableCount': 300,
+    'provisionedCount': 100
+}
diff --git a/SoftLayer/managers/block.py b/SoftLayer/managers/block.py
index 1f8c6ec5..fe1b203b 100644
--- a/SoftLayer/managers/block.py
+++ b/SoftLayer/managers/block.py
@@ -24,6 +24,13 @@ def __init__(self, client):
         self.configuration = {}
         self.client = client
 
+    def list_block_volume_limit(self):
+        """Returns a list of block volume count limit.
+
+        :return: Returns a list of block volume count limit.
+        """
+        return self.client.call('Network_Storage', 'getVolumeCountLimits')
+
     def list_block_volumes(self, datacenter=None, username=None,
                            storage_type=None, **kwargs):
         """Returns a list of block volumes.
diff --git a/SoftLayer/managers/file.py b/SoftLayer/managers/file.py
index c0d8fcae..95cf85c8 100644
--- a/SoftLayer/managers/file.py
+++ b/SoftLayer/managers/file.py
@@ -19,6 +19,13 @@ def __init__(self, client):
         self.configuration = {}
         self.client = client
 
+    def list_file_volume_limit(self):
+        """Returns a list of file volume count limit.
+
+        :return: Returns a list of file volume count limit.
+        """
+        return self.client.call('Network_Storage', 'getVolumeCountLimits')
+
     def list_file_volumes(self, datacenter=None, username=None,
                           storage_type=None, **kwargs):
         """Returns a list of file volumes.


Test patch:
diff --git a/tests/CLI/modules/block_tests.py b/tests/CLI/modules/block_tests.py
index b8629de8..47ffda2b 100644
--- a/tests/CLI/modules/block_tests.py
+++ b/tests/CLI/modules/block_tests.py
@@ -665,3 +665,15 @@ def test_modify_order(self, order_mock):
     def test_set_password(self):
         result = self.run_command(['block', 'access-password', '1234', '--password=AAAAA'])
         self.assert_no_fail(result)
+
+    @mock.patch('SoftLayer.BlockStorageManager.list_block_volume_limit')
+    def test_volume_limit(self, list_mock):
+        list_mock.return_value = [
+            {
+                "datacenterName": "global",
+                "maximumAvailableCount": 300,
+                "provisionedCount": 100
+            }]
+
+        result = self.run_command(['block', 'volume-limits'])
+        self.assert_no_fail(result)
diff --git a/tests/CLI/modules/file_tests.py b/tests/CLI/modules/file_tests.py
index f64b1962..0fc4ffc0 100644
--- a/tests/CLI/modules/file_tests.py
+++ b/tests/CLI/modules/file_tests.py
@@ -665,3 +665,14 @@ def test_modify_order(self, order_mock):
         self.assert_no_fail(result)
         self.assertEqual('Order #24602 placed successfully!\n > Storage as a Service\n > 1000 GBs\n > 4 IOPS per GB\n',
                          result.output)
+
+    @mock.patch('SoftLayer.FileStorageManager.list_file_volume_limit')
+    def test_volume_limit(self, list_mock):
+        list_mock.return_value = [
+            {
+                'datacenterName': 'global',
+                'maximumAvailableCount': 300,
+                'provisionedCount': 100
+            }]
+        result = self.run_command(['file', 'volume-limits'])
+        self.assert_no_fail(result)
diff --git a/tests/managers/block_tests.py b/tests/managers/block_tests.py
index f5b3b437..280460c2 100644
--- a/tests/managers/block_tests.py
+++ b/tests/managers/block_tests.py
@@ -936,3 +936,7 @@ def test_setCredentialPassword(self):
         result = self.block.set_credential_password(access_id=102, password='AAAaaa')
         self.assertEqual(True, result)
         self.assert_called_with('SoftLayer_Network_Storage_Allowed_Host', 'setCredentialPassword')
+
+    def test_list_block_volume_limit(self):
+        result = self.block.list_block_volume_limit()
+        self.assertEqual(fixtures.SoftLayer_Network_Storage.getVolumeCountLimits, result)
diff --git a/tests/managers/cdn_tests.py b/tests/managers/cdn_tests.py
index 31c3c4fa..32f9ea9e 100644
--- a/tests/managers/cdn_tests.py
+++ b/tests/managers/cdn_tests.py
@@ -49,16 +49,16 @@ def test_add_origin(self):
                                    cache_query="include all")
 
         args = ({
-                    'uniqueId': "12345",
-                    'origin': '10.10.10.1',
-                    'path': '/example/videos',
+            'uniqueId': "12345",
+            'origin': '10.10.10.1',
+            'path': '/example/videos',
                     'originType': 'HOST_SERVER',
                     'header': 'test.example.com',
                     'httpPort': 80,
                     'protocol': 'HTTP',
                     'performanceConfiguration': 'General web delivery',
                     'cacheKeyQueryRule': "include all"
-                },)
+        },)
         self.assert_called_with('SoftLayer_Network_CdnMarketplace_Configuration_Mapping_Path',
                                 'createOriginPath',
                                 args=args)
@@ -69,9 +69,9 @@ def test_add_origin_with_bucket_and_file_extension(self):
                                    protocol='http', optimize_for="web", cache_query="include all")
 
         args = ({
-                    'uniqueId': "12345",
-                    'origin': '10.10.10.1',
-                    'path': '/example/videos',
+            'uniqueId': "12345",
+            'origin': '10.10.10.1',
+            'path': '/example/videos',
                     'originType': 'OBJECT_STORAGE',
                     'header': 'test.example.com',
                     'httpPort': 80,
@@ -80,7 +80,7 @@ def test_add_origin_with_bucket_and_file_extension(self):
                     'fileExtension': 'jpg',
                     'performanceConfiguration': 'General web delivery',
                     'cacheKeyQueryRule': "include all"
-                },)
+        },)
         self.assert_called_with('SoftLayer_Network_CdnMarketplace_Configuration_Mapping_Path',
                                 'createOriginPath',
                                 args=args)
diff --git a/tests/managers/file_tests.py b/tests/managers/file_tests.py
index 9e69d7fc..d6ca66c6 100644
--- a/tests/managers/file_tests.py
+++ b/tests/managers/file_tests.py
@@ -668,7 +668,6 @@ def test_order_file_duplicate_performance_no_duplicate_snapshot(self):
     def test_order_file_duplicate_performance(self):
         mock = self.set_mock('SoftLayer_Product_Package', 'getAllObjects')
         mock.return_value = [fixtures.SoftLayer_Product_Package.SAAS_PACKAGE]
-
         mock_volume = copy.deepcopy(fixtures.SoftLayer_Network_Storage.STAAS_TEST_VOLUME)
         mock_volume['storageType']['keyName'] = 'PERFORMANCE_FILE_STORAGE'
         mock = self.set_mock('SoftLayer_Network_Storage', 'getObject')
@@ -829,3 +828,7 @@ def test_order_file_modified_endurance(self):
                    'volume': {'id': 102},
                    'volumeSize': 1000},)
         )
+
+    def test_list_file_volume_limit(self):
+        result = self.file.list_file_volume_limit()
+        self.assertEqual(fixtures.SoftLayer_Network_Storage.getVolumeCountLimits, result)
diff --git a/tests/managers/ordering_tests.py b/tests/managers/ordering_tests.py
index 35d5b819..045517cd 100644
--- a/tests/managers/ordering_tests.py
+++ b/tests/managers/ordering_tests.py
@@ -722,7 +722,7 @@ def test_get_item_capacity_core(self):
                 "capacity": "1",
                 "id": 10201,
                 "keyName": "GUEST_CORE_1_DEDICATED",
-            }]
+        }]
 
         item_capacity = self.ordering.get_item_capacity(items, ['GUEST_CORE_1_DEDICATED', 'OS_RHEL_7_X_LAMP_64_BIT'])
 
@@ -739,7 +739,7 @@ def test_get_item_capacity_storage(self):
                 "capacity": "1",
                 "id": 10201,
                 "keyName": "READHEAVY_TIER",
-            }]
+        }]
 
         item_capacity = self.ordering.get_item_capacity(items, ['READHEAVY_TIER', 'STORAGE_SPACE_FOR_2_IOPS_PER_GB'])