Skip to content

Commit 63219ac

Browse files
Merged in #1232 and added it to the refactor
1 parent 5ef66a6 commit 63219ac

File tree

7 files changed

+50
-114
lines changed

7 files changed

+50
-114
lines changed

SoftLayer/CLI/block/detail.py

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,12 @@
99
from SoftLayer import utils
1010

1111

12-
def get_block_volume_id(volume_id, block_manager):
13-
"""Returns the volume id.
14-
15-
:param volume_id: ID of volume.
16-
:param block_manager: Block Storage Manager.
17-
:return: Returns the volume id.
18-
"""
19-
storage_list = block_manager.list_block_volumes()
20-
for storage in storage_list:
21-
if volume_id == storage['username']:
22-
volume_id = storage['id']
23-
break
24-
25-
return volume_id
26-
27-
2812
@click.command()
2913
@click.argument('volume_id')
3014
@environment.pass_env
3115
def cli(env, volume_id):
3216
"""Display details for a specified volume."""
3317
block_manager = SoftLayer.BlockStorageManager(env.client)
34-
volume_id = get_block_volume_id(volume_id, block_manager)
3518
block_volume_id = helpers.resolve_id(block_manager.resolve_ids, volume_id, 'Block Volume')
3619
block_volume = block_manager.get_block_volume_details(block_volume_id)
3720
block_volume = utils.NestedDict(block_volume)

SoftLayer/CLI/file/detail.py

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,12 @@
99
from SoftLayer import utils
1010

1111

12-
def get_file_volume_id(volume_id, file_manager):
13-
"""Returns the volume id.
14-
15-
:param volume_id: ID of volume.
16-
:param block_manager: Block Storage Manager.
17-
:return: Returns the volume id.
18-
"""
19-
storage_list = file_manager.list_file_volumes()
20-
for storage in storage_list:
21-
if volume_id == storage['username']:
22-
volume_id = storage['id']
23-
break
24-
25-
return volume_id
26-
27-
2812
@click.command()
2913
@click.argument('volume_id')
3014
@environment.pass_env
3115
def cli(env, volume_id):
3216
"""Display details for a specified volume."""
3317
file_manager = SoftLayer.FileStorageManager(env.client)
34-
volume_id = get_file_volume_id(volume_id, file_manager)
3518
file_volume_id = helpers.resolve_id(file_manager.resolve_ids, volume_id, 'File Storage')
3619
file_volume = file_manager.get_file_volume_details(file_volume_id)
3720
file_volume = utils.NestedDict(file_volume)

SoftLayer/managers/block.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,3 +184,10 @@ def create_or_update_lun_id(self, volume_id, lun_id):
184184
:return: a SoftLayer_Network_Storage_Property object
185185
"""
186186
return self.client.call('Network_Storage', 'createOrUpdateLunId', lun_id, id=volume_id)
187+
188+
def _get_ids_from_username(self, username):
189+
object_mask = "mask[id]"
190+
results = self.list_block_volumes(username=username, mask=object_mask)
191+
if results:
192+
return [result['id'] for result in results]
193+

SoftLayer/managers/file.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,3 +157,10 @@ def cancel_file_volume(self, volume_id, reason='No longer needed', immediate=Fal
157157
:param boolean immediate: Cancel immediately or on anniversary date
158158
"""
159159
return self.cancel_volume(volume_id, reason, immediate)
160+
161+
def _get_ids_from_username(self, username):
162+
object_mask = "mask[id]"
163+
results = self.list_file_volumes(username=username, mask=object_mask)
164+
if results:
165+
return [result['id'] for result in results]
166+

SoftLayer/managers/storage.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ class StorageManager(utils.IdentifierMixin, object):
2323
def __init__(self, client):
2424
self.configuration = {}
2525
self.client = client
26+
self.resolvers = [self._get_ids_from_username]
27+
28+
def _get_ids_from_username(self, username):
29+
raise exceptions.SoftLayerError("Not Implemented.")
2630

2731
def get_volume_count_limits(self):
2832
"""Returns a list of block volume count limit.

tests/CLI/modules/block_tests.py

Lines changed: 16 additions & 40 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',
@@ -99,47 +100,22 @@ def test_volume_detail(self):
99100
}, json.loads(result.output))
100101

101102
def test_volume_detail_name_identifier(self):
102-
result = self.run_command(['block', 'volume-detail', 'username'])
103-
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+
self.assert_called_with('SoftLayer_Account', 'getIscsiNetworkStorage', filter=expected_filter)
117+
self.assert_called_with('SoftLayer_Network_Storage', 'getObject', identifier=100)
104118
self.assert_no_fail(result)
105-
isinstance(json.loads(result.output)['IOPs'], float)
106-
self.assertEqual({
107-
'Username': 'username',
108-
'LUN Id': '2',
109-
'Endurance Tier': 'READHEAVY_TIER',
110-
'IOPs': 1000,
111-
'Snapshot Capacity (GB)': '10',
112-
'Snapshot Used (Bytes)': 1024,
113-
'Capacity (GB)': '20GB',
114-
'Target IP': '10.1.2.3',
115-
'Data Center': 'dal05',
116-
'Type': 'ENDURANCE',
117-
'ID': 100,
118-
'# of Active Transactions': '1',
119-
'Ongoing Transaction': 'This is a buffer time in which the customer may cancel the server',
120-
'Replicant Count': '1',
121-
'Replication Status': 'Replicant Volume Provisioning '
122-
'has completed.',
123-
'Replicant Volumes': [[
124-
{'Replicant ID': 'Volume Name', '1784': 'TEST_REP_1'},
125-
{'Replicant ID': 'Target IP', '1784': '10.3.174.79'},
126-
{'Replicant ID': 'Data Center', '1784': 'wdc01'},
127-
{'Replicant ID': 'Schedule', '1784': 'REPLICATION_HOURLY'},
128-
], [
129-
{'Replicant ID': 'Volume Name', '1785': 'TEST_REP_2'},
130-
{'Replicant ID': 'Target IP', '1785': '10.3.177.84'},
131-
{'Replicant ID': 'Data Center', '1785': 'dal01'},
132-
{'Replicant ID': 'Schedule', '1785': 'REPLICATION_DAILY'},
133-
]],
134-
'Original Volume Properties': [
135-
{'Property': 'Original Volume Size',
136-
'Value': '20'},
137-
{'Property': 'Original Volume Name',
138-
'Value': 'test-original-volume-name'},
139-
{'Property': 'Original Snapshot Name',
140-
'Value': 'test-original-snapshot-name'}
141-
]
142-
}, json.loads(result.output))
143119

144120
def test_volume_list(self):
145121
result = self.run_command(['block', 'volume-list'])

tests/CLI/modules/file_tests.py

Lines changed: 16 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -164,47 +164,23 @@ def test_volume_detail(self):
164164
}, json.loads(result.output))
165165

166166
def test_volume_detail_name_identifier(self):
167-
result = self.run_command(['file', 'volume-detail', 'user'])
168-
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)
169182
self.assert_no_fail(result)
170-
self.assertEqual({
171-
'Username': 'username',
172-
'Used Space': '0B',
173-
'Endurance Tier': 'READHEAVY_TIER',
174-
'IOPs': 1000,
175-
'Mount Address': '127.0.0.1:/TEST',
176-
'Snapshot Capacity (GB)': '10',
177-
'Snapshot Used (Bytes)': 1024,
178-
'Capacity (GB)': '20GB',
179-
'Target IP': '10.1.2.3',
180-
'Data Center': 'dal05',
181-
'Type': 'ENDURANCE',
182-
'ID': 100,
183-
'# of Active Transactions': '1',
184-
'Ongoing Transaction': 'This is a buffer time in which the customer may cancel the server',
185-
'Replicant Count': '1',
186-
'Replication Status': 'Replicant Volume Provisioning '
187-
'has completed.',
188-
'Replicant Volumes': [[
189-
{'Replicant ID': 'Volume Name', '1784': 'TEST_REP_1'},
190-
{'Replicant ID': 'Target IP', '1784': '10.3.174.79'},
191-
{'Replicant ID': 'Data Center', '1784': 'wdc01'},
192-
{'Replicant ID': 'Schedule', '1784': 'REPLICATION_HOURLY'},
193-
], [
194-
{'Replicant ID': 'Volume Name', '1785': 'TEST_REP_2'},
195-
{'Replicant ID': 'Target IP', '1785': '10.3.177.84'},
196-
{'Replicant ID': 'Data Center', '1785': 'dal01'},
197-
{'Replicant ID': 'Schedule', '1785': 'REPLICATION_DAILY'},
198-
]],
199-
'Original Volume Properties': [
200-
{'Property': 'Original Volume Size',
201-
'Value': '20'},
202-
{'Property': 'Original Volume Name',
203-
'Value': 'test-original-volume-name'},
204-
{'Property': 'Original Snapshot Name',
205-
'Value': 'test-original-snapshot-name'}
206-
]
207-
}, json.loads(result.output))
183+
208184

209185
def test_volume_order_performance_iops_not_given(self):
210186
result = self.run_command(['file', 'volume-order',

0 commit comments

Comments
 (0)