Skip to content

Commit ae30c66

Browse files
sghattyDavid Pickle
authored andcommitted
Address pull request feedback; improve code style/formatting
1 parent 26977f2 commit ae30c66

9 files changed

Lines changed: 93 additions & 29 deletions

File tree

SoftLayer/CLI/block/detail.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,13 @@ def cli(env, volume_id):
6262

6363
if block_volume['activeTransactions']:
6464
for trans in block_volume['activeTransactions']:
65-
table.add_row([
66-
'Ongoing Transactions',
67-
trans['transactionStatus']['friendlyName']])
65+
if trans['transactionStatus']:
66+
table.add_row([
67+
'Ongoing Transactions',
68+
trans['transactionStatus']['friendlyName']])
6869

69-
table.add_row(['Replicant Count', "%u"
70+
if block_volume['replicationPartnerCount']:
71+
table.add_row(['Replicant Count', "%u"
7072
% block_volume['replicationPartnerCount']])
7173

7274
if block_volume['replicationPartnerCount'] > 0:
@@ -105,7 +107,7 @@ def cli(env, volume_id):
105107
if block_volume.get('originalVolumeSize'):
106108

107109
origin_volume_info = formatting.Table(['Property',
108-
'Value'])
110+
'Value'])
109111
origin_volume_info.add_row(['Original Volume Size',
110112
block_volume['originalVolumeSize']])
111113
if block_volume.get('originalVolumeName'):

SoftLayer/CLI/block/modify.py

Lines changed: 29 additions & 0 deletions
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 exceptions
8+
from SoftLayer import utils
89

910

1011
CONTEXT_SETTINGS = {'token_normalize_func': lambda x: x.upper()}
@@ -47,6 +48,34 @@ def cli(env, volume_id, new_size, new_iops, new_tier):
4748
"""Modify an existing block storage volume."""
4849
block_manager = SoftLayer.BlockStorageManager(env.client)
4950

51+
block_volume = block_manager.get_block_volume_details(volume_id)
52+
block_volume = utils.NestedDict(block_volume)
53+
54+
storage_type = block_volume['storageType']['keyName'].split('_').pop(0)
55+
help_message = "For help, try \"slcli block volume-modify --help\"."
56+
57+
if storage_type == 'ENDURANCE':
58+
if new_iops is not None:
59+
raise exceptions.CLIAbort(
60+
'Invalid option --new-iops for Endurance volume. Please use --new-tier instead.')
61+
62+
if new_size is None and new_tier is None:
63+
raise exceptions.CLIAbort(
64+
'Option --new-size or --new-tier must be specified for modifying an Endurance volume. \n'+
65+
help_message
66+
)
67+
68+
if storage_type == 'PERFORMANCE':
69+
if new_tier is not None:
70+
raise exceptions.CLIAbort(
71+
'Invalid option --new-tier for Performance volume. Please use --new-iops instead.')
72+
73+
if new_size is None and new_iops is None:
74+
raise exceptions.CLIAbort(
75+
'Option --new-size or --new-iops must be specified for modifying a Performance volume. \n' +
76+
help_message
77+
)
78+
5079
if new_tier is not None:
5180
new_tier = float(new_tier)
5281

SoftLayer/CLI/file/detail.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,14 @@ def cli(env, volume_id):
7878

7979
if file_volume['activeTransactions']:
8080
for trans in file_volume['activeTransactions']:
81-
table.add_row([
82-
'Ongoing Transactions',
83-
trans['transactionStatus']['friendlyName']])
81+
if trans['transactionStatus'] and trans['transactionStatus']['friendlyName']:
82+
table.add_row([
83+
'Ongoing Transactions',
84+
trans['transactionStatus']['friendlyName']])
8485

85-
table.add_row(['Replicant Count', "%u"
86-
% file_volume['replicationPartnerCount']])
86+
if file_volume['replicationPartnerCount']:
87+
table.add_row(['Replicant Count', "%u"
88+
% file_volume['replicationPartnerCount']])
8789

8890
if file_volume['replicationPartnerCount'] > 0:
8991
# This if/else temporarily handles a bug in which the SL API
@@ -121,7 +123,7 @@ def cli(env, volume_id):
121123
if file_volume.get('originalVolumeSize'):
122124

123125
origin_volume_info = formatting.Table(['Property',
124-
'Value'])
126+
'Value'])
125127
origin_volume_info.add_row(['Original Volume Size',
126128
file_volume['originalVolumeSize']])
127129
if file_volume.get('originalVolumeName'):

SoftLayer/CLI/file/modify.py

Lines changed: 31 additions & 3 deletions
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 exceptions
8+
from SoftLayer import utils
89

910

1011
CONTEXT_SETTINGS = {'token_normalize_func': lambda x: x.upper()}
@@ -20,8 +21,7 @@
2021
'Potential Sizes: [20, 40, 80, 100, 250, '
2122
'500, 1000, 2000, 4000, 8000, 12000] '
2223
'Minimum: [the size of the origin volume] '
23-
'Maximum: [the minimum of 12000 GB or '
24-
'10*(origin volume size)]')
24+
'Maximum: 12000 GB.')
2525
@click.option('--new-iops', '-i',
2626
type=int,
2727
help='Performance Storage IOPS, between 100 and 6000 in '
@@ -37,7 +37,7 @@
3737
help='Endurance Storage Tier (IOPS per GB) [only used for '
3838
'endurance volumes] ***If no tier is specified, the original tier '
3939
'of the volume will be used.***\n'
40-
'Requirements: [IOPS/GB for the volume is 0.25, '
40+
'Requirements: [If original IOPS/GB for the volume is 0.25, '
4141
'new IOPS/GB for the volume must also be 0.25. If original IOPS/GB '
4242
'for the volume is greater than 0.25, new IOPS/GB '
4343
'for the volume must also be greater than 0.25.]',
@@ -46,6 +46,34 @@
4646
def cli(env, volume_id, new_size, new_iops, new_tier):
4747
"""Modify an existing file storage volume."""
4848
file_manager = SoftLayer.FileStorageManager(env.client)
49+
50+
file_volume = file_manager.get_file_volume_details(volume_id)
51+
file_volume = utils.NestedDict(file_volume)
52+
53+
storage_type = file_volume['storageType']['keyName'].split('_').pop(0)
54+
help_message = "For help, try \"slcli file volume-modify --help\""
55+
56+
if storage_type == 'ENDURANCE':
57+
if new_iops is not None:
58+
raise exceptions.CLIAbort(
59+
'Invalid option --new-iops for Endurance volume. Please use --new-tier instead.')
60+
61+
if new_size is None and new_tier is None:
62+
raise exceptions.CLIAbort(
63+
'Option --new-size or --new-tier must be specified for modifying an Endurance volume. \n'+
64+
help_message
65+
)
66+
67+
if storage_type == 'PERFORMANCE':
68+
if new_tier is not None:
69+
raise exceptions.CLIAbort(
70+
'Invalid option --new-tier for Performance volume. Please use --new-iops instead.')
71+
72+
if new_size is None and new_iops is None:
73+
raise exceptions.CLIAbort(
74+
'Option --new-size or --new-iops must be specified for modifying a Performance volume. \n' +
75+
help_message
76+
)
4977

5078
if new_tier is not None:
5179
new_tier = float(new_tier)

SoftLayer/CLI/routes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@
7979
('block:volume-count', 'SoftLayer.CLI.block.count:cli'),
8080
('block:volume-detail', 'SoftLayer.CLI.block.detail:cli'),
8181
('block:volume-duplicate', 'SoftLayer.CLI.block.duplicate:cli'),
82-
('block:volume-modify', 'SoftLayer.CLI.block.modify:cli'),
8382
('block:volume-list', 'SoftLayer.CLI.block.list:cli'),
83+
('block:volume-modify', 'SoftLayer.CLI.block.modify:cli'),
8484
('block:volume-order', 'SoftLayer.CLI.block.order:cli'),
8585
('block:volume-set-lun-id', 'SoftLayer.CLI.block.lun:cli'),
8686

@@ -105,8 +105,8 @@
105105
('file:volume-count', 'SoftLayer.CLI.file.count:cli'),
106106
('file:volume-detail', 'SoftLayer.CLI.file.detail:cli'),
107107
('file:volume-duplicate', 'SoftLayer.CLI.file.duplicate:cli'),
108-
('file:volume-modify', 'SoftLayer.CLI.file.modify:cli'),
109108
('file:volume-list', 'SoftLayer.CLI.file.list:cli'),
109+
('file:volume-modify', 'SoftLayer.CLI.file.modify:cli'),
110110
('file:volume-order', 'SoftLayer.CLI.file.order:cli'),
111111

112112
('firewall', 'SoftLayer.CLI.firewall'),

SoftLayer/managers/file.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ def order_modified_volume(self, volume_id,
297297

298298
file_mask = 'id,billingItem[location,hourlyFlag],snapshotCapacityGb,'\
299299
'storageType[keyName],capacityGb,originalVolumeSize,'\
300-
'provisionedIops,storageTierLevel,osType[keyName],'\
300+
'provisionedIops,storageTierLevel,'\
301301
'staasVersion,hasEncryptionAtRest'
302302
origin_volume = self.get_file_volume_details(volume_id,
303303
mask=file_mask)

SoftLayer/managers/storage_utils.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,7 +1003,7 @@ def prepare_duplicate_order_object(manager, origin_volume, iops, tier,
10031003

10041004
def prepare_modify_order_object(manager, origin_volume, new_iops, new_tier,
10051005
new_size, volume_type):
1006-
"""Prepare the duplicate order to submit to SoftLayer_Product::placeOrder()
1006+
"""Prepare the modification order to submit to SoftLayer_Product::placeOrder()
10071007
10081008
:param manager: The File or Block manager calling this function
10091009
:param origin_volume: The origin volume which is being modified
@@ -1078,7 +1078,6 @@ def prepare_modify_order_object(manager, origin_volume, new_iops, new_tier,
10781078
'packageId': package['id'],
10791079
'prices': prices,
10801080
'volume': origin_volume,
1081-
#'useHourlyPricing' : 'true',
10821081
'volumeSize': new_size
10831082
}
10841083

tests/CLI/modules/block_tests.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,13 @@ def test_volume_detail(self):
8686
{'Replicant ID': 'Data Center', '1785': 'dal01'},
8787
{'Replicant ID': 'Schedule', '1785': 'REPLICATION_DAILY'},
8888
]],
89-
'Duplicate Volume Properties': [
90-
{'Original Volume Name': 'Original Volume Size',
91-
'test-origin-volume-name': '20'},
92-
{'Original Volume Name': 'Original Snapshot Name',
93-
'test-origin-volume-name': 'test-origin-snapshot-name'}
89+
'Original Volume Properties': [
90+
{'Property': 'Original Volume Size',
91+
'Value': '20'},
92+
{'Property': 'Original Volume Name',
93+
'Value': 'test-origin-volume-name'},
94+
{'Property': 'Original Snapshot Name',
95+
'Value': 'test-origin-snapshot-name'}
9496
]
9597
}, json.loads(result.output))
9698

tests/CLI/modules/file_tests.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,13 @@ def test_volume_detail(self):
126126
{'Replicant ID': 'Data Center', '1785': 'dal01'},
127127
{'Replicant ID': 'Schedule', '1785': 'REPLICATION_DAILY'},
128128
]],
129-
'Duplicate Volume Properties': [
130-
{'Original Volume Name': 'Original Volume Size',
131-
'test-origin-volume-name': '20'},
132-
{'Original Volume Name': 'Original Snapshot Name',
133-
'test-origin-volume-name': 'test-origin-snapshot-name'}
129+
'Original Volume Properties': [
130+
{'Property': 'Original Volume Size',
131+
'Value': '20'},
132+
{'Property': 'Original Volume Name',
133+
'Value': 'test-origin-volume-name'},
134+
{'Property': 'Original Snapshot Name',
135+
'Value': 'test-origin-snapshot-name'}
134136
]
135137
}, json.loads(result.output))
136138

0 commit comments

Comments
 (0)