def order(env, **args): """Creates a LB. Protocols supported are TCP, HTTP, and HTTPS.""" mgr = SoftLayer.LoadBalancerManager(env.client) network = SoftLayer.NetworkManager(env.client) datacenter = network.get_datacenter(datacenter=args.get('datacenter')) if datacenter: location = {'id': datacenter[0]['id']} else: raise exceptions.CLIHalt('Datacenter {} was not found'.format(datacenter)) name = args.get('name') description = args.get('label', None) backend = args.get('backend') frontend = args.get('frontend') protocols = [ { "backendPort": backend.get('port'), "backendProtocol": backend.get('protocol'), "frontendPort": frontend.get('port'), "frontendProtocol": frontend.get('protocol'), "loadBalancingMethod": args.get('method'), "maxConn": 1000 } ] # remove verify=True to place the order receipt = mgr.order_lbaas(location, name, description, protocols, args.get('subnet'), public=args.get('public'), verify=args.get('verify')) table = parse_receipt(receipt) env.fout(table)
def cli(env, **args): """Order/create virtual servers.""" vsi = SoftLayer.VSManager(env.client) _validate_args(env, args) create_args = _parse_create_args(env.client, args) test = args.get('test', False) do_create = not (args.get('export') or test) if do_create: if not (env.skip_confirmations or formatting.confirm( "This action will incur charges on your account. Continue?")): raise exceptions.CLIAbort('Aborting virtual server order.') if args.get('export'): export_file = args.pop('export') template.export_to_template(export_file, args, exclude=['wait', 'test']) env.fout('Successfully exported options to a template file.') else: result = vsi.order_guest(create_args, test) output = _build_receipt_table(result, args.get('billing'), test) if do_create: env.fout(_build_guest_table(result)) env.fout(output) if args.get('wait'): virtual_guests = utils.lookup(result, 'orderDetails', 'virtualGuests') guest_id = virtual_guests[0]['id'] click.secho("Waiting for %s to finish provisioning..." % guest_id, fg='green') ready = vsi.wait_for_ready(guest_id, args.get('wait') or 1) if ready is False: env.out(env.fmt(output)) raise exceptions.CLIHalt(code=1)
def cli(env, **args): """Order/create virtual servers.""" vsi = SoftLayer.VSManager(env.client) _validate_args(env, args) # Do not create a virtual server with test or export do_create = not (args['export'] or args['test']) table = formatting.Table(['Item', 'cost']) table.align['Item'] = 'r' table.align['cost'] = 'r' data = _parse_create_args(env.client, args) output = [] if args.get('test'): result = vsi.verify_create_instance(**data) total_monthly = 0.0 total_hourly = 0.0 table = formatting.Table(['Item', 'cost']) table.align['Item'] = 'r' table.align['cost'] = 'r' for price in result['prices']: total_monthly += float(price.get('recurringFee', 0.0)) total_hourly += float(price.get('hourlyRecurringFee', 0.0)) if args.get('billing') == 'hourly': rate = "%.2f" % float(price['hourlyRecurringFee']) elif args.get('billing') == 'monthly': rate = "%.2f" % float(price['recurringFee']) table.add_row([price['item']['description'], rate]) total = 0 if args.get('billing') == 'hourly': total = total_hourly elif args.get('billing') == 'monthly': total = total_monthly billing_rate = 'monthly' if args.get('billing') == 'hourly': billing_rate = 'hourly' table.add_row(['Total %s cost' % billing_rate, "%.2f" % total]) output.append(table) output.append( formatting.FormattedItem( None, ' -- ! Prices reflected here are retail and do not ' 'take account level discounts and are not guaranteed.')) if args['export']: export_file = args.pop('export') template.export_to_template(export_file, args, exclude=['wait', 'test']) env.fout('Successfully exported options to a template file.') if do_create: if not (env.skip_confirmations or formatting.confirm( "This action will incur charges on your account. Continue?")): raise exceptions.CLIAbort('Aborting virtual server order.') result = vsi.create_instance(**data) table = formatting.KeyValueTable(['name', 'value']) table.align['name'] = 'r' table.align['value'] = 'l' table.add_row(['id', result['id']]) table.add_row(['created', result['createDate']]) table.add_row(['guid', result['globalIdentifier']]) output.append(table) if args.get('wait'): ready = vsi.wait_for_ready(result['id'], args.get('wait') or 1) table.add_row(['ready', ready]) if ready is False: env.out(env.fmt(output)) raise exceptions.CLIHalt(code=1) env.fout(output)
def cli(env, **args): """Order/create virtual servers.""" vsi = SoftLayer.VSManager(env.client) _validate_args(env, args) # Do not create a virtual server with test or export do_create = not (args['export'] or args['test']) table = formatting.Table(['Item', 'cost']) table.align['Item'] = 'r' table.align['cost'] = 'r' data = _parse_create_args(env.client, args) output = [] if args.get('test'): result = vsi.verify_create_instance(**data) if result['presetId']: ordering_mgr = SoftLayer.OrderingManager(env.client) item_prices = ordering_mgr.get_item_prices(result['packageId']) preset_prices = ordering_mgr.get_preset_prices(result['presetId']) search_keys = ["guest_core", "ram"] for price in preset_prices['prices']: if price['item']['itemCategory'][ 'categoryCode'] in search_keys: item_key_name = price['item']['keyName'] _add_item_prices(item_key_name, item_prices, result) table = _build_receipt_table(result['prices'], args.get('billing')) output.append(table) output.append( formatting.FormattedItem( None, ' -- ! Prices reflected here are retail and do not ' 'take account level discounts and are not guaranteed.')) if args['export']: export_file = args.pop('export') template.export_to_template(export_file, args, exclude=['wait', 'test']) env.fout('Successfully exported options to a template file.') if do_create: if not (env.skip_confirmations or formatting.confirm( "This action will incur charges on your account. Continue?")): raise exceptions.CLIAbort('Aborting virtual server order.') result = vsi.create_instance(**data) table = formatting.KeyValueTable(['name', 'value']) table.align['name'] = 'r' table.align['value'] = 'l' table.add_row(['id', result['id']]) table.add_row(['created', result['createDate']]) table.add_row(['guid', result['globalIdentifier']]) output.append(table) if args.get('wait'): ready = vsi.wait_for_ready(result['id'], args.get('wait') or 1) table.add_row(['ready', ready]) if ready is False: env.out(env.fmt(output)) raise exceptions.CLIHalt(code=1) env.fout(output)