SoftLayer API:如何获取所有可能的 locationGroupId 的每小时裸机服务器预设价格

SoftLayer API: How to get hourly bare metal server preset prices for all possible locationGroupId

按小时计算的裸机服务器Softlayer_Product_Package 200 有预设。

我正在尝试获取所有位置的每个预设的商品价格。

如果我使用下面的查询 https://$apiuser:$apikey@api.softlayer.com/rest/v3/SoftLayer_Product_Package/200/getActivePresets.json?objectMask=mask [id,packageId,description,name,keyName,configuration.category,configuration.price]

它只有 returns "standard" 价格 "locationGroupId" = null。

如何从 "SoftLayer_Product_Package_Preset" 获取所有位置的价格,不同 loationGroupId 值的不同价格,但不仅限于 loationGroupId= null 的 "standard" 价格?

谢谢。

我在执行 SoftLayer_Product_Package::getActivePresets 时得到了相同的值(我的意思是:"locationGroupId" = null)。

但是在查看快速服务器的订单配置后,我可以看到预设是 pre-established/fixed 配置,这似乎是使用“getActivePresets”显示的商品价格没有位置的原因选择。这些具有 locationGroupId = null 的价格 ID 被视为 "a standard price",而 API 将在内部为客户切换价格。但建议先执行verifyOrder,以查看想要的订单是否可以(费用可能会有所不同)。

例如当执行下面这个请求时:

https://[username]:[apikey]@api.softlayer.com/rest/v3/SoftLayer_Product_Package/200/getActivePresets.json?objectMask=mask [id,description,keyName,configuration.category, configuration.price,prices]

我们得到预先确定的价格(包装:200,预设:66):

* Item prices: Disk Controller (NoRAID)  -- > price id: 32927
* server ("Single Intel Xeon E3-1270 v3 (4 Cores, 3.50 GHz)") --> price id: 37318
* RAM ("32 GB RAM") --> price id: 37360
* disk0 (“960 GB SSD (3 DWPD)”) --> price id: 50407
*disk1 ("960 GB SSD (3 DWPD)”) --> price id: 50407

在内部,API 将匹配这些价格和客户选择的位置。 可能与这些价格匹配的位置是旧位置,例如:dal01, ams01, dal07 dal06, sng01, hou02, wdc01, SJC01.

但上述价格并不是为每小时快速服务器配置的唯一项目。例如,对于此订单,我们需要配置更多项目:

https://[username]:[apikey]@api.softlayer.com/rest/v3/SoftLayer_Product_Order/verifyOrder

{
  "parameters": [
    {
      "complexType": "SoftLayer_Container_Product_Order_Hardware_Server",
      "quantity": 1,
      "location": "SANJOSE",
      "packageId": 200,
      "useHourlyPricing": 1,
      "presetId": 66,
      "prices": [
        {
          "id": 37318        # Single Intel Xeon E3-1270 v3 (4 Cores, 3.50 GHz)
        },
        {
          "id": 37360        # "32 GB RAM
        },
        {
          "id": 44992        # "CentOS 7.x (64 bit)"
        },
        {
          "id": 32927        # "Non-RAID  Non-RAID"
        },
        {
          "id": 50407        # disk0 - 960 GB SSD (3 DWPD)
        },
        {
          "id": 50407        # disk1 - 960 GB SSD (3 DWPD)
        },
        {
          "id": 34183        # "0 GB Bandwidth"
        },
        {
          "id": 26737        # "100 Mbps Public & Private Network Uplinks"
        },
        {
          "id": 33483        # "Unlimited SSL VPN Users & 1 PPTP VPN User per account"
        },
        {
          "id": 34807        # "1 IP Address"
        },
        {
          "id": 25014        # "Reboot / KVM over IP"
        }
      ],
      "hardware": [
        {
          "hostname": "myhostname",
          "domain": "mydomain.com"
        }
      ]
    }
  ]
}

要获取这些商品价格,我们可以使用以下方法:

https://[username]:[apikey]@api.softlayer.com/rest/v3/SoftLayer_Product_Package/200/getItemPrices?objectMask=mask[id,item[keyName,description],pricingLocationGroup[locations[id, name, longName]]]

在这个请求中,我们可以看到一些项目可以根据位置选择“locationGroupId <> null”

参考文献:

http://sldn.softlayer.com/reference/services/SoftLayer_Product_Package/getItemPrices http://sldn.softlayer.com/reference/services/SoftLayer_Product_Package/getAllObjects http://sldn.softlayer.com/reference/services/SoftLayer_Product_Package http://sldn.softlayer.com/blog/cmporter/Location-based-Pricing-and-You

编辑

每个数据中心的快速配置服务器数量有限。即使我们去门户网站选择任何数据中心,也有一些情况会在验证订单后显示错误,即:

There is currently no hardware available for package # 200 with preset configuration # 66 in Frankfurt 2. Please select a different datacenter.

这意味着该位置没有足够的硬件来完成订单。似乎快速配置服务器的可用性订单只在少数数据中心中,因此它们没有特定的位置组。例如,如果我们执行以下请求以了解可用的位置组定价,我们可以看到每个组都有超过 1 个位置,并且快速供应订单可能仅适用于其中一个数据中心(不接受其他订单)这些 DC)。

https://[username]:[apikey]@api.softlayer.com/rest/v3/SoftLayer_Location_Group_Pricing/getAllObjects?objectMask=mask[locations]

当正在使用 FastProvision 服务器的客户取消它们时,他们会回到可用池中并再次成为 'orderable'。

目前这些类型的订单正在处理 "standard prices"。

控制门户执行一些内部流程来获取您在订购服务器时选择的数据中心的价格。不幸的是,不可能通过单个休息请求检索您想要的所有信息。

但是,我们可以使用SoftLayer 支持的编程语言。您可以在以下位置查看 SoftLayer 支持的语言:

http://sldn.softlayer.com/

我可以提供以下 python 脚本,这将帮助您获得每个活动预设配置的每个数据中心的价格。此代码可以改进,这只是一个想法。

"""
Get active presets and its prices per location

This script retrieves the active presets with their prices per datacenter. 
Also it displays the information for hourly recurring fee and recurring fee.

Important manual pages:
http://sldn.softlayer.com/reference/services/SoftLayer_Product_Package/getActivePresets
http://sldn.softlayer.com/reference/services/SoftLayer_Product_Package/getItemPrices
http://sldn.softlayer.com/search/site/object%20mask
http://sldn.softlayer.com/article/Object-Filters

@License: http://sldn.softlayer.com/article/License
@Author: SoftLayer Technologies, Inc. <sldn@softlayer.com>
"""

# So we can talk to the SoftLayer API:
import SoftLayer
from prettytable import PrettyTable

# Your SoftLayer API username and key.
API_USERNAME = 'set me'
API_KEY = 'set me'
# Declare the package id
packageId = 200
# Create a client instance
client = SoftLayer.Client(username=API_USERNAME, api_key=API_KEY)
# Declare an object mask to get prices and items information
objectMask = 'mask[prices[item]]'
# Declare an object mask to get pricingLocationGroup
objectMaskPrice = 'mask[pricingLocationGroup[locations]]'
try:
    # Get active presets
    activePresets = client['SoftLayer_Product_Package'].getActivePresets(id=packageId, mask=objectMask)
    for activePreset in activePresets:
        print('**************   PRESET ID: %s   **************' % activePreset['id'])
        # Configuring table's columns
        x = PrettyTable(['Locations', 'Price Id', 'Item Id', 'Item Description', 'hourlyRecurringFee', 'recurringFee'])
        x.padding_width = 1
        print('Id: %s, Description: %s, isActive: %s' % (activePreset['id'], activePreset['description'], activePreset['isActive']))
        print('        KeyName: %s, Name: %s' % (activePreset['keyName'], activePreset['name']))
        for prices in activePreset['prices']:
            print('                 Price Id: %s, Item Id: %s Item Description: %s' % (prices['id'], prices['item']['id'], prices['item']['description']))
            objectFilterItem = {'itemPrices':{'item':{'id':{'operation':prices['item']['id']}}}}
            prices = client['SoftLayer_Product_Package'].getItemPrices(id=200, filter=objectFilterItem, mask=objectMaskPrice)
            for price in prices:
                locationDisplay = ''
                recurringFee = 0
                # Verifying if the price has pricingLocationGroup 
                if 'pricingLocationGroup' in price:
                    for location in price['pricingLocationGroup']['locations']:
                        locationDisplay = locationDisplay + ' ' + location['longName']
                else:
                    locationDisplay = 'STANDARD PRICE'
                # Verifying if the price has Recurring Fee
                if 'recurringFee' in price:
                    recurringFee = price['recurringFee']
                else:
                    recurringFee = 'null'
                x.add_row([locationDisplay, price['id'], price['item']['id'], price['item']['description'], price['hourlyRecurringFee'], recurringFee])
        print(x)
except SoftLayer.SoftLayerAPIError as e:
    print('Unable to get active presets faultCode=%s, faultString=%s' % (e.faultCode, e.faultString))
    exit(1)

希望对您有所帮助

如有任何疑问或评论,请告诉我

要像门户一样获取预设订单的价格,您需要使用其他方法:

此方法将为您提供可用的服务器、它的预设(如果有的话)以及它在门户中的价格 http://sldn.softlayer.com/reference/services/SoftLayer_Product_Package_Server/getAllObjects

但价格是标准的,为了获得特定位置的价格,您需要使用这些方法:http://sldn.softlayer.com/reference/services/SoftLayer_Product_Package/getItemPrices or the http://sldn.softlayer.com/reference/services/SoftLayer_Product_Package/getItems

他们将 return 每个位置的所有价格。

getActivePresets 方法可以帮助您了解预设中有哪些项目,使用其他方法可以获取特定位置的价格。

此致