Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions SoftLayer/CLI/block/order.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from SoftLayer.CLI import exceptions


CONTEXT_SETTINGS = dict(token_normalize_func=lambda x: x.upper())
CONTEXT_SETTINGS = {'token_normalize_func': lambda x: x.upper()}


@click.command(context_settings=CONTEXT_SETTINGS)
Expand Down Expand Up @@ -42,8 +42,14 @@
@click.option('--location',
help='Datacenter short name (e.g.: dal09)',
required=True)
@click.option('--snapshot-size',
type=int,
help='Optional parameter for ordering snapshot '
'space along with endurance block storage; specifies '
'the size (in GB) of snapshot space to order')
@environment.pass_env
def cli(env, storage_type, size, iops, tier, os_type, location):
def cli(env, storage_type, size, iops, tier, os_type,
location, snapshot_size):
"""Order a block storage volume."""
block_manager = SoftLayer.BlockStorageManager(env.client)
storage_type = storage_type.lower()
Expand All @@ -62,6 +68,12 @@ def cli(env, storage_type, size, iops, tier, os_type, location):
'Option --iops must be a multiple of 100'
)

if snapshot_size is not None:
raise exceptions.CLIAbort(
'Option --snapshot-size not allowed for performance volumes.'
' Snapshots are only available for endurance storage.'
)

try:
order = block_manager.order_block_volume(
storage_type='performance_storage_iscsi',
Expand All @@ -84,7 +96,8 @@ def cli(env, storage_type, size, iops, tier, os_type, location):
location=location,
size=size,
tier_level=float(tier),
os_type=os_type
os_type=os_type,
snapshot_size=snapshot_size
)
except ValueError as ex:
raise exceptions.ArgumentError(str(ex))
Expand Down
19 changes: 16 additions & 3 deletions SoftLayer/CLI/file/order.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from SoftLayer.CLI import exceptions


CONTEXT_SETTINGS = dict(token_normalize_func=lambda x: x.upper())
CONTEXT_SETTINGS = {'token_normalize_func': lambda x: x.upper()}


@click.command(context_settings=CONTEXT_SETTINGS)
Expand Down Expand Up @@ -42,8 +42,14 @@
@click.option('--location',
help='Datacenter short name (e.g.: dal09)',
required=True)
@click.option('--snapshot-size',
type=int,
help='Optional parameter for ordering snapshot '
'space along with endurance file storage; specifies '
'the size (in GB) of snapshot space to order')
@environment.pass_env
def cli(env, storage_type, size, iops, tier, os_type, location):
def cli(env, storage_type, size, iops, tier, os_type,
location, snapshot_size):
"""Order a file storage volume."""
file_manager = SoftLayer.FileStorageManager(env.client)
storage_type = storage_type.lower()
Expand All @@ -62,6 +68,12 @@ def cli(env, storage_type, size, iops, tier, os_type, location):
'Option --iops must be a multiple of 100'
)

if snapshot_size is not None:
raise exceptions.CLIAbort(
'Option --snapshot-size not allowed for performance volumes.'
' Snapshots are only available for endurance storage.'
)

try:
order = file_manager.order_file_volume(
storage_type='performance_storage_nfs',
Expand All @@ -84,7 +96,8 @@ def cli(env, storage_type, size, iops, tier, os_type, location):
location=location,
size=size,
tier_level=float(tier),
os_type=os_type
os_type=os_type,
snapshot_size=snapshot_size
)
except ValueError as ex:
raise exceptions.ArgumentError(str(ex))
Expand Down
7 changes: 6 additions & 1 deletion SoftLayer/managers/block.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ def delete_snapshot(self, snapshot_id):
id=snapshot_id)

def order_block_volume(self, storage_type, location, size, os_type,
iops=None, tier_level=None):
iops=None, tier_level=None, snapshot_size=None):
"""Places an order for a block volume.

:param storage_type: "performance_storage_iscsi" (performance)
Expand All @@ -203,6 +203,8 @@ def order_block_volume(self, storage_type, location, size, os_type,
:param os_type: OS Type to use for volume alignment, see help for list
:param iops: Number of IOPs for a "Performance" order
:param tier_level: Tier level to use for an "Endurance" order
:param snapshot_size: The size of optional snapshot space,
if snapshot space should also be ordered (None if not ordered)
"""

try:
Expand Down Expand Up @@ -239,6 +241,9 @@ def order_block_volume(self, storage_type, location, size, os_type,
),
storage_utils.find_endurance_tier_price(package, tier_level),
]
if snapshot_size is not None:
prices.append(storage_utils.find_snapshot_space_price(
package, snapshot_size, tier_level))
else:
raise exceptions.SoftLayerError(
"Block volume storage_type must be either "
Expand Down
7 changes: 6 additions & 1 deletion SoftLayer/managers/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ def delete_snapshot(self, snapshot_id):
id=snapshot_id)

def order_file_volume(self, storage_type, location, size, os_type,
iops=None, tier_level=None):
iops=None, tier_level=None, snapshot_size=None):
"""Places an order for a file volume.

:param storage_type: "performance_storage_iscsi" (performance)
Expand All @@ -206,6 +206,8 @@ def order_file_volume(self, storage_type, location, size, os_type,
:param os_type: OS Type to use for volume alignment, see help for list
:param iops: Number of IOPs for a "Performance" order
:param tier_level: Tier level to use for an "Endurance" order
:param snapshot_size: The size of optional snapshot space,
if snapshot space should also be ordered (None if not ordered)
"""

try:
Expand Down Expand Up @@ -242,6 +244,9 @@ def order_file_volume(self, storage_type, location, size, os_type,
),
storage_utils.find_endurance_tier_price(package, tier_level),
]
if snapshot_size is not None:
prices.append(storage_utils.find_snapshot_space_price(
package, snapshot_size, tier_level))
else:
raise exceptions.SoftLayerError(
"File volume storage_type must be either "
Expand Down
94 changes: 86 additions & 8 deletions tests/CLI/modules/block_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,29 +101,107 @@ def test_volume_list(self):
}],
json.loads(result.output))

def test_volume_order_performance_iops_not_given(self):
result = self.run_command(['block', 'volume-order',
'--storage-type=performance', '--size=20',
'--os-type=linux', '--location=dal05'])

self.assertEqual(2, result.exit_code)

def test_volume_order_performance_iops_out_of_range(self):
result = self.run_command(['block', 'volume-order',
'--storage-type=performance', '--size=20',
'--iops=80000', '--os-type=linux',
'--location=dal05'])

self.assertEqual(2, result.exit_code)

def test_volume_order_performance_iops_not_multiple_of_100(self):
result = self.run_command(['block', 'volume-order',
'--storage-type=performance', '--size=20',
'--iops=122', '--os-type=linux',
'--location=dal05'])

self.assertEqual(2, result.exit_code)

def test_volume_order_performance_snapshot_error(self):
result = self.run_command(['block', 'volume-order',
'--storage-type=performance', '--size=20',
'--iops=100', '--os-type=linux',
'--location=dal05', '--snapshot-size=10'])

self.assertEqual(2, result.exit_code)

@mock.patch('SoftLayer.BlockStorageManager.order_block_volume')
def test_volume_order_performance(self, order_mock):
order_mock.return_value = {
'placedOrder': {
'id': 478,
'items': [
{'description': 'Performance Storage'},
{'description': 'Block Storage'},
{'description': '0.25 IOPS per GB'},
{'description': '20 GB Storage Space'}]
}
}

result = self.run_command(['block', 'volume-order',
'--storage-type=performance', '--size=20',
'--iops=100', '--os-type=linux',
'--location=dal05'])

self.assert_no_fail(result)
self.assertEqual(result.output,
'Order #478 placed successfully!\n'
' > Performance Storage\n > Block Storage\n'
' > 0.25 IOPS per GB\n > 20 GB Storage Space\n')

def test_volume_order_endurance_tier_not_given(self):
result = self.run_command(['block', 'volume-order',
'--storage-type=endurance', '--size=20',
'--os-type=linux', '--location=dal05'])

self.assertEqual(2, result.exit_code)

@mock.patch('SoftLayer.BlockStorageManager.order_block_volume')
def test_volume_order(self, order_mock):
def test_volume_order_endurance(self, order_mock):
order_mock.return_value = {
'placedOrder': {
'id': 478,
'items': [{'description': 'Endurance Storage'},
{'description': 'Block Storage'},
{'description': '0.25 IOPS per GB'},
{'description': '20 GB Storage Space'},
]
'items': [
{'description': 'Endurance Storage'},
{'description': 'Block Storage'},
{'description': '0.25 IOPS per GB'},
{'description': '20 GB Storage Space'},
{'description': '10 GB Storage Space (Snapshot Space)'}]
}
}

result = self.run_command(['block', 'volume-order',
'--storage-type=endurance', '--size=20',
'--tier=0.25', '--os-type=linux',
'--location=dal05'])
'--location=dal05', '--snapshot-size=10'])

self.assert_no_fail(result)
self.assertEqual(result.output,
'Order #478 placed successfully!\n'
' > Endurance Storage\n > Block Storage\n'
' > 0.25 IOPS per GB\n > 20 GB Storage Space\n')
' > 0.25 IOPS per GB\n > 20 GB Storage Space\n'
' > 10 GB Storage Space (Snapshot Space)\n')

@mock.patch('SoftLayer.BlockStorageManager.order_block_volume')
def test_volume_order_order_not_placed(self, order_mock):
order_mock.return_value = {}

result = self.run_command(['block', 'volume-order',
'--storage-type=endurance', '--size=20',
'--tier=0.25', '--os-type=linux',
'--location=dal05'])

self.assert_no_fail(result)
self.assertEqual(result.output,
'Order could not be placed! Please verify '
'your options and try again.\n')

def test_enable_snapshots(self):
result = self.run_command(['block', 'snapshot-enable', '12345678',
Expand Down
94 changes: 86 additions & 8 deletions tests/CLI/modules/file_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,29 +131,107 @@ def test_volume_detail(self):
'# of Active Transactions': '0'
}, json.loads(result.output))

def test_volume_order_performance_iops_not_given(self):
result = self.run_command(['file', 'volume-order',
'--storage-type=performance', '--size=20',
'--os-type=linux', '--location=dal05'])

self.assertEqual(2, result.exit_code)

def test_volume_order_performance_iops_out_of_range(self):
result = self.run_command(['file', 'volume-order',
'--storage-type=performance', '--size=20',
'--iops=80000', '--os-type=linux',
'--location=dal05'])

self.assertEqual(2, result.exit_code)

def test_volume_order_performance_iops_not_multiple_of_100(self):
result = self.run_command(['file', 'volume-order',
'--storage-type=performance', '--size=20',
'--iops=122', '--os-type=linux',
'--location=dal05'])

self.assertEqual(2, result.exit_code)

def test_volume_order_performance_snapshot_error(self):
result = self.run_command(['file', 'volume-order',
'--storage-type=performance', '--size=20',
'--iops=100', '--os-type=linux',
'--location=dal05', '--snapshot-size=10'])

self.assertEqual(2, result.exit_code)

@mock.patch('SoftLayer.FileStorageManager.order_file_volume')
def test_volume_order_performance(self, order_mock):
order_mock.return_value = {
'placedOrder': {
'id': 478,
'items': [
{'description': 'Performance Storage'},
{'description': 'File Storage'},
{'description': '0.25 IOPS per GB'},
{'description': '20 GB Storage Space'}]
}
}

result = self.run_command(['file', 'volume-order',
'--storage-type=performance', '--size=20',
'--iops=100', '--os-type=linux',
'--location=dal05'])

self.assert_no_fail(result)
self.assertEqual(result.output,
'Order #478 placed successfully!\n'
' > Performance Storage\n > File Storage\n'
' > 0.25 IOPS per GB\n > 20 GB Storage Space\n')

def test_volume_order_endurance_tier_not_given(self):
result = self.run_command(['file', 'volume-order',
'--storage-type=endurance', '--size=20',
'--os-type=linux', '--location=dal05'])

self.assertEqual(2, result.exit_code)

@mock.patch('SoftLayer.FileStorageManager.order_file_volume')
def test_volume_order(self, order_mock):
def test_volume_order_endurance(self, order_mock):
order_mock.return_value = {
'placedOrder': {
'id': 478,
'items': [{'description': 'Endurance Storage'},
{'description': 'File Storage'},
{'description': '0.25 IOPS per GB'},
{'description': '20 GB Storage Space'},
]
'items': [
{'description': 'Endurance Storage'},
{'description': 'File Storage'},
{'description': '0.25 IOPS per GB'},
{'description': '20 GB Storage Space'},
{'description': '10 GB Storage Space (Snapshot Space)'}]
}
}

result = self.run_command(['file', 'volume-order',
'--storage-type=endurance', '--size=20',
'--tier=0.25', '--os-type=linux',
'--location=dal05'])
'--location=dal05', '--snapshot-size=10'])

self.assert_no_fail(result)
self.assertEqual(result.output,
'Order #478 placed successfully!\n'
' > Endurance Storage\n > File Storage\n'
' > 0.25 IOPS per GB\n > 20 GB Storage Space\n')
' > 0.25 IOPS per GB\n > 20 GB Storage Space\n'
' > 10 GB Storage Space (Snapshot Space)\n')

@mock.patch('SoftLayer.FileStorageManager.order_file_volume')
def test_volume_order_order_not_placed(self, order_mock):
order_mock.return_value = {}

result = self.run_command(['file', 'volume-order',
'--storage-type=endurance', '--size=20',
'--tier=0.25', '--os-type=linux',
'--location=dal05'])

self.assert_no_fail(result)
self.assertEqual(result.output,
'Order could not be placed! Please verify '
'your options and try again.\n')

def test_enable_snapshots(self):
result = self.run_command(['file', 'snapshot-enable', '12345678',
Expand Down
Loading