|
| 1 | +"""Order a duplicate 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('origin-volume-id') |
| 15 | +@click.option('--origin-snapshot-id', '-o', |
| 16 | + type=int, |
| 17 | + help="ID of an origin volume snapshot to use for duplcation.") |
| 18 | +@click.option('--duplicate-size', '-c', |
| 19 | + type=int, |
| 20 | + help='Size of duplicate block volume in GB. ' |
| 21 | + '***If no size is specified, the size of ' |
| 22 | + 'the origin volume will be used.***\n' |
| 23 | + 'Potential Sizes: [20, 40, 80, 100, 250, ' |
| 24 | + '500, 1000, 2000, 4000, 8000, 12000] ' |
| 25 | + 'Minimum: [the size of the origin volume] ' |
| 26 | + 'Maximum: [the minimum of 12000 GB or ' |
| 27 | + '10*(origin volume size)]') |
| 28 | +@click.option('--duplicate-iops', '-i', |
| 29 | + type=int, |
| 30 | + help='Performance Storage IOPS, between 100 and 6000 in ' |
| 31 | + 'multiples of 100 [only used for performance volumes] ' |
| 32 | + '***If no IOPS value is specified, the IOPS value of the ' |
| 33 | + 'origin volume will be used.***\n' |
| 34 | + 'Requirements: [If IOPS/GB for the origin volume is less ' |
| 35 | + 'than 0.3, IOPS/GB for the duplicate must also be less ' |
| 36 | + 'than 0.3. If IOPS/GB for the origin volume is greater ' |
| 37 | + 'than or equal to 0.3, IOPS/GB for the duplicate must ' |
| 38 | + 'also be greater than or equal to 0.3.]') |
| 39 | +@click.option('--duplicate-tier', '-t', |
| 40 | + help='Endurance Storage Tier (IOPS per GB) [only used for ' |
| 41 | + 'endurance volumes] ***If no tier is specified, the tier ' |
| 42 | + 'of the origin volume will be used.***\n' |
| 43 | + 'Requirements: [If IOPS/GB for the origin volume is 0.25, ' |
| 44 | + 'IOPS/GB for the duplicate must also be 0.25. If IOPS/GB ' |
| 45 | + 'for the origin volume is greater than 0.25, IOPS/GB ' |
| 46 | + 'for the duplicate must also be greater than 0.25.]', |
| 47 | + type=click.Choice(['0.25', '2', '4', '10'])) |
| 48 | +@click.option('--duplicate-snapshot-size', '-s', |
| 49 | + type=int, |
| 50 | + help='The size of snapshot space to order for the duplicate. ' |
| 51 | + '***If no snapshot space size is specified, the snapshot ' |
| 52 | + 'space size of the origin volume will be used.***\n' |
| 53 | + 'Input "0" for this parameter to order a duplicate volume ' |
| 54 | + 'with no snapshot space.') |
| 55 | +@environment.pass_env |
| 56 | +def cli(env, origin_volume_id, origin_snapshot_id, duplicate_size, |
| 57 | + duplicate_iops, duplicate_tier, duplicate_snapshot_size): |
| 58 | + """Order a duplicate block storage volume.""" |
| 59 | + block_manager = SoftLayer.BlockStorageManager(env.client) |
| 60 | + |
| 61 | + if duplicate_tier is not None: |
| 62 | + duplicate_tier = float(duplicate_tier) |
| 63 | + |
| 64 | + try: |
| 65 | + order = block_manager.order_duplicate_volume( |
| 66 | + origin_volume_id, |
| 67 | + origin_snapshot_id=origin_snapshot_id, |
| 68 | + duplicate_size=duplicate_size, |
| 69 | + duplicate_iops=duplicate_iops, |
| 70 | + duplicate_tier_level=duplicate_tier, |
| 71 | + duplicate_snapshot_size=duplicate_snapshot_size |
| 72 | + ) |
| 73 | + except ValueError as ex: |
| 74 | + raise exceptions.ArgumentError(str(ex)) |
| 75 | + |
| 76 | + if 'placedOrder' in order.keys(): |
| 77 | + click.echo("Order #{0} placed successfully!".format( |
| 78 | + order['placedOrder']['id'])) |
| 79 | + for item in order['placedOrder']['items']: |
| 80 | + click.echo(" > %s" % item['description']) |
| 81 | + else: |
| 82 | + click.echo("Order could not be placed! Please verify your options " + |
| 83 | + "and try again.") |
0 commit comments