Skip to content

Commit b3a3c1f

Browse files
caberoscaberos
authored andcommitted
add a new feature to get all cloud object storage
1 parent 9c55550 commit b3a3c1f

File tree

6 files changed

+258
-184
lines changed

6 files changed

+258
-184
lines changed

SoftLayer/CLI/block/object_list.py

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

SoftLayer/CLI/routes.py

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

129130
('email', 'SoftLayer.CLI.email'),
130131
('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: 7 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,9 @@ 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+
203+
mask = 'mask[id,username,billingItem,storageType, notes]'
204+
205+
return self.client.call('Account', 'getHubNetworkStorage', mask=mask)

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)