Skip to content

Commit 5ef66a6

Browse files
Merge branch 'fo_block_file_storage_detail' of https://github.com/FernandoOjeda/softlayer-python into issues1233-fbRefactor #1232
2 parents 1c812de + b07e0ec commit 5ef66a6

File tree

4 files changed

+126
-2
lines changed

4 files changed

+126
-2
lines changed

SoftLayer/CLI/block/detail.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,35 @@
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

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+
1128
@click.command()
1229
@click.argument('volume_id')
1330
@environment.pass_env
1431
def cli(env, volume_id):
1532
"""Display details for a specified volume."""
1633
block_manager = SoftLayer.BlockStorageManager(env.client)
17-
block_volume = block_manager.get_block_volume_details(volume_id)
34+
volume_id = get_block_volume_id(volume_id, block_manager)
35+
block_volume_id = helpers.resolve_id(block_manager.resolve_ids, volume_id, 'Block Volume')
36+
block_volume = block_manager.get_block_volume_details(block_volume_id)
1837
block_volume = utils.NestedDict(block_volume)
1938

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

SoftLayer/CLI/file/detail.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,35 @@
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

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+
1128
@click.command()
1229
@click.argument('volume_id')
1330
@environment.pass_env
1431
def cli(env, volume_id):
1532
"""Display details for a specified volume."""
1633
file_manager = SoftLayer.FileStorageManager(env.client)
17-
file_volume = file_manager.get_file_volume_details(volume_id)
34+
volume_id = get_file_volume_id(volume_id, file_manager)
35+
file_volume_id = helpers.resolve_id(file_manager.resolve_ids, volume_id, 'File Storage')
36+
file_volume = file_manager.get_file_volume_details(file_volume_id)
1837
file_volume = utils.NestedDict(file_volume)
1938

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

tests/CLI/modules/block_tests.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,49 @@ def test_volume_detail(self):
9898
]
9999
}, json.loads(result.output))
100100

101+
def test_volume_detail_name_identifier(self):
102+
result = self.run_command(['block', 'volume-detail', 'username'])
103+
104+
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))
143+
101144
def test_volume_list(self):
102145
result = self.run_command(['block', 'volume-list'])
103146

tests/CLI/modules/file_tests.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,49 @@ 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', 'user'])
168+
169+
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))
208+
166209
def test_volume_order_performance_iops_not_given(self):
167210
result = self.run_command(['file', 'volume-order',
168211
'--storage-type=performance', '--size=20',

0 commit comments

Comments
 (0)