def test_template_options(self):
     path = os.path.join(testing.FIXTURE_PATH, 'sample_vs_template.conf')
     args = {
         'key': 'value',
         '--cpu': None,
         '--memory': '32',
         '--template': path,
         '--hourly': False,
         '--disk': [],
     }
     template.update_with_template_args(args, list_args=['--disk'])
     self.assertEqual(
         args, {
             '--cpu': '4',
             '--datacenter': 'dal05',
             '--domain': 'example.com',
             '--hostname': 'myhost',
             '--hourly': 'true',
             '--memory': '32',
             '--monthly': 'false',
             '--network': '100',
             '--os': 'DEBIAN_7_64',
             'key': 'value',
             '--disk': ['50', '100'],
         })
Example #2
0
def cli(env, **args):
    """Order/create a dedicated server."""

    template.update_with_template_args(args, list_args=['disk', 'key'])
    mgr = SoftLayer.HardwareManager(env.client)

    ds_options = mgr.get_dedicated_server_create_options(args['chassis'])

    order = _process_args(env, args, ds_options)

    # Do not create hardware server with --test or --export
    do_create = not (args['export'] or args['test'])

    output = None
    if args.get('test'):
        result = mgr.verify_order(**order)

        table = formatting.Table(['Item', 'cost'])
        table.align['Item'] = 'r'
        table.align['cost'] = 'r'

        total = 0.0
        for price in result['prices']:
            total += float(price.get('recurringFee', 0.0))
            rate = "%.2f" % float(price['recurringFee'])

            table.add_row([price['item']['description'], rate])

        table.add_row(['Total monthly cost', "%.2f" % total])
        output = []
        output.append(table)
        output.append(
            formatting.FormattedItem(
                '', ' -- ! 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'])
        return 'Successfully exported options to a template file.'

    if do_create:
        if env.skip_confirmations or formatting.confirm(
                "This action will incur charges on your account. "
                "Continue?"):
            result = mgr.place_order(**order)

            table = formatting.KeyValueTable(['name', 'value'])
            table.align['name'] = 'r'
            table.align['value'] = 'l'
            table.add_row(['id', result['orderId']])
            table.add_row(['created', result['orderDate']])
            output = table
        else:
            raise exceptions.CLIAbort('Aborting dedicated server order.')

    return output
def cli(env, **args):
    """Order/create a dedicated server."""

    template.update_with_template_args(args, list_args=['disk', 'key'])
    mgr = SoftLayer.HardwareManager(env.client)

    ds_options = mgr.get_dedicated_server_create_options(args['chassis'])

    order = _process_args(env, args, ds_options)

    # Do not create hardware server with --test or --export
    do_create = not (args['export'] or args['test'])

    output = None
    if args.get('test'):
        result = mgr.verify_order(**order)

        table = formatting.Table(['Item', 'cost'])
        table.align['Item'] = 'r'
        table.align['cost'] = 'r'

        total = 0.0
        for price in result['prices']:
            total += float(price.get('recurringFee', 0.0))
            rate = "%.2f" % float(price['recurringFee'])

            table.add_row([price['item']['description'], rate])

        table.add_row(['Total monthly cost', "%.2f" % total])
        output = []
        output.append(table)
        output.append(formatting.FormattedItem(
            '',
            ' -- ! 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'])
        return 'Successfully exported options to a template file.'

    if do_create:
        if env.skip_confirmations or formatting.confirm(
                "This action will incur charges on your account. "
                "Continue?"):
            result = mgr.place_order(**order)

            table = formatting.KeyValueTable(['name', 'value'])
            table.align['name'] = 'r'
            table.align['value'] = 'l'
            table.add_row(['id', result['orderId']])
            table.add_row(['created', result['orderDate']])
            output = table
        else:
            raise exceptions.CLIAbort('Aborting dedicated server order.')

    return output
 def test_template_options(self):
     path = os.path.join(testing.FIXTURE_PATH, "sample_vs_template.conf")
     args = {"key": "value", "--cpu": None, "--memory": "32", "--template": path, "--hourly": False, "--disk": []}
     template.update_with_template_args(args, list_args=["--disk"])
     self.assertEqual(
         args,
         {
             "--cpu": "4",
             "--datacenter": "dal05",
             "--domain": "example.com",
             "--hostname": "myhost",
             "--hourly": "true",
             "--memory": "32",
             "--monthly": "false",
             "--network": "100",
             "--os": "DEBIAN_7_64",
             "key": "value",
             "--disk": ["50", "100"],
         },
     )
 def test_template_options(self):
     path = os.path.join(testing.FIXTURE_PATH, 'sample_vs_template.conf')
     args = {
         'cpu': None,
         'memory': '32',
         'template': path,
         'hourly': False,
         'disk': [],
     }
     template.update_with_template_args(args, list_args=['disk'])
     self.assertEqual(args, {
         'cpu': '4',
         'datacenter': 'dal05',
         'domain': 'example.com',
         'hostname': 'myhost',
         'hourly': 'true',
         'memory': '32',
         'monthly': 'false',
         'network': '100',
         'os': 'DEBIAN_7_64',
         'disk': ['50', '100'],
     })
 def test_no_template_option(self):
     args = {'key': 'value'}
     template.update_with_template_args(args)
     self.assertEqual(args, {'key': 'value'})
Example #7
0
def cli(env, **args):
    """Order/create virtual servers."""

    template.update_with_template_args(args, list_args=['disk', 'key'])
    vsi = SoftLayer.VSManager(env.client)
    _update_with_like_args(env.client, args)
    _validate_args(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'])
        return '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'], int(args.get('wait') or 1))
            table.add_row(['ready', ready])

    return output
Example #8
0
def cli(env, **args):
    """Order/create a dedicated server."""

    template.update_with_template_args(args, list_args=['key'])
    _validate_args(args)

    mgr = SoftLayer.HardwareManager(env.client)

    # Get the SSH keys
    ssh_keys = []
    for key in args.get('key'):
        resolver = SoftLayer.SshKeyManager(env.client).resolve_ids
        key_id = helpers.resolve_id(resolver, key, 'SshKey')
        ssh_keys.append(key_id)

    order = {
        'hostname': args['hostname'],
        'domain': args['domain'],
        'size': args['size'],
        'public_vlan': args.get('vlan_public'),
        'private_vlan': args.get('vlan_private'),
        'location': args.get('datacenter'),
        'ssh_keys': ssh_keys,
        'post_uri': args.get('postinstall'),
        'os': args['os'],
        'hourly': args.get('billing') == 'hourly',
        'port_speed': args.get('port_speed'),
        'no_public': args.get('no_public') or False,
        'extras': args.get('extra'),
    }

    # Do not create hardware server with --test or --export
    do_create = not (args['export'] or args['test'])

    output = None
    if args.get('test'):
        result = mgr.verify_order(**order)

        table = formatting.Table(['Item', 'cost'])
        table.align['Item'] = 'r'
        table.align['cost'] = 'r'

        total = 0.0
        for price in result['prices']:
            total += float(price.get('recurringFee', 0.0))
            rate = "%.2f" % float(price['recurringFee'])

            table.add_row([price['item']['description'], rate])

        table.add_row(['Total monthly cost', "%.2f" % total])
        output = []
        output.append(table)
        output.append(formatting.FormattedItem(
            '',
            ' -- ! 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'])
        return '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 dedicated server order.')

        result = mgr.place_order(**order)

        table = formatting.KeyValueTable(['name', 'value'])
        table.align['name'] = 'r'
        table.align['value'] = 'l'
        table.add_row(['id', result['orderId']])
        table.add_row(['created', result['orderDate']])
        output = table

    return output
 def test_no_template_option(self):
     args = {'key': 'value'}
     template.update_with_template_args(args)
     self.assertEqual(args, {'key': 'value'})
Example #10
0
def cli(env, **args):
    """Order/create virtual servers."""

    template.update_with_template_args(args, list_args=['disk', 'key'])
    vsi = SoftLayer.VSManager(env.client)
    _update_with_like_args(env.client, args)
    _validate_args(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('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'])
        return 'Successfully exported options to a template file.'

    if do_create:
        if env.skip_confirmations or formatting.confirm(
                "This action will incur charges on your account. Continue?"):
            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'], int(args.get('wait') or 1))
                table.add_row(['ready', ready])
        else:
            raise exceptions.CLIAbort('Aborting virtual server order.')

    return output
Example #11
0
 def test_no_template_option(self):
     args = {"key": "value"}
     template.update_with_template_args(args)
     self.assertEqual(args, {"key": "value"})