|
| 1 | +"""Order a block storage replica 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('--snapshot-schedule', '-s', |
| 16 | + help='Snapshot schedule to use for replication, ' |
| 17 | + '(HOURLY | DAILY | WEEKLY)', |
| 18 | + required=True, |
| 19 | + type=click.Choice(['HOURLY', 'DAILY', 'WEEKLY'])) |
| 20 | +@click.option('--location', '-l', |
| 21 | + help='Short name of the data center for the replicant ' |
| 22 | + '(e.g.: dal09)', |
| 23 | + required=True) |
| 24 | +@click.option('--tier', |
| 25 | + help='Endurance Storage Tier (IOPS per GB) of the primary' |
| 26 | + ' volume for which a replicant is ordered [optional]', |
| 27 | + type=click.Choice(['0.25', '2', '4'])) |
| 28 | +@click.option('--os-type', |
| 29 | + help='Operating System Type (e.g.: LINUX) of the primary' |
| 30 | + ' volume for which a replica is ordered [optional]', |
| 31 | + type=click.Choice([ |
| 32 | + 'HYPER_V', |
| 33 | + 'LINUX', |
| 34 | + 'VMWARE', |
| 35 | + 'WINDOWS_2008', |
| 36 | + 'WINDOWS_GPT', |
| 37 | + 'WINDOWS', |
| 38 | + 'XEN'])) |
| 39 | +@environment.pass_env |
| 40 | +def cli(env, volume_id, snapshot_schedule, location, tier, os_type): |
| 41 | + """Order a block storage replica volume.""" |
| 42 | + block_manager = SoftLayer.BlockStorageManager(env.client) |
| 43 | + |
| 44 | + if tier is not None: |
| 45 | + tier = float(tier) |
| 46 | + |
| 47 | + try: |
| 48 | + order = block_manager.order_replicant_volume( |
| 49 | + volume_id, |
| 50 | + snapshot_schedule=snapshot_schedule, |
| 51 | + location=location, |
| 52 | + tier=tier, |
| 53 | + os_type=os_type, |
| 54 | + ) |
| 55 | + except ValueError as ex: |
| 56 | + raise exceptions.ArgumentError(str(ex)) |
| 57 | + |
| 58 | + if 'placedOrder' in order.keys(): |
| 59 | + click.echo("Order #{0} placed successfully!".format( |
| 60 | + order['placedOrder']['id'])) |
| 61 | + for item in order['placedOrder']['items']: |
| 62 | + click.echo(" > %s" % item['description']) |
| 63 | + else: |
| 64 | + click.echo("Order could not be placed! Please verify your options " + |
| 65 | + "and try again.") |
0 commit comments