예제 #1
0
def get_price(environment, cpus, memory):
    client = get_client(environment)
    manager = SoftLayer.OrderingManager(client)
    if cpus == 1:
        cpu = 'GUEST_CORE_' + str(cpus)
    else:
        cpu = 'GUEST_CORES_' + str(cpus)
    memory = 'RAM_' + str(memory) + '_GB'

    try:
        location_groups = [
            data_center['groups'] for data_center in client.call(
                'SoftLayer_Location', 'getDatacenters', mask='groups')
            if data_center['name'] == environment.slayer_datacenter
        ]
        location_group_ids = []
        for location_group in location_groups:
            for location in location_group:
                location_group_ids.append(location['id'])

        item_prices = client.call('SoftLayer_Product_Package',
                                  'getItemPrices',
                                  id=835)

        cpu_cost = [
            float(cost['hourlyRecurringFee']) for cost in item_prices
            if (cost['locationGroupId'] in location_group_ids
                and cost['item'].get('keyName') == cpu)
        ][0]
        memory_cost = [
            float(cost['hourlyRecurringFee']) for cost in item_prices
            if (cost['locationGroupId'] in location_group_ids
                and cost['item'].get('keyName') == memory)
        ][0]
        total_cost = cpu_cost + memory_cost
        return total_cost
    except Exception as e:
        print('-------------------------')
        print(e)
        return 0
예제 #2
0
 def set_up(self):
     self.vs = SoftLayer.VSManager(self.client,
                                   SoftLayer.OrderingManager(self.client))
예제 #3
0
 def set_up(self):
     self.ordering = SoftLayer.OrderingManager(self.client)
예제 #4
0
    def test_init_with_ordering_manager(self):
        ordering_manager = SoftLayer.OrderingManager(self.client)
        mgr = SoftLayer.HardwareManager(self.client, ordering_manager)

        self.assertEqual(mgr.ordering_manager, ordering_manager)
예제 #5
0
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)
 def set_up(self):
     self.client = testing.FixtureClient()
     self.ordering = SoftLayer.OrderingManager(self.client)
예제 #7
0
 def test_get_server_packages_with_ordering_manager_provided(self):
     self.hardware = SoftLayer.HardwareManager(
         self.client, SoftLayer.OrderingManager(self.client))
     self.test_get_available_dedicated_server_packages()