Repository: softlayer/softlayer-python
Pull request #1662 (2022-06-07 22:14:46)

add a new feature to get all cloud object storage
[#issue1659](https://github.com/softlayer/softlayer-python/issues/1659)

```
slcli block object-list
┌───────────┬───────────────┬─────────────────────────────────┬───────────────────────────┬─────────────────────────┐
│    Id     │ Account name  │           Description           │        Create Date        │          Type           │
├───────────┼───────────────┼─────────────────────────────────┼───────────────────────────┼─────────────────────────┤
│ 176367162 │ SLOSC307608-1 │ Object Storage Standard Account │ 2020-10-08T11:45:17-06:00 │ OBJECT_STORAGE_STANDARD │
└───────────┴───────────────┴─────────────────────────────────┴───────────────────────────┴─────────────────────────┘
```


Patch:
diff --git a/SoftLayer/CLI/block/object_list.py b/SoftLayer/CLI/block/object_list.py
new file mode 100644
index 00000000..dd677929
--- /dev/null
+++ b/SoftLayer/CLI/block/object_list.py
@@ -0,0 +1,31 @@
+"""List cloud object storage volumes."""
+# :license: MIT, see LICENSE for more details.
+
+import click
+
+import SoftLayer
+from SoftLayer.CLI import environment
+from SoftLayer.CLI import formatting
+
+
+@click.command(cls=SoftLayer.CLI.command.SLCommand, )
+@environment.pass_env
+def cli(env):
+    """List cloud block storage."""
+    block_manager = SoftLayer.BlockStorageManager(env.client)
+
+    storages = block_manager.get_cloud_list()
+
+    table = formatting.Table(['Id',
+                              'Account name',
+                              'Description',
+                              'Create Date',
+                              'Type'])
+    for storage in storages:
+        table.add_row([storage.get('id'),
+                       storage.get('username'),
+                       storage['storageType']['description'],
+                       storage['billingItem']['createDate'],
+                       storage['storageType']['keyName']])
+
+    env.fout(table)
diff --git a/SoftLayer/CLI/routes.py b/SoftLayer/CLI/routes.py
index e6d34282..a9f64d84 100644
--- a/SoftLayer/CLI/routes.py
+++ b/SoftLayer/CLI/routes.py
@@ -126,6 +126,7 @@
     ('block:volume-refresh', 'SoftLayer.CLI.block.refresh:cli'),
     ('block:volume-convert', 'SoftLayer.CLI.block.convert:cli'),
     ('block:volume-set-note', 'SoftLayer.CLI.block.set_note:cli'),
+    ('block:object-list', 'SoftLayer.CLI.block.object_list:cli'),
 
     ('email', 'SoftLayer.CLI.email'),
     ('email:list', 'SoftLayer.CLI.email.list:cli'),
diff --git a/SoftLayer/fixtures/SoftLayer_Account.py b/SoftLayer/fixtures/SoftLayer_Account.py
index b7874496..28359b7d 100644
--- a/SoftLayer/fixtures/SoftLayer_Account.py
+++ b/SoftLayer/fixtures/SoftLayer_Account.py
@@ -647,8 +647,36 @@
 
 getNextInvoiceTotalAmount = 2
 
-getHubNetworkStorage = [{'id': 12345, 'username': 'SLOS12345-1', 'serviceResource': {'name': 'Cleversafe - US Region'}},
-                        {'id': 12346, 'username': 'SLOS12345-2', 'vendorName': 'Swift'}]
+getHubNetworkStorage = [
+    {
+        "id": 12345,
+        "username": "SLOS12345-1",
+        "billingItem": {
+            "createDate": "2020-10-08T11:45:17-06:00"
+        },
+        "serviceResource": {
+            "name": "Cleversafe - US Region"
+        },
+        "storageType": {
+            "description": "Object Storage Standard Account",
+            "id": 24,
+            "keyName": "OBJECT_STORAGE_STANDARD"
+        }
+    },
+    {
+        "id": 12346,
+        "username": "SLOS12345-2",
+        "vendorName": "Swift",
+        "billingItem": {
+            "createDate": "2020-10-08T11:45:17-06:00"
+        },
+        "storageType": {
+            "description": "Object Storage Standard Account",
+            "id": 24,
+            "keyName": "OBJECT_STORAGE_STANDARD"
+        }
+    }
+]
 
 getIscsiNetworkStorage = [{
     'accountId': 1234,
diff --git a/SoftLayer/managers/block.py b/SoftLayer/managers/block.py
index 871c9cb2..26094145 100644
--- a/SoftLayer/managers/block.py
+++ b/SoftLayer/managers/block.py
@@ -9,6 +9,7 @@
 from SoftLayer.managers import storage_utils
 from SoftLayer import utils
 
+
 # pylint: disable=too-many-public-methods
 
 
@@ -196,3 +197,13 @@ def _get_ids_from_username(self, username):
         if results:
             return [result['id'] for result in results]
         return []
+
+    def get_cloud_list(self):
+        """Returns a list cloud object storage.
+
+        return: Returns a list cloud object storage.
+        """
+
+        mask = 'mask[id,username,billingItem,storageType, notes]'
+
+        return self.client.call('Account', 'getHubNetworkStorage', mask=mask)
diff --git a/docs/cli/block.rst b/docs/cli/block.rst
index 2c2499ab..799070b5 100644
--- a/docs/cli/block.rst
+++ b/docs/cli/block.rst
@@ -156,6 +156,10 @@ Block Commands
     :prog: block snapshot-get-notification-status
     :show-nested:
 
+.. click:: SoftLayer.CLI.block.object_list:cli
+    :prog: block object-list
+    :show-nested:
+
 .. click:: SoftLayer.CLI.block.duplicate_convert_status:cli
     :prog: block duplicate-convert-status
     :show-nested:


Test patch:
diff --git a/tests/CLI/modules/block_tests.py b/tests/CLI/modules/block_tests.py
index 8241087b..f909683a 100644
--- a/tests/CLI/modules/block_tests.py
+++ b/tests/CLI/modules/block_tests.py
@@ -819,3 +819,9 @@ def test_snapshot_get_notification_status(self, status):
             result = self.run_command(['block', 'snapshot-get-notification-status', '999'])
             self.assert_no_fail(result)
             self.assertIn(expect, result.output)
+
+    def test_object_list(self):
+        result = self.run_command(['block', 'object-list'])
+
+        self.assert_no_fail(result)
+        self.assert_called_with('SoftLayer_Account', 'getHubNetworkStorage')
diff --git a/tests/managers/block_tests.py b/tests/managers/block_tests.py
index 8dc1cd83..85481331 100644
--- a/tests/managers/block_tests.py
+++ b/tests/managers/block_tests.py
@@ -452,22 +452,22 @@ def test_order_block_volume_performance(self):
             'SoftLayer_Product_Order',
             'placeOrder',
             args=({
-                'complexType': 'SoftLayer_Container_Product_Order_'
-                'Network_Storage_AsAService',
-                'packageId': 759,
-                'prices': [
-                    {'id': 189433},
-                    {'id': 189443},
-                    {'id': 190113},
-                    {'id': 190173}
-                ],
-                'volumeSize': 1000,
-                'quantity': 1,
-                'location': 449494,
-                'iops': 2000,
-                'useHourlyPricing': False,
-                'osFormatType': {'keyName': 'LINUX'}
-            },)
+                      'complexType': 'SoftLayer_Container_Product_Order_'
+                                     'Network_Storage_AsAService',
+                      'packageId': 759,
+                      'prices': [
+                          {'id': 189433},
+                          {'id': 189443},
+                          {'id': 190113},
+                          {'id': 190173}
+                      ],
+                      'volumeSize': 1000,
+                      'quantity': 1,
+                      'location': 449494,
+                      'iops': 2000,
+                      'useHourlyPricing': False,
+                      'osFormatType': {'keyName': 'LINUX'}
+                  },)
         )
 
     def test_order_block_volume_endurance(self):
@@ -496,21 +496,21 @@ def test_order_block_volume_endurance(self):
             'SoftLayer_Product_Order',
             'placeOrder',
             args=({
-                'complexType': 'SoftLayer_Container_Product_Order_'
-                'Network_Storage_AsAService',
-                'packageId': 759,
-                'prices': [
-                    {'id': 189433},
-                    {'id': 189443},
-                    {'id': 194763},
-                    {'id': 194703}
-                ],
-                'volumeSize': 1000,
-                'quantity': 1,
-                'location': 449494,
-                'useHourlyPricing': False,
-                'osFormatType': {'keyName': 'LINUX'}
-            },)
+                      'complexType': 'SoftLayer_Container_Product_Order_'
+                                     'Network_Storage_AsAService',
+                      'packageId': 759,
+                      'prices': [
+                          {'id': 189433},
+                          {'id': 189443},
+                          {'id': 194763},
+                          {'id': 194703}
+                      ],
+                      'volumeSize': 1000,
+                      'quantity': 1,
+                      'location': 449494,
+                      'useHourlyPricing': False,
+                      'osFormatType': {'keyName': 'LINUX'}
+                  },)
         )
 
     def test_authorize_host_to_volume(self):
@@ -657,17 +657,17 @@ def test_order_block_snapshot_space_upgrade(self):
             'SoftLayer_Product_Order',
             'placeOrder',
             args=({
-                'complexType': 'SoftLayer_Container_Product_Order_Network_'
-                'Storage_Enterprise_SnapshotSpace_Upgrade',
-                'packageId': 759,
-                'prices': [
-                    {'id': 193853}
-                ],
-                'quantity': 1,
-                'location': 449500,
-                'volumeId': 102,
-                'useHourlyPricing': False
-            },)
+                      'complexType': 'SoftLayer_Container_Product_Order_Network_'
+                                     'Storage_Enterprise_SnapshotSpace_Upgrade',
+                      'packageId': 759,
+                      'prices': [
+                          {'id': 193853}
+                      ],
+                      'quantity': 1,
+                      'location': 449500,
+                      'volumeId': 102,
+                      'useHourlyPricing': False
+                  },)
         )
 
     def test_order_block_snapshot_space(self):
@@ -686,17 +686,17 @@ def test_order_block_snapshot_space(self):
             'SoftLayer_Product_Order',
             'placeOrder',
             args=({
-                'complexType': 'SoftLayer_Container_Product_Order_Network_'
-                'Storage_Enterprise_SnapshotSpace',
-                'packageId': 759,
-                'prices': [
-                    {'id': 193613}
-                ],
-                'quantity': 1,
-                'location': 449500,
-                'volumeId': 102,
-                'useHourlyPricing': False
-            },)
+                      'complexType': 'SoftLayer_Container_Product_Order_Network_'
+                                     'Storage_Enterprise_SnapshotSpace',
+                      'packageId': 759,
+                      'prices': [
+                          {'id': 193613}
+                      ],
+                      'quantity': 1,
+                      'location': 449500,
+                      'volumeId': 102,
+                      'useHourlyPricing': False
+                  },)
         )
 
     def test_order_block_replicant_os_type_not_found(self):
@@ -745,26 +745,26 @@ def test_order_block_replicant_performance_os_type_given(self):
             'SoftLayer_Product_Order',
             'placeOrder',
             args=({
-                'complexType': 'SoftLayer_Container_Product_Order_'
-                'Network_Storage_AsAService',
-                'packageId': 759,
-                'prices': [
-                    {'id': 189433},
-                    {'id': 189443},
-                    {'id': 189993},
-                    {'id': 190053},
-                    {'id': 191193},
-                    {'id': 192033}
-                ],
-                'volumeSize': 500,
-                'quantity': 1,
-                'location': 449494,
-                'iops': 1000,
-                'originVolumeId': 102,
-                'originVolumeScheduleId': 978,
-                'useHourlyPricing': False,
-                'osFormatType': {'keyName': 'XEN'}
-            },)
+                      'complexType': 'SoftLayer_Container_Product_Order_'
+                                     'Network_Storage_AsAService',
+                      'packageId': 759,
+                      'prices': [
+                          {'id': 189433},
+                          {'id': 189443},
+                          {'id': 189993},
+                          {'id': 190053},
+                          {'id': 191193},
+                          {'id': 192033}
+                      ],
+                      'volumeSize': 500,
+                      'quantity': 1,
+                      'location': 449494,
+                      'iops': 1000,
+                      'originVolumeId': 102,
+                      'originVolumeScheduleId': 978,
+                      'useHourlyPricing': False,
+                      'osFormatType': {'keyName': 'XEN'}
+                  },)
         )
 
     def test_order_block_replicant_endurance(self):
@@ -786,25 +786,25 @@ def test_order_block_replicant_endurance(self):
             'SoftLayer_Product_Order',
             'placeOrder',
             args=({
-                'complexType': 'SoftLayer_Container_Product_Order_'
-                'Network_Storage_AsAService',
-                'packageId': 759,
-                'prices': [
-                    {'id': 189433},
-                    {'id': 189443},
-                    {'id': 193433},
-                    {'id': 193373},
-                    {'id': 193613},
-                    {'id': 194693}
-                ],
-                'volumeSize': 500,
-                'quantity': 1,
-                'location': 449494,
-                'originVolumeId': 102,
-                'originVolumeScheduleId': 978,
-                'useHourlyPricing': False,
-                'osFormatType': {'keyName': 'LINUX'}
-            },)
+                      'complexType': 'SoftLayer_Container_Product_Order_'
+                                     'Network_Storage_AsAService',
+                      'packageId': 759,
+                      'prices': [
+                          {'id': 189433},
+                          {'id': 189443},
+                          {'id': 193433},
+                          {'id': 193373},
+                          {'id': 193613},
+                          {'id': 194693}
+                      ],
+                      'volumeSize': 500,
+                      'quantity': 1,
+                      'location': 449494,
+                      'originVolumeId': 102,
+                      'originVolumeScheduleId': 978,
+                      'useHourlyPricing': False,
+                      'osFormatType': {'keyName': 'LINUX'}
+                  },)
         )
 
     def test_order_block_duplicate_origin_os_type_not_found(self):
@@ -844,23 +844,23 @@ def test_order_block_duplicate_performance_no_duplicate_snapshot(self):
             'SoftLayer_Product_Order',
             'placeOrder',
             args=({
-                'complexType': 'SoftLayer_Container_Product_Order_'
-                'Network_Storage_AsAService',
-                'packageId': 759,
-                'prices': [
-                    {'id': 189433},
-                    {'id': 189443},
-                    {'id': 189993},
-                    {'id': 190053}
-                ],
-                'volumeSize': 500,
-                'quantity': 1,
-                'location': 449500,
-                'duplicateOriginVolumeId': 102,
-                'osFormatType': {'keyName': 'LINUX'},
-                'iops': 1000,
-                'useHourlyPricing': False
-            },))
+                      'complexType': 'SoftLayer_Container_Product_Order_'
+                                     'Network_Storage_AsAService',
+                      'packageId': 759,
+                      'prices': [
+                          {'id': 189433},
+                          {'id': 189443},
+                          {'id': 189993},
+                          {'id': 190053}
+                      ],
+                      'volumeSize': 500,
+                      'quantity': 1,
+                      'location': 449500,
+                      'duplicateOriginVolumeId': 102,
+                      'osFormatType': {'keyName': 'LINUX'},
+                      'iops': 1000,
+                      'useHourlyPricing': False
+                  },))
 
     def test_order_block_duplicate_performance(self):
         mock = self.set_mock('SoftLayer_Product_Package', 'getAllObjects')
@@ -886,25 +886,25 @@ def test_order_block_duplicate_performance(self):
             'SoftLayer_Product_Order',
             'placeOrder',
             args=({
-                'complexType': 'SoftLayer_Container_Product_Order_'
-                'Network_Storage_AsAService',
-                'packageId': 759,
-                'prices': [
-                    {'id': 189433},
-                    {'id': 189443},
-                    {'id': 190113},
-                    {'id': 190173},
-                    {'id': 191193}
-                ],
-                'volumeSize': 1000,
-                'quantity': 1,
-                'location': 449500,
-                'duplicateOriginVolumeId': 102,
-                'osFormatType': {'keyName': 'LINUX'},
-                'duplicateOriginSnapshotId': 470,
-                'iops': 2000,
-                'useHourlyPricing': False
-            },))
+                      'complexType': 'SoftLayer_Container_Product_Order_'
+                                     'Network_Storage_AsAService',
+                      'packageId': 759,
+                      'prices': [
+                          {'id': 189433},
+                          {'id': 189443},
+                          {'id': 190113},
+                          {'id': 190173},
+                          {'id': 191193}
+                      ],
+                      'volumeSize': 1000,
+                      'quantity': 1,
+                      'location': 449500,
+                      'duplicateOriginVolumeId': 102,
+                      'osFormatType': {'keyName': 'LINUX'},
+                      'duplicateOriginSnapshotId': 470,
+                      'iops': 2000,
+                      'useHourlyPricing': False
+                  },))
 
     def test_order_block_duplicate_depdupe(self):
         mock = self.set_mock('SoftLayer_Product_Package', 'getAllObjects')
@@ -931,26 +931,26 @@ def test_order_block_duplicate_depdupe(self):
             'SoftLayer_Product_Order',
             'placeOrder',
             args=({
-                'complexType': 'SoftLayer_Container_Product_Order_'
-                'Network_Storage_AsAService',
-                'packageId': 759,
-                'prices': [
-                    {'id': 189433},
-                    {'id': 189443},
-                    {'id': 190113},
-                    {'id': 190173},
-                    {'id': 191193}
-                ],
-                'volumeSize': 1000,
-                'quantity': 1,
-                'location': 449500,
-                'duplicateOriginVolumeId': 102,
-                'osFormatType': {'keyName': 'LINUX'},
-                'duplicateOriginSnapshotId': 470,
-                'iops': 2000,
-                'useHourlyPricing': False,
-                'isDependentDuplicateFlag': 1
-            },))
+                      'complexType': 'SoftLayer_Container_Product_Order_'
+                                     'Network_Storage_AsAService',
+                      'packageId': 759,
+                      'prices': [
+                          {'id': 189433},
+                          {'id': 189443},
+                          {'id': 190113},
+                          {'id': 190173},
+                          {'id': 191193}
+                      ],
+                      'volumeSize': 1000,
+                      'quantity': 1,
+                      'location': 449500,
+                      'duplicateOriginVolumeId': 102,
+                      'osFormatType': {'keyName': 'LINUX'},
+                      'duplicateOriginSnapshotId': 470,
+                      'iops': 2000,
+                      'useHourlyPricing': False,
+                      'isDependentDuplicateFlag': 1
+                  },))
 
     def test_order_block_duplicate_endurance_no_duplicate_snapshot(self):
         mock = self.set_mock('SoftLayer_Product_Package', 'getAllObjects')
@@ -970,22 +970,22 @@ def test_order_block_duplicate_endurance_no_duplicate_snapshot(self):
             'SoftLayer_Product_Order',
             'placeOrder',
             args=({
-                'complexType': 'SoftLayer_Container_Product_Order_'
-                'Network_Storage_AsAService',
-                'packageId': 759,
-                'prices': [
-                    {'id': 189433},
-                    {'id': 189443},
-                    {'id': 193433},
-                    {'id': 193373}
-                ],
-                'volumeSize': 500,
-                'quantity': 1,
-                'location': 449500,
-                'duplicateOriginVolumeId': 102,
-                'osFormatType': {'keyName': 'LINUX'},
-                'useHourlyPricing': False
-            },))
+                      'complexType': 'SoftLayer_Container_Product_Order_'
+                                     'Network_Storage_AsAService',
+                      'packageId': 759,
+                      'prices': [
+                          {'id': 189433},
+                          {'id': 189443},
+                          {'id': 193433},
+                          {'id': 193373}
+                      ],
+                      'volumeSize': 500,
+                      'quantity': 1,
+                      'location': 449500,
+                      'duplicateOriginVolumeId': 102,
+                      'osFormatType': {'keyName': 'LINUX'},
+                      'useHourlyPricing': False
+                  },))
 
     def test_order_block_duplicate_endurance(self):
         mock = self.set_mock('SoftLayer_Product_Package', 'getAllObjects')
@@ -1010,24 +1010,24 @@ def test_order_block_duplicate_endurance(self):
             'SoftLayer_Product_Order',
             'placeOrder',
             args=({
-                'complexType': 'SoftLayer_Container_Product_Order_'
-                'Network_Storage_AsAService',
-                'packageId': 759,
-                'prices': [
-                    {'id': 189433},
-                    {'id': 189443},
-                    {'id': 194763},
-                    {'id': 194703},
-                    {'id': 194943}
-                ],
-                'volumeSize': 1000,
-                'quantity': 1,
-                'location': 449500,
-                'duplicateOriginVolumeId': 102,
-                'osFormatType': {'keyName': 'LINUX'},
-                'duplicateOriginSnapshotId': 470,
-                'useHourlyPricing': False
-            },))
+                      'complexType': 'SoftLayer_Container_Product_Order_'
+                                     'Network_Storage_AsAService',
+                      'packageId': 759,
+                      'prices': [
+                          {'id': 189433},
+                          {'id': 189443},
+                          {'id': 194763},
+                          {'id': 194703},
+                          {'id': 194943}
+                      ],
+                      'volumeSize': 1000,
+                      'quantity': 1,
+                      'location': 449500,
+                      'duplicateOriginVolumeId': 102,
+                      'osFormatType': {'keyName': 'LINUX'},
+                      'duplicateOriginSnapshotId': 470,
+                      'useHourlyPricing': False
+                  },))
 
     def test_order_block_modified_performance(self):
         mock = self.set_mock('SoftLayer_Product_Package', 'getAllObjects')
@@ -1115,3 +1115,7 @@ def test_convert_block_depdupe(self):
             'convertCloneDependentToIndependent',
             identifier=123
         )
+
+    def test_get_cloud_list(self):
+        self.block.get_cloud_list()
+        self.assert_called_with('SoftLayer_Account', 'getHubNetworkStorage')