Skip to content

Commit 846404e

Browse files
Merge pull request #1666 from caberos/issue1665
add a new command on block object-storage details
2 parents 7c5698b + 754fa45 commit 846404e

File tree

7 files changed

+65
-2
lines changed

7 files changed

+65
-2
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
"""Display details for a specified cloud object storage."""
2+
# :license: MIT, see LICENSE for more details.
3+
4+
import click
5+
import SoftLayer
6+
from SoftLayer.CLI import environment
7+
from SoftLayer.CLI import formatting
8+
9+
10+
@click.command(cls=SoftLayer.CLI.command.SLCommand, )
11+
@click.argument('object_id')
12+
@environment.pass_env
13+
def cli(env, object_id):
14+
"""Display details for a cloud object storage."""
15+
16+
block_manager = SoftLayer.BlockStorageManager(env.client)
17+
18+
cloud = block_manager.get_volume_details(object_id)
19+
bucket = block_manager.get_buckets(object_id)
20+
21+
table = formatting.KeyValueTable(['Name', 'Value'])
22+
table.align['Name'] = 'r'
23+
table.align['Value'] = 'l'
24+
25+
table.add_row(['Id', cloud.get('id')])
26+
table.add_row(['Username', cloud.get('username')])
27+
table.add_row(['Name Service Resource', cloud['serviceResource']['name']])
28+
table.add_row(['Type Service Resource', cloud['serviceResource']['type']['type']])
29+
table.add_row(['Datacenter', cloud['serviceResource']['datacenter']['name']])
30+
table.add_row(['Storage type', cloud['storageType']['keyName']])
31+
table.add_row(['Bytes Used', formatting.b_to_gb(bucket[0]['bytesUsed'])])
32+
table.add_row(['Bucket name', bucket[0]['name']])
33+
34+
env.fout(table)

SoftLayer/CLI/routes.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@
127127
('block:volume-convert', 'SoftLayer.CLI.block.convert:cli'),
128128
('block:volume-set-note', 'SoftLayer.CLI.block.set_note:cli'),
129129
('block:object-list', 'SoftLayer.CLI.block.object_list:cli'),
130+
('block:object-storage-detail', 'SoftLayer.CLI.block.object_storage_detail:cli'),
130131

131132
('email', 'SoftLayer.CLI.email'),
132133
('email:list', 'SoftLayer.CLI.email.list:cli'),

SoftLayer/fixtures/SoftLayer_Network_Storage.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,11 @@
149149
}
150150
],
151151
'serviceProviderId': 1,
152-
'serviceResource': {'datacenter': {'id': 449500, 'name': 'dal05'}},
152+
'serviceResource': {'datacenter': {'id': 449500, 'name': 'dal05'},
153+
'name': 'Cleversafe - US Region',
154+
'type': {
155+
'type': 'CLEVERSAFE_SVC_API'
156+
}},
153157
'serviceResourceBackendIpAddress': '10.1.2.3',
154158
'serviceResourceName': 'Storage Type 01 Aggregate staaspar0101_pc01',
155159
'snapshotCapacityGb': '10',

SoftLayer/managers/block.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,3 +207,13 @@ def get_cloud_list(self):
207207
mask = 'mask[id,username,billingItem,storageType, notes]'
208208

209209
return self.client.call('Account', 'getHubNetworkStorage', mask=mask)
210+
211+
def get_buckets(self, object_id):
212+
"""Return buckets data of the cloud storage.
213+
214+
:param object_id cloud object storage identifier
215+
216+
Returns: Get buckets
217+
218+
"""
219+
return self.client.call('SoftLayer_Network_Storage_Hub_Cleversafe_Account', 'getBuckets', id=object_id)

docs/cli/block.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,10 @@ Block Commands
160160
:prog: block object-list
161161
:show-nested:
162162

163+
.. click:: SoftLayer.CLI.block.object_storage_detail:cli
164+
:prog: block object-storage-detail
165+
:show-nested:
166+
163167
.. click:: SoftLayer.CLI.block.duplicate_convert_status:cli
164168
:prog: block duplicate-convert-status
165169
:show-nested:

tests/CLI/modules/block_tests.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ def test_snapshot_restore(self):
444444

445445
self.assert_no_fail(result)
446446
self.assertEqual(result.output, 'Block volume 12345678 is being'
447-
' restored using snapshot 87654321\n')
447+
' restored using snapshot 87654321\n')
448448

449449
@mock.patch('SoftLayer.BlockStorageManager.order_snapshot_space')
450450
def test_snapshot_order_order_not_placed(self, order_mock):
@@ -825,3 +825,9 @@ def test_object_list(self):
825825

826826
self.assert_no_fail(result)
827827
self.assert_called_with('SoftLayer_Account', 'getHubNetworkStorage')
828+
829+
def test_object_details(self):
830+
result = self.run_command(['block', 'object-storage-detail', '1234'])
831+
832+
self.assert_no_fail(result)
833+
self.assert_called_with('SoftLayer_Network_Storage_Hub_Cleversafe_Account', 'getBuckets')

tests/managers/block_tests.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1119,3 +1119,7 @@ def test_convert_block_depdupe(self):
11191119
def test_get_cloud_list(self):
11201120
self.block.get_cloud_list()
11211121
self.assert_called_with('SoftLayer_Account', 'getHubNetworkStorage')
1122+
1123+
def test_get_bucket(self):
1124+
self.block.get_buckets(1234)
1125+
self.assert_called_with('SoftLayer_Network_Storage_Hub_Cleversafe_Account', 'getBuckets')

0 commit comments

Comments
 (0)