Repository: softlayer/softlayer-python
Pull request #1666 (2022-06-14 21:07:48)

add a new command on block object-storage details
[#issue1665](https://github.com/softlayer/softlayer-python/issues/1665)

![image](https://user-images.githubusercontent.com/22535437/173689068-9aa66d20-359c-415f-b221-b5788ee2aacd.png)



Patch:
diff --git a/SoftLayer/CLI/block/object_storage_detail.py b/SoftLayer/CLI/block/object_storage_detail.py
new file mode 100644
index 00000000..e7aa6913
--- /dev/null
+++ b/SoftLayer/CLI/block/object_storage_detail.py
@@ -0,0 +1,34 @@
+"""Display details for a specified cloud object storage."""
+# :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, )
+@click.argument('object_id')
+@environment.pass_env
+def cli(env, object_id):
+    """Display details for a cloud object storage."""
+
+    block_manager = SoftLayer.BlockStorageManager(env.client)
+
+    cloud = block_manager.get_volume_details(object_id)
+    bucket = block_manager.get_buckets(object_id)
+
+    table = formatting.KeyValueTable(['Name', 'Value'])
+    table.align['Name'] = 'r'
+    table.align['Value'] = 'l'
+
+    table.add_row(['Id', cloud.get('id')])
+    table.add_row(['Username', cloud.get('username')])
+    table.add_row(['Name Service Resource', cloud['serviceResource']['name']])
+    table.add_row(['Type Service Resource', cloud['serviceResource']['type']['type']])
+    table.add_row(['Datacenter', cloud['serviceResource']['datacenter']['name']])
+    table.add_row(['Storage type', cloud['storageType']['keyName']])
+    table.add_row(['Bytes Used', formatting.b_to_gb(bucket[0]['bytesUsed'])])
+    table.add_row(['Bucket name', bucket[0]['name']])
+
+    env.fout(table)
diff --git a/SoftLayer/CLI/firewall/monitoring.py b/SoftLayer/CLI/firewall/monitoring.py
deleted file mode 100644
index a76df667..00000000
--- a/SoftLayer/CLI/firewall/monitoring.py
+++ /dev/null
@@ -1,51 +0,0 @@
-"""Get monitoring for a firewall device."""
-# :license: MIT, see LICENSE for more details.
-import datetime
-
-import click
-
-import SoftLayer
-from SoftLayer.CLI import environment
-from SoftLayer.CLI import formatting
-
-
-@click.command(cls=SoftLayer.CLI.command.SLCommand, )
-@click.argument('identifier')
-@environment.pass_env
-def cli(env, identifier):
-    """Gets bandwidth details for a firewall from the past 30 days."""
-
-    mgr = SoftLayer.FirewallManager(env.client)
-
-    _firewall = mgr.get_instance(identifier)
-
-    table = formatting.KeyValueTable(['name', 'value'])
-    table.align['name'] = 'r'
-    table.align['value'] = 'l'
-
-    end = datetime.date.today()
-    start = end.replace(day=1)
-    last_month = start - datetime.timedelta(days=30)
-
-    monitoring = mgr.get_summary(_firewall['metricTrackingObject']['id'],
-                                 last_month.strftime('%Y-%m-%d'), end.strftime('%Y-%m-%d'))
-    public_out = 0
-    public_in = 0
-    for monitor in monitoring:
-
-        if monitor['type'] == 'publicOut_net_octet':
-            public_out += monitor['counter']
-
-        if monitor['type'] == 'publicIn_net_octet':
-            public_in += monitor['counter']
-
-    table.add_row(['Id', _firewall.get('id')])
-    table.add_row(['Name', _firewall['networkGateway']['name']])
-    table.add_row(['Stard Date', last_month.strftime('%Y-%m-%d')])
-    table.add_row(['End Date', end.strftime('%Y-%m-%d')])
-    table.add_row(['Out', formatting.b_to_gb(public_out)])
-    table.add_row(['In', formatting.b_to_gb(public_in)])
-    table.add_row(['Total', formatting.b_to_gb(public_out + public_in)])
-    table.add_row(['Status', _firewall['networkGateway']['status']['name']])
-
-    env.fout(table)
diff --git a/SoftLayer/CLI/routes.py b/SoftLayer/CLI/routes.py
index 420f7212..2c307202 100644
--- a/SoftLayer/CLI/routes.py
+++ b/SoftLayer/CLI/routes.py
@@ -127,6 +127,7 @@
     ('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'),
+    ('block:object-storage-detail', 'SoftLayer.CLI.block.object_storage_detail:cli'),
 
     ('email', 'SoftLayer.CLI.email'),
     ('email:list', 'SoftLayer.CLI.email.list:cli'),
@@ -180,7 +181,6 @@
     ('firewall:detail', 'SoftLayer.CLI.firewall.detail:cli'),
     ('firewall:edit', 'SoftLayer.CLI.firewall.edit:cli'),
     ('firewall:list', 'SoftLayer.CLI.firewall.list:cli'),
-    ('firewall:monitoring', 'SoftLayer.CLI.firewall.monitoring:cli'),
 
     ('globalip', 'SoftLayer.CLI.globalip'),
     ('globalip:assign', 'SoftLayer.CLI.globalip.assign:cli'),
diff --git a/SoftLayer/fixtures/SoftLayer_Network_Storage.py b/SoftLayer/fixtures/SoftLayer_Network_Storage.py
index acf369d1..409f1fd8 100644
--- a/SoftLayer/fixtures/SoftLayer_Network_Storage.py
+++ b/SoftLayer/fixtures/SoftLayer_Network_Storage.py
@@ -149,7 +149,11 @@
         }
     ],
     'serviceProviderId': 1,
-    'serviceResource': {'datacenter': {'id': 449500, 'name': 'dal05'}},
+    'serviceResource': {'datacenter': {'id': 449500, 'name': 'dal05'},
+                        'name': 'Cleversafe - US Region',
+                        'type': {
+                            'type': 'CLEVERSAFE_SVC_API'
+                        }},
     'serviceResourceBackendIpAddress': '10.1.2.3',
     'serviceResourceName': 'Storage Type 01 Aggregate staaspar0101_pc01',
     'snapshotCapacityGb': '10',
diff --git a/SoftLayer/fixtures/SoftLayer_Network_Vlan_Firewall.py b/SoftLayer/fixtures/SoftLayer_Network_Vlan_Firewall.py
index e7f64837..1c57523e 100644
--- a/SoftLayer/fixtures/SoftLayer_Network_Vlan_Firewall.py
+++ b/SoftLayer/fixtures/SoftLayer_Network_Vlan_Firewall.py
@@ -174,12 +174,6 @@
             "modifyDate": "2022-05-17T14:00:42-06:00",
             "primarySubnetId": 2623338,
             "vlanNumber": 1255
-        },
-        "status": {
-            "description": "Gateway is ready to accept commands and actions",
-            "id": 1,
-            "keyName": "ACTIVE",
-            "name": "Active"
         }
     },
     "rules": [
@@ -218,16 +212,7 @@
             'action': 'permit',
             'sourceIpAddress': '0.0.0.0'
         }
-    ],
-    "metricTrackingObject": {
-        "id": 147258369,
-        "resourceTableId": 17438,
-        "startDate": "2022-05-17T14:01:48-06:00",
-        "type": {
-            "keyname": "FIREWALL_CONTEXT",
-            "name": "Firewall Module Context"
-        }
-    }
+    ]
 
 }
 
diff --git a/SoftLayer/managers/block.py b/SoftLayer/managers/block.py
index 26094145..1910107d 100644
--- a/SoftLayer/managers/block.py
+++ b/SoftLayer/managers/block.py
@@ -207,3 +207,13 @@ def get_cloud_list(self):
         mask = 'mask[id,username,billingItem,storageType, notes]'
 
         return self.client.call('Account', 'getHubNetworkStorage', mask=mask)
+
+    def get_buckets(self, object_id):
+        """Return  buckets data of the cloud storage.
+
+        :param object_id cloud object storage identifier
+
+        Returns: Get buckets
+
+        """
+        return self.client.call('SoftLayer_Network_Storage_Hub_Cleversafe_Account', 'getBuckets', id=object_id)
diff --git a/SoftLayer/managers/firewall.py b/SoftLayer/managers/firewall.py
index 0c4d10bb..cb41caff 100644
--- a/SoftLayer/managers/firewall.py
+++ b/SoftLayer/managers/firewall.py
@@ -297,9 +297,8 @@ def get_instance(self, firewall_id, mask=None):
         :param integer firewall_id: the instance ID of the standard firewall
         """
         if not mask:
-            mask = 'mask[firewallType,datacenter,managementCredentials,networkVlan,' \
-                   'metricTrackingObject[data,type],networkGateway[insideVlans,members,privateIpAddress,' \
-                   'publicIpAddress,publicIpv6Address,privateVlan,publicVlan,status]]'
+            mask = 'mask[firewallType,networkGateway[insideVlans,members,privateIpAddress,publicIpAddress,' \
+                   'publicIpv6Address,privateVlan,publicVlan],datacenter,managementCredentials,networkVlan]'
 
         svc = self.client['Network_Vlan_Firewall']
 
@@ -320,20 +319,3 @@ def get_firewalls_gatewalls(self):
         _filter = {"networkGateways": {"networkFirewall": {"operation": "not null"}}}
 
         return self.account.getNetworkGateways(mask=mask, filter=_filter)
-
-    def get_summary(self, identifier, start_date, end_date):
-        """Returns the metric data for the date range provided
-
-        :param integer metric_tracking_id
-        """
-        body = [{
-            "keyName": "PUBLICIN",
-            "summaryType": "sum"
-
-        }, {
-            "keyName": "PUBLICOUT",
-            "summaryType": "sum"
-        }]
-
-        return self.client['Metric_Tracking_Object'].getSummaryData(start_date,
-                                                                    end_date, body, 86400, id=identifier)
diff --git a/docs/cli/block.rst b/docs/cli/block.rst
index 799070b5..58508775 100644
--- a/docs/cli/block.rst
+++ b/docs/cli/block.rst
@@ -160,6 +160,10 @@ Block Commands
     :prog: block object-list
     :show-nested:
 
+.. click:: SoftLayer.CLI.block.object_storage_detail:cli
+    :prog: block object-storage-detail
+    :show-nested:
+
 .. click:: SoftLayer.CLI.block.duplicate_convert_status:cli
     :prog: block duplicate-convert-status
     :show-nested:
diff --git a/docs/cli/firewall.rst b/docs/cli/firewall.rst
index 4053505a..bae1c99d 100644
--- a/docs/cli/firewall.rst
+++ b/docs/cli/firewall.rst
@@ -22,7 +22,3 @@ Firewall Management
 .. click:: SoftLayer.CLI.firewall.list:cli
     :prog: firewall list
     :show-nested:
-
-.. click:: SoftLayer.CLI.firewall.monitoring:cli
-    :prog: firewall monitoring
-    :show-nested:


Test patch:
diff --git a/tests/CLI/modules/block_tests.py b/tests/CLI/modules/block_tests.py
index f909683a..96f471f1 100644
--- a/tests/CLI/modules/block_tests.py
+++ b/tests/CLI/modules/block_tests.py
@@ -444,7 +444,7 @@ def test_snapshot_restore(self):
 
         self.assert_no_fail(result)
         self.assertEqual(result.output, 'Block volume 12345678 is being'
-                         ' restored using snapshot 87654321\n')
+                                        ' restored using snapshot 87654321\n')
 
     @mock.patch('SoftLayer.BlockStorageManager.order_snapshot_space')
     def test_snapshot_order_order_not_placed(self, order_mock):
@@ -825,3 +825,9 @@ def test_object_list(self):
 
         self.assert_no_fail(result)
         self.assert_called_with('SoftLayer_Account', 'getHubNetworkStorage')
+
+    def test_object_details(self):
+        result = self.run_command(['block', 'object-storage-detail', '1234'])
+
+        self.assert_no_fail(result)
+        self.assert_called_with('SoftLayer_Network_Storage_Hub_Cleversafe_Account', 'getBuckets')
diff --git a/tests/CLI/modules/firewall_tests.py b/tests/CLI/modules/firewall_tests.py
index 3ccc2c59..7930a8c1 100644
--- a/tests/CLI/modules/firewall_tests.py
+++ b/tests/CLI/modules/firewall_tests.py
@@ -154,7 +154,3 @@ def test_edit(self, confirm_mock):
         confirm_mock.return_value = True
         result = self.run_command(['firewall', 'edit', 'vlan:1234'])
         print(result.output)
-
-    def test_monitoring(self):
-        result = self.run_command(['firewall', 'monitoring', '123456'])
-        print(result.output)
diff --git a/tests/managers/block_tests.py b/tests/managers/block_tests.py
index 85481331..b0e80814 100644
--- a/tests/managers/block_tests.py
+++ b/tests/managers/block_tests.py
@@ -1119,3 +1119,7 @@ def test_convert_block_depdupe(self):
     def test_get_cloud_list(self):
         self.block.get_cloud_list()
         self.assert_called_with('SoftLayer_Account', 'getHubNetworkStorage')
+
+    def test_get_bucket(self):
+        self.block.get_buckets(1234)
+        self.assert_called_with('SoftLayer_Network_Storage_Hub_Cleversafe_Account', 'getBuckets')
diff --git a/tests/managers/firewall_tests.py b/tests/managers/firewall_tests.py
index cbd6d962..783d7cbe 100644
--- a/tests/managers/firewall_tests.py
+++ b/tests/managers/firewall_tests.py
@@ -46,6 +46,7 @@ def test_get_standard_fwl_rules(self):
                                 identifier=1234)
 
     def test_get_dedicated_fwl_rules(self):
+
         rules = self.firewall.get_dedicated_fwl_rules(1234)
 
         self.assertEqual(rules,