|
1 | 1 | """Order a block storage volume.""" |
2 | 2 | # :license: MIT, see LICENSE for more details. |
3 | 3 |
|
| 4 | +import click |
4 | 5 | import SoftLayer |
5 | 6 | from SoftLayer.CLI import environment |
6 | 7 | from SoftLayer.CLI import exceptions |
7 | | -import click |
8 | 8 |
|
9 | 9 |
|
10 | | -@click.command() |
11 | | -@click.option('--storage_type', |
| 10 | +CONTEXT_SETTINGS = dict(token_normalize_func=lambda x: x.upper()) |
| 11 | + |
| 12 | + |
| 13 | +@click.command(context_settings=CONTEXT_SETTINGS) |
| 14 | +@click.option('--storage-type', |
12 | 15 | help='Type of storage volume', |
13 | 16 | type=click.Choice(['performance', 'endurance']), |
14 | 17 | required=True) |
15 | 18 | @click.option('--size', |
16 | | - help='Size of storage volume', |
| 19 | + type=int, |
| 20 | + help='Size of storage volume in GB', |
17 | 21 | required=True) |
18 | 22 | @click.option('--iops', |
19 | | - help='Performance Storage IOPs') |
| 23 | + type=int, |
| 24 | + help='Performance Storage IOPs,' |
| 25 | + + ' between 100 and 6000 in multiples of 100' |
| 26 | + + ' [required for storage-type performance]') |
20 | 27 | @click.option('--tier', |
21 | | - help='Endurance Storage Tier (IOP per GB)', |
| 28 | + help='Endurance Storage Tier (IOP per GB)' |
| 29 | + + ' [required for storage-type endurance]', |
22 | 30 | type=click.Choice(['0.25', '2', '4'])) |
23 | | -@click.option('--os', |
| 31 | +@click.option('--os-type', |
24 | 32 | help='Operating System', |
25 | 33 | type=click.Choice([ |
26 | 34 | 'HYPER_V', |
|
32 | 40 | 'XEN']), |
33 | 41 | required=True) |
34 | 42 | @click.option('--location', |
35 | | - help='Size of storage volume', |
| 43 | + help='Datacenter short name (e.g.: dal09)', |
36 | 44 | required=True) |
37 | 45 | @environment.pass_env |
38 | | -def cli(env, storage_type, size, iops, tier, os, location): |
| 46 | +def cli(env, storage_type, size, iops, tier, os_type, location): |
39 | 47 | """Order a block storage volume.""" |
40 | 48 | block_manager = SoftLayer.BlockStorageManager(env.client) |
| 49 | + storage_type = storage_type.lower() |
41 | 50 |
|
42 | 51 | if storage_type == 'performance': |
43 | 52 | if iops is None: |
44 | | - raise exceptions.CLIAbort('Option --iops required with performance') |
| 53 | + raise exceptions.CLIAbort( |
| 54 | + 'Option --iops required with Performance') |
| 55 | + |
| 56 | + if iops < 100 or iops > 6000: |
| 57 | + raise exceptions.CLIAbort( |
| 58 | + 'Option --iops must be between 100 and 6000, inclusive') |
| 59 | + |
| 60 | + if iops % 100 != 0: |
| 61 | + raise exceptions.CLIAbort( |
| 62 | + 'Option --iops must be a multiple of 100' |
| 63 | + ) |
45 | 64 |
|
46 | 65 | order = block_manager.order_block_volume( |
47 | 66 | storage_type='performance_storage_iscsi', |
48 | 67 | location=location, |
49 | 68 | size=size, |
50 | 69 | iops=iops, |
51 | | - os_type=os |
| 70 | + os_type=os_type |
52 | 71 | ) |
53 | 72 |
|
54 | 73 | if storage_type == 'endurance': |
55 | 74 | if tier is None: |
56 | | - raise exceptions.CLIAbort('Option --tier required with performance') |
| 75 | + raise exceptions.CLIAbort( |
| 76 | + 'Option --tier required with Endurance in IOPS/GB [0.25,2,4]') |
57 | 77 |
|
58 | 78 | order = block_manager.order_block_volume( |
59 | 79 | storage_type='storage_service_enterprise', |
60 | 80 | location=location, |
61 | 81 | size=size, |
62 | 82 | tier_level=tier, |
63 | | - os_type=os |
| 83 | + os_type=os_type |
64 | 84 | ) |
65 | 85 |
|
66 | 86 | if 'placedOrder' in order.keys(): |
67 | | - print "Order #{0} placed successfully!".format( |
68 | | - order['placedOrder']['id']) |
| 87 | + click.echo("Order #{0} placed successfully!".format( |
| 88 | + order['placedOrder']['id'])) |
69 | 89 | for item in order['placedOrder']['items']: |
70 | | - print " > %s" % item['description'] |
| 90 | + click.echo(" > %s" % item['description']) |
71 | 91 | else: |
72 | | - print "Order could not be placed! Please verify your options " \ |
73 | | - "and try again." |
| 92 | + click.echo("Order could not be placed! Please verify your options " + |
| 93 | + "and try again.") |
0 commit comments