|
| 1 | +"""List Reserved Capacity""" |
| 2 | +# :license: MIT, see LICENSE for more details. |
| 3 | + |
| 4 | +import click |
| 5 | + |
| 6 | +from SoftLayer.CLI import environment |
| 7 | +from SoftLayer.CLI import formatting |
| 8 | +from SoftLayer.CLI import helpers |
| 9 | +from SoftLayer.CLI.virt.create import _parse_create_args as _parse_create_args |
| 10 | +from SoftLayer.CLI.virt.create import _update_with_like_args as _update_with_like_args |
| 11 | +from SoftLayer.managers.vs_capacity import CapacityManager as CapacityManager |
| 12 | + |
| 13 | + |
| 14 | +@click.command() |
| 15 | +@click.option('--capacity-id', type=click.INT, help="Reserve capacity Id to provision this guest into.") |
| 16 | +@click.option('--primary-disk', type=click.Choice(['25', '100']), default='25', help="Size of the main drive.") |
| 17 | +@click.option('--hostname', '-H', required=True, prompt=True, help="Host portion of the FQDN.") |
| 18 | +@click.option('--domain', '-D', required=True, prompt=True, help="Domain portion of the FQDN.") |
| 19 | +@click.option('--os', '-o', help="OS install code. Tip: you can specify <OS>_LATEST.") |
| 20 | +@click.option('--image', help="Image ID. See: 'slcli image list' for reference.") |
| 21 | +@click.option('--boot-mode', type=click.STRING, |
| 22 | + help="Specify the mode to boot the OS in. Supported modes are HVM and PV.") |
| 23 | +@click.option('--postinstall', '-i', help="Post-install script to download.") |
| 24 | +@helpers.multi_option('--key', '-k', help="SSH keys to add to the root user.") |
| 25 | +@helpers.multi_option('--disk', help="Additional disk sizes.") |
| 26 | +@click.option('--private', is_flag=True, help="Forces the VS to only have access the private network.") |
| 27 | +@click.option('--like', is_eager=True, callback=_update_with_like_args, |
| 28 | + help="Use the configuration from an existing VS.") |
| 29 | +@click.option('--network', '-n', help="Network port speed in Mbps.") |
| 30 | +@helpers.multi_option('--tag', '-g', help="Tags to add to the instance.") |
| 31 | +@click.option('--userdata', '-u', help="User defined metadata string.") |
| 32 | +@click.option('--ipv6', is_flag=True, help="Adds an IPv6 address to this guest") |
| 33 | +@click.option('--test', is_flag=True, |
| 34 | + help="Test order, will return the order container, but not actually order a server.") |
| 35 | +@environment.pass_env |
| 36 | +def cli(env, **args): |
| 37 | + """Allows for creating a virtual guest in a reserved capacity.""" |
| 38 | + create_args = _parse_create_args(env.client, args) |
| 39 | + if args.get('ipv6'): |
| 40 | + create_args['ipv6'] = True |
| 41 | + create_args['primary_disk'] = args.get('primary_disk') |
| 42 | + manager = CapacityManager(env.client) |
| 43 | + capacity_id = args.get('capacity_id') |
| 44 | + test = args.get('test') |
| 45 | + |
| 46 | + result = manager.create_guest(capacity_id, test, create_args) |
| 47 | + |
| 48 | + env.fout(_build_receipt(result, test)) |
| 49 | + |
| 50 | + |
| 51 | +def _build_receipt(result, test=False): |
| 52 | + title = "OrderId: %s" % (result.get('orderId', 'No order placed')) |
| 53 | + table = formatting.Table(['Item Id', 'Description'], title=title) |
| 54 | + table.align['Description'] = 'l' |
| 55 | + |
| 56 | + if test: |
| 57 | + prices = result['prices'] |
| 58 | + else: |
| 59 | + prices = result['orderDetails']['prices'] |
| 60 | + |
| 61 | + for item in prices: |
| 62 | + table.add_row([item['id'], item['item']['description']]) |
| 63 | + return table |
0 commit comments