Skip to content

Commit 2587d41

Browse files
Merge pull request #1235 from allmightyspiff/issues1233-fbRefactor
Issues1233 file and block refactor
2 parents ab9552d + c64c058 commit 2587d41

File tree

12 files changed

+676
-959
lines changed

12 files changed

+676
-959
lines changed

SoftLayer/CLI/block/detail.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import SoftLayer
66
from SoftLayer.CLI import environment
77
from SoftLayer.CLI import formatting
8+
from SoftLayer.CLI import helpers
89
from SoftLayer import utils
910

1011

@@ -14,7 +15,8 @@
1415
def cli(env, volume_id):
1516
"""Display details for a specified volume."""
1617
block_manager = SoftLayer.BlockStorageManager(env.client)
17-
block_volume = block_manager.get_block_volume_details(volume_id)
18+
block_volume_id = helpers.resolve_id(block_manager.resolve_ids, volume_id, 'Block Volume')
19+
block_volume = block_manager.get_block_volume_details(block_volume_id)
1820
block_volume = utils.NestedDict(block_volume)
1921

2022
table = formatting.KeyValueTable(['Name', 'Value'])

SoftLayer/CLI/file/detail.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import SoftLayer
66
from SoftLayer.CLI import environment
77
from SoftLayer.CLI import formatting
8+
from SoftLayer.CLI import helpers
89
from SoftLayer import utils
910

1011

@@ -14,7 +15,8 @@
1415
def cli(env, volume_id):
1516
"""Display details for a specified volume."""
1617
file_manager = SoftLayer.FileStorageManager(env.client)
17-
file_volume = file_manager.get_file_volume_details(volume_id)
18+
file_volume_id = helpers.resolve_id(file_manager.resolve_ids, volume_id, 'File Storage')
19+
file_volume = file_manager.get_file_volume_details(file_volume_id)
1820
file_volume = utils.NestedDict(file_volume)
1921

2022
table = formatting.KeyValueTable(['Name', 'Value'])
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
getDatacenters = [
2+
{
3+
"id": 1441195,
4+
"longName": "Dallas 10",
5+
"name": "dal10"
6+
},
7+
{
8+
"id": 449494,
9+
"longName": "Dallas 9",
10+
"name": "dal09"
11+
}
12+
]

SoftLayer/managers/block.py

Lines changed: 20 additions & 445 deletions
Large diffs are not rendered by default.

SoftLayer/managers/file.py

Lines changed: 16 additions & 379 deletions
Large diffs are not rendered by default.

SoftLayer/managers/storage.py

Lines changed: 416 additions & 0 deletions
Large diffs are not rendered by default.

SoftLayer/managers/storage_utils.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,19 @@
1919
}
2020

2121

22-
def populate_host_templates(host_templates,
23-
hardware_ids=None,
22+
def populate_host_templates(hardware_ids=None,
2423
virtual_guest_ids=None,
2524
ip_address_ids=None,
2625
subnet_ids=None):
27-
"""Populate the given host_templates array with the IDs provided
26+
"""Returns a populated array with the IDs provided
2827
29-
:param host_templates: The array to which host templates will be added
3028
:param hardware_ids: A List of SoftLayer_Hardware ids
3129
:param virtual_guest_ids: A List of SoftLayer_Virtual_Guest ids
3230
:param ip_address_ids: A List of SoftLayer_Network_Subnet_IpAddress ids
3331
:param subnet_ids: A List of SoftLayer_Network_Subnet ids
32+
:return: array of objects formatted for allowAccessFromHostList
3433
"""
34+
host_templates = []
3535
if hardware_ids is not None:
3636
for hardware_id in hardware_ids:
3737
host_templates.append({
@@ -59,6 +59,7 @@ def populate_host_templates(host_templates,
5959
'objectType': 'SoftLayer_Network_Subnet',
6060
'id': subnet_id
6161
})
62+
return host_templates
6263

6364

6465
def get_package(manager, category_code):
@@ -991,6 +992,15 @@ def prepare_modify_order_object(manager, volume, new_iops, new_tier, new_size):
991992
return modify_order
992993

993994

995+
def block_or_file(storage_type_keyname):
996+
"""returns either 'block' or 'file'
997+
998+
:param storage_type_keyname: the Network_Storage['storageType']['keyName']
999+
:returns: 'block' or 'file'
1000+
"""
1001+
return 'block' if 'BLOCK_STORAGE' in storage_type_keyname else 'file'
1002+
1003+
9941004
def _has_category(categories, category_code):
9951005
return any(
9961006
True

tests/CLI/modules/block_tests.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ def test_volume_detail(self):
6060

6161
self.assert_no_fail(result)
6262
isinstance(json.loads(result.output)['IOPs'], float)
63+
self.assert_called_with('SoftLayer_Network_Storage', 'getObject', identifier=1234)
6364
self.assertEqual({
6465
'Username': 'username',
6566
'LUN Id': '2',
@@ -98,6 +99,26 @@ def test_volume_detail(self):
9899
]
99100
}, json.loads(result.output))
100101

102+
def test_volume_detail_name_identifier(self):
103+
result = self.run_command(['block', 'volume-detail', 'SL-12345'])
104+
expected_filter = {
105+
'iscsiNetworkStorage': {
106+
'serviceResource': {
107+
'type': {
108+
'type': {'operation': '!~ ISCSI'}
109+
}
110+
},
111+
'storageType': {
112+
'keyName': {'operation': '*= BLOCK_STORAGE'}
113+
},
114+
'username': {'operation': '_= SL-12345'}
115+
}
116+
}
117+
118+
self.assert_called_with('SoftLayer_Account', 'getIscsiNetworkStorage', filter=expected_filter)
119+
self.assert_called_with('SoftLayer_Network_Storage', 'getObject', identifier=100)
120+
self.assert_no_fail(result)
121+
101122
def test_volume_list(self):
102123
result = self.run_command(['block', 'volume-list'])
103124

tests/CLI/modules/file_tests.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,24 @@ def test_volume_detail(self):
163163
]
164164
}, json.loads(result.output))
165165

166+
def test_volume_detail_name_identifier(self):
167+
result = self.run_command(['file', 'volume-detail', 'SL-12345'])
168+
expected_filter = {
169+
'nasNetworkStorage': {
170+
'serviceResource': {
171+
'type': {
172+
'type': {'operation': '!~ NAS'}
173+
}
174+
},
175+
'storageType': {
176+
'keyName': {'operation': '*= FILE_STORAGE'}
177+
},
178+
'username': {'operation': '_= SL-12345'}}}
179+
180+
self.assert_called_with('SoftLayer_Account', 'getNasNetworkStorage', filter=expected_filter)
181+
self.assert_called_with('SoftLayer_Network_Storage', 'getObject', identifier=1)
182+
self.assert_no_fail(result)
183+
166184
def test_volume_order_performance_iops_not_given(self):
167185
result = self.run_command(['file', 'volume-order',
168186
'--storage-type=performance', '--size=20',

0 commit comments

Comments
 (0)