|
| 1 | +"""Modify an existing block storage volume.""" |
| 2 | +# :license: MIT, see LICENSE for more details. |
| 3 | + |
| 4 | +import click |
| 5 | +import SoftLayer |
| 6 | +from SoftLayer.CLI import environment |
| 7 | +from SoftLayer.CLI import exceptions |
| 8 | + |
| 9 | + |
| 10 | +CONTEXT_SETTINGS = {'token_normalize_func': lambda x: x.upper()} |
| 11 | + |
| 12 | + |
| 13 | +@click.command(context_settings=CONTEXT_SETTINGS) |
| 14 | +@click.argument('volume-id') |
| 15 | +@click.option('--new-size', '-c', |
| 16 | + type=int, |
| 17 | + help='New Size of block volume in GB. ***If no size is given, the original size of volume is used.***\n' |
| 18 | + 'Potential Sizes: [20, 40, 80, 100, 250, 500, 1000, 2000, 4000, 8000, 12000]\n' |
| 19 | + 'Minimum: [the original size of the volume]') |
| 20 | +@click.option('--new-iops', '-i', |
| 21 | + type=int, |
| 22 | + help='Performance Storage IOPS, between 100 and 6000 in multiples of 100 [only for performance volumes] ' |
| 23 | + '***If no IOPS value is specified, the original IOPS value of the volume will be used.***\n' |
| 24 | + 'Requirements: [If original IOPS/GB for the volume is less than 0.3, new IOPS/GB must also be ' |
| 25 | + 'less than 0.3. If original IOPS/GB for the volume is greater than or equal to 0.3, new IOPS/GB ' |
| 26 | + 'for the volume must also be greater than or equal to 0.3.]') |
| 27 | +@click.option('--new-tier', '-t', |
| 28 | + help='Endurance Storage Tier (IOPS per GB) [only for endurance volumes] ' |
| 29 | + '***If no tier is specified, the original tier of the volume will be used.***\n' |
| 30 | + 'Requirements: [If original IOPS/GB for the volume is 0.25, new IOPS/GB for the volume must also ' |
| 31 | + 'be 0.25. If original IOPS/GB for the volume is greater than 0.25, new IOPS/GB for the volume ' |
| 32 | + 'must also be greater than 0.25.]', |
| 33 | + type=click.Choice(['0.25', '2', '4', '10'])) |
| 34 | +@environment.pass_env |
| 35 | +def cli(env, volume_id, new_size, new_iops, new_tier): |
| 36 | + """Modify an existing block storage volume.""" |
| 37 | + block_manager = SoftLayer.BlockStorageManager(env.client) |
| 38 | + |
| 39 | + if new_tier is not None: |
| 40 | + new_tier = float(new_tier) |
| 41 | + |
| 42 | + try: |
| 43 | + order = block_manager.order_modified_volume( |
| 44 | + volume_id, |
| 45 | + new_size=new_size, |
| 46 | + new_iops=new_iops, |
| 47 | + new_tier_level=new_tier, |
| 48 | + ) |
| 49 | + except ValueError as ex: |
| 50 | + raise exceptions.ArgumentError(str(ex)) |
| 51 | + |
| 52 | + if 'placedOrder' in order.keys(): |
| 53 | + click.echo("Order #{0} placed successfully!".format(order['placedOrder']['id'])) |
| 54 | + for item in order['placedOrder']['items']: |
| 55 | + click.echo(" > %s" % item['description']) |
| 56 | + else: |
| 57 | + click.echo("Order could not be placed! Please verify your options and try again.") |
0 commit comments