Skip to content

Commit 105d503

Browse files
Merge pull request #1662 from caberos/issue1659
add a new feature to get all cloud object storage
2 parents 182c390 + b84f8bb commit 105d503

File tree

7 files changed

+269
-184
lines changed

7 files changed

+269
-184
lines changed

SoftLayer/CLI/block/object_list.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
"""List cloud object storage volumes."""
2+
# :license: MIT, see LICENSE for more details.
3+
4+
import click
5+
6+
import SoftLayer
7+
from SoftLayer.CLI import environment
8+
from SoftLayer.CLI import formatting
9+
10+
11+
@click.command(cls=SoftLayer.CLI.command.SLCommand, )
12+
@environment.pass_env
13+
def cli(env):
14+
"""List cloud block storage."""
15+
block_manager = SoftLayer.BlockStorageManager(env.client)
16+
17+
storages = block_manager.get_cloud_list()
18+
19+
table = formatting.Table(['Id',
20+
'Account name',
21+
'Description',
22+
'Create Date',
23+
'Type'])
24+
for storage in storages:
25+
table.add_row([storage.get('id'),
26+
storage.get('username'),
27+
storage['storageType']['description'],
28+
storage['billingItem']['createDate'],
29+
storage['storageType']['keyName']])
30+
31+
env.fout(table)

SoftLayer/CLI/routes.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@
126126
('block:volume-refresh', 'SoftLayer.CLI.block.refresh:cli'),
127127
('block:volume-convert', 'SoftLayer.CLI.block.convert:cli'),
128128
('block:volume-set-note', 'SoftLayer.CLI.block.set_note:cli'),
129+
('block:object-list', 'SoftLayer.CLI.block.object_list:cli'),
129130

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

SoftLayer/fixtures/SoftLayer_Account.py

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -647,8 +647,36 @@
647647

648648
getNextInvoiceTotalAmount = 2
649649

650-
getHubNetworkStorage = [{'id': 12345, 'username': 'SLOS12345-1', 'serviceResource': {'name': 'Cleversafe - US Region'}},
651-
{'id': 12346, 'username': 'SLOS12345-2', 'vendorName': 'Swift'}]
650+
getHubNetworkStorage = [
651+
{
652+
"id": 12345,
653+
"username": "SLOS12345-1",
654+
"billingItem": {
655+
"createDate": "2020-10-08T11:45:17-06:00"
656+
},
657+
"serviceResource": {
658+
"name": "Cleversafe - US Region"
659+
},
660+
"storageType": {
661+
"description": "Object Storage Standard Account",
662+
"id": 24,
663+
"keyName": "OBJECT_STORAGE_STANDARD"
664+
}
665+
},
666+
{
667+
"id": 12346,
668+
"username": "SLOS12345-2",
669+
"vendorName": "Swift",
670+
"billingItem": {
671+
"createDate": "2020-10-08T11:45:17-06:00"
672+
},
673+
"storageType": {
674+
"description": "Object Storage Standard Account",
675+
"id": 24,
676+
"keyName": "OBJECT_STORAGE_STANDARD"
677+
}
678+
}
679+
]
652680

653681
getIscsiNetworkStorage = [{
654682
'accountId': 1234,

SoftLayer/managers/block.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from SoftLayer.managers import storage_utils
1010
from SoftLayer import utils
1111

12+
1213
# pylint: disable=too-many-public-methods
1314

1415

@@ -196,3 +197,13 @@ def _get_ids_from_username(self, username):
196197
if results:
197198
return [result['id'] for result in results]
198199
return []
200+
201+
def get_cloud_list(self):
202+
"""Returns a list cloud object storage.
203+
204+
return: Returns a list cloud object storage.
205+
"""
206+
207+
mask = 'mask[id,username,billingItem,storageType, notes]'
208+
209+
return self.client.call('Account', 'getHubNetworkStorage', mask=mask)

docs/cli/block.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,10 @@ Block Commands
156156
:prog: block snapshot-get-notification-status
157157
:show-nested:
158158

159+
.. click:: SoftLayer.CLI.block.object_list:cli
160+
:prog: block object-list
161+
:show-nested:
162+
159163
.. click:: SoftLayer.CLI.block.duplicate_convert_status:cli
160164
:prog: block duplicate-convert-status
161165
:show-nested:

tests/CLI/modules/block_tests.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -819,3 +819,9 @@ def test_snapshot_get_notification_status(self, status):
819819
result = self.run_command(['block', 'snapshot-get-notification-status', '999'])
820820
self.assert_no_fail(result)
821821
self.assertIn(expect, result.output)
822+
823+
def test_object_list(self):
824+
result = self.run_command(['block', 'object-list'])
825+
826+
self.assert_no_fail(result)
827+
self.assert_called_with('SoftLayer_Account', 'getHubNetworkStorage')

0 commit comments

Comments
 (0)