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
22 changes: 10 additions & 12 deletions SoftLayer/CLI/block/detail.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,10 @@ def cli(env, volume_id):

if block_volume['activeTransactions']:
for trans in block_volume['activeTransactions']:
table.add_row([
'Ongoing Transactions',
trans['transactionStatus']['friendlyName']])
if 'transactionStatus' in trans and 'friendlyName' in trans['transactionStatus']:
table.add_row(['Ongoing Transaction', trans['transactionStatus']['friendlyName']])

table.add_row(['Replicant Count', "%u"
% block_volume['replicationPartnerCount']])
table.add_row(['Replicant Count', "%u" % block_volume.get('replicationPartnerCount', 0)])

if block_volume['replicationPartnerCount'] > 0:
# This if/else temporarily handles a bug in which the SL API
Expand Down Expand Up @@ -102,12 +100,12 @@ def cli(env, volume_id):
table.add_row(['Replicant Volumes', replicant_list])

if block_volume.get('originalVolumeSize'):
duplicate_info = formatting.Table(['Original Volume Name',
block_volume['originalVolumeName']])
duplicate_info.add_row(['Original Volume Size',
block_volume['originalVolumeSize']])
duplicate_info.add_row(['Original Snapshot Name',
block_volume['originalSnapshotName']])
table.add_row(['Duplicate Volume Properties', duplicate_info])
original_volume_info = formatting.Table(['Property', 'Value'])
original_volume_info.add_row(['Original Volume Size', block_volume['originalVolumeSize']])
if block_volume.get('originalVolumeName'):
original_volume_info.add_row(['Original Volume Name', block_volume['originalVolumeName']])
if block_volume.get('originalSnapshotName'):
original_volume_info.add_row(['Original Snapshot Name', block_volume['originalSnapshotName']])
table.add_row(['Original Volume Properties', original_volume_info])

env.fout(table)
4 changes: 1 addition & 3 deletions SoftLayer/CLI/block/duplicate.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@
'the origin volume will be used.***\n'
'Potential Sizes: [20, 40, 80, 100, 250, '
'500, 1000, 2000, 4000, 8000, 12000] '
'Minimum: [the size of the origin volume] '
'Maximum: [the minimum of 12000 GB or '
'10*(origin volume size)]')
'Minimum: [the size of the origin volume]')
@click.option('--duplicate-iops', '-i',
type=int,
help='Performance Storage IOPS, between 100 and 6000 in '
Expand Down
57 changes: 57 additions & 0 deletions SoftLayer/CLI/block/modify.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
"""Modify an existing block storage volume."""
# :license: MIT, see LICENSE for more details.

import click
import SoftLayer
from SoftLayer.CLI import environment
from SoftLayer.CLI import exceptions


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


@click.command(context_settings=CONTEXT_SETTINGS)
@click.argument('volume-id')
@click.option('--new-size', '-c',
type=int,
help='New Size of block volume in GB. ***If no size is given, the original size of volume is used.***\n'
'Potential Sizes: [20, 40, 80, 100, 250, 500, 1000, 2000, 4000, 8000, 12000]\n'
'Minimum: [the original size of the volume]')
@click.option('--new-iops', '-i',
type=int,
help='Performance Storage IOPS, between 100 and 6000 in multiples of 100 [only for performance volumes] '
'***If no IOPS value is specified, the original IOPS value of the volume will be used.***\n'
'Requirements: [If original IOPS/GB for the volume is less than 0.3, new IOPS/GB must also be '
'less than 0.3. If original IOPS/GB for the volume is greater than or equal to 0.3, new IOPS/GB '
'for the volume must also be greater than or equal to 0.3.]')
@click.option('--new-tier', '-t',
help='Endurance Storage Tier (IOPS per GB) [only for endurance volumes] '
'***If no tier is specified, the original tier of the volume will be used.***\n'
'Requirements: [If original IOPS/GB for the volume is 0.25, new IOPS/GB for the volume must also '
'be 0.25. If original IOPS/GB for the volume is greater than 0.25, new IOPS/GB for the volume '
'must also be greater than 0.25.]',
type=click.Choice(['0.25', '2', '4', '10']))
@environment.pass_env
def cli(env, volume_id, new_size, new_iops, new_tier):
"""Modify an existing block storage volume."""
block_manager = SoftLayer.BlockStorageManager(env.client)

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

try:
order = block_manager.order_modified_volume(
volume_id,
new_size=new_size,
new_iops=new_iops,
new_tier_level=new_tier,
)
except ValueError as ex:
raise exceptions.ArgumentError(str(ex))

if 'placedOrder' in order.keys():
click.echo("Order #{0} placed successfully!".format(order['placedOrder']['id']))
for item in order['placedOrder']['items']:
click.echo(" > %s" % item['description'])
else:
click.echo("Order could not be placed! Please verify your options and try again.")
22 changes: 10 additions & 12 deletions SoftLayer/CLI/file/detail.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,10 @@ def cli(env, volume_id):

if file_volume['activeTransactions']:
for trans in file_volume['activeTransactions']:
table.add_row([
'Ongoing Transactions',
trans['transactionStatus']['friendlyName']])
if 'transactionStatus' in trans and 'friendlyName' in trans['transactionStatus']:
table.add_row(['Ongoing Transaction', trans['transactionStatus']['friendlyName']])

table.add_row(['Replicant Count', "%u"
% file_volume['replicationPartnerCount']])
table.add_row(['Replicant Count', "%u" % file_volume.get('replicationPartnerCount', 0)])

if file_volume['replicationPartnerCount'] > 0:
# This if/else temporarily handles a bug in which the SL API
Expand Down Expand Up @@ -118,12 +116,12 @@ def cli(env, volume_id):
table.add_row(['Replicant Volumes', replicant_list])

if file_volume.get('originalVolumeSize'):
duplicate_info = formatting.Table(['Original Volume Name',
file_volume['originalVolumeName']])
duplicate_info.add_row(['Original Volume Size',
file_volume['originalVolumeSize']])
duplicate_info.add_row(['Original Snapshot Name',
file_volume['originalSnapshotName']])
table.add_row(['Duplicate Volume Properties', duplicate_info])
original_volume_info = formatting.Table(['Property', 'Value'])
original_volume_info.add_row(['Original Volume Size', file_volume['originalVolumeSize']])
if file_volume.get('originalVolumeName'):
original_volume_info.add_row(['Original Volume Name', file_volume['originalVolumeName']])
if file_volume.get('originalSnapshotName'):
original_volume_info.add_row(['Original Snapshot Name', file_volume['originalSnapshotName']])
table.add_row(['Original Volume Properties', original_volume_info])

env.fout(table)
57 changes: 57 additions & 0 deletions SoftLayer/CLI/file/modify.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
"""Modify an existing file storage volume."""
# :license: MIT, see LICENSE for more details.

import click
import SoftLayer
from SoftLayer.CLI import environment
from SoftLayer.CLI import exceptions


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


@click.command(context_settings=CONTEXT_SETTINGS)
@click.argument('volume-id')
@click.option('--new-size', '-c',
type=int,
help='New Size of file volume in GB. ***If no size is given, the original size of volume is used.***\n'
'Potential Sizes: [20, 40, 80, 100, 250, 500, 1000, 2000, 4000, 8000, 12000]\n'
'Minimum: [the original size of the volume]')
@click.option('--new-iops', '-i',
type=int,
help='Performance Storage IOPS, between 100 and 6000 in multiples of 100 [only for performance volumes] '
'***If no IOPS value is specified, the original IOPS value of the volume will be used.***\n'
'Requirements: [If original IOPS/GB for the volume is less than 0.3, new IOPS/GB must also be '
'less than 0.3. If original IOPS/GB for the volume is greater than or equal to 0.3, new IOPS/GB '
'for the volume must also be greater than or equal to 0.3.]')
@click.option('--new-tier', '-t',
help='Endurance Storage Tier (IOPS per GB) [only for endurance volumes] '
'***If no tier is specified, the original tier of the volume will be used.***\n'
'Requirements: [If original IOPS/GB for the volume is 0.25, new IOPS/GB for the volume must also '
'be 0.25. If original IOPS/GB for the volume is greater than 0.25, new IOPS/GB for the volume '
'must also be greater than 0.25.]',
type=click.Choice(['0.25', '2', '4', '10']))
@environment.pass_env
def cli(env, volume_id, new_size, new_iops, new_tier):
"""Modify an existing file storage volume."""
file_manager = SoftLayer.FileStorageManager(env.client)

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

try:
order = file_manager.order_modified_volume(
volume_id,
new_size=new_size,
new_iops=new_iops,
new_tier_level=new_tier,
)
except ValueError as ex:
raise exceptions.ArgumentError(str(ex))

if 'placedOrder' in order.keys():
click.echo("Order #{0} placed successfully!".format(order['placedOrder']['id']))
for item in order['placedOrder']['items']:
click.echo(" > %s" % item['description'])
else:
click.echo("Order could not be placed! Please verify your options and try again.")
2 changes: 2 additions & 0 deletions SoftLayer/CLI/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
('block:volume-detail', 'SoftLayer.CLI.block.detail:cli'),
('block:volume-duplicate', 'SoftLayer.CLI.block.duplicate:cli'),
('block:volume-list', 'SoftLayer.CLI.block.list:cli'),
('block:volume-modify', 'SoftLayer.CLI.block.modify:cli'),
('block:volume-order', 'SoftLayer.CLI.block.order:cli'),
('block:volume-set-lun-id', 'SoftLayer.CLI.block.lun:cli'),

Expand All @@ -105,6 +106,7 @@
('file:volume-detail', 'SoftLayer.CLI.file.detail:cli'),
('file:volume-duplicate', 'SoftLayer.CLI.file.duplicate:cli'),
('file:volume-list', 'SoftLayer.CLI.file.list:cli'),
('file:volume-modify', 'SoftLayer.CLI.file.modify:cli'),
('file:volume-order', 'SoftLayer.CLI.file.order:cli'),

('firewall', 'SoftLayer.CLI.firewall'),
Expand Down
10 changes: 6 additions & 4 deletions SoftLayer/fixtures/SoftLayer_Network_Storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@

getObject = {
'accountId': 1234,
'activeTransactionCount': 0,
'activeTransactions': None,
'activeTransactionCount': 1,
'activeTransactions': [{
'transactionStatus': {'friendlyName': 'This is a buffer time in which the customer may cancel the server'}
}],
'allowedHardware': [{
'allowedHost': {
'credential': {'username': 'joe', 'password': '12345'},
Expand Down Expand Up @@ -104,8 +106,8 @@
'lunId': 2,
'nasType': 'ISCSI',
'notes': """{'status': 'available'}""",
'originalSnapshotName': 'test-origin-snapshot-name',
'originalVolumeName': 'test-origin-volume-name',
'originalSnapshotName': 'test-original-snapshot-name',
'originalVolumeName': 'test-original-volume-name',
'originalVolumeSize': '20',
'osType': {'keyName': 'LINUX'},
'parentVolume': {'snapshotSizeBytes': 1024},
Expand Down
29 changes: 29 additions & 0 deletions SoftLayer/managers/block.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,35 @@ def order_duplicate_volume(self, origin_volume_id, origin_snapshot_id=None,

return self.client.call('Product_Order', 'placeOrder', order)

def order_modified_volume(self, volume_id, new_size=None, new_iops=None, new_tier_level=None):
"""Places an order for modifying an existing block volume.

:param volume_id: The ID of the volume to be modified
:param new_size: The new size/capacity for the volume
:param new_iops: The new IOPS for the volume
:param new_tier_level: The new tier level for the volume
:return: Returns a SoftLayer_Container_Product_Order_Receipt
"""

mask_items = [
'id',
'billingItem',
'storageType[keyName]',
'capacityGb',
'provisionedIops',
'storageTierLevel',
'staasVersion',
'hasEncryptionAtRest',
]
block_mask = ','.join(mask_items)
volume = self.get_block_volume_details(volume_id, mask=block_mask)

order = storage_utils.prepare_modify_order_object(
self, volume, new_iops, new_tier_level, new_size
)

return self.client.call('Product_Order', 'placeOrder', order)

def delete_snapshot(self, snapshot_id):
"""Deletes the specified snapshot object.

Expand Down
29 changes: 29 additions & 0 deletions SoftLayer/managers/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,35 @@ def order_duplicate_volume(self, origin_volume_id, origin_snapshot_id=None,

return self.client.call('Product_Order', 'placeOrder', order)

def order_modified_volume(self, volume_id, new_size=None, new_iops=None, new_tier_level=None):
"""Places an order for modifying an existing file volume.

:param volume_id: The ID of the volume to be modified
:param new_size: The new size/capacity for the volume
:param new_iops: The new IOPS for the volume
:param new_tier_level: The new tier level for the volume
:return: Returns a SoftLayer_Container_Product_Order_Receipt
"""

mask_items = [
'id',
'billingItem',
'storageType[keyName]',
'capacityGb',
'provisionedIops',
'storageTierLevel',
'staasVersion',
'hasEncryptionAtRest',
]
file_mask = ','.join(mask_items)
volume = self.get_file_volume_details(volume_id, mask=file_mask)

order = storage_utils.prepare_modify_order_object(
self, volume, new_iops, new_tier_level, new_size
)

return self.client.call('Product_Order', 'placeOrder', order)

def delete_snapshot(self, snapshot_id):
"""Deletes the specified snapshot object.

Expand Down
Loading