如何在商店包配置

时间:2016-04-04 20:28:58

标签: ibm-cloud-infrastructure

上下文:

在虚拟访客的软件层配置页面(https://www.softlayer.com/Store/orderComputingInstance/1640,1644,2202)上,JavaScript会根据以下某些限制对价格项目进行大量显示/隐藏:

  • 当您选择Windows作为操作系统(价格限制价格)时,隐藏MySQL for Linux
  • 达拉斯无法使用私人节点(位置价格限制)

我的问题:

构建一个用于配置虚拟客户机的Web界面,我需要构建一个与配置页面上显示的priceConflicts完全相同的哈希值。

致电SoftLayer_Product_Package.getItemLocationConflicts我可以获得价格限制的位置,但是当我致电SoftLayer_Product_Package.getItemConflicts时,会返回一个SoftLayer_Product_Item_Resource_Conflict_Item数组,其中包含4个属性itemId,{{1} },packageIdresourceTableId,这正是http://sldn.softlayer.com/reference/datatypes/SoftLayer_Product_Item_Resource_Conflict_Item所描述的

有些奇怪的事情:

那么,我如何获得创建像mask[resource] hash这样的结构所需的信息?

谢谢

1 个答案:

答案 0 :(得分:1)

对于这两种情况,它返回一个SoftLayer_Product_Item_Resource_Conflict

数组

你需要假设

  

正如你所说,JavaScript在价格项目上做了很多显示/隐藏   基于一些限制。

我可以提供一个Python脚本来帮助您获取所有这些信息

  

更新

"""
Get item prices information

This script retrieves information of prices from a package. It retrieves the item description,
location conflicts, pricing location group and item conflicts

Important manual pages:
http://sldn.softlayer.com/reference/services/SoftLayer_Product_Package/getRegions
http://sldn.softlayer.com/reference/services/SoftLayer_Product_Package/getItemPrices
http://sldn.softlayer.com/reference/datatypes/SoftLayer_Product_Package/getItemPrices
http://sldn.softlayer.com/article/object-masks

@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 image template id
packageId = 46
# Create a client instance
client = SoftLayer.Client(username=API_USERNAME, api_key=API_KEY)
# Declare an object mask to get location conflicts
objectMask = 'mask[pricingLocationGroup[locations],item[locationConflicts, conflicts]]'

try:
    locations = client['SoftLayer_Product_Package'].getRegions(id=packageId)
    items = client['SoftLayer_Product_Package'].getItems(id=packageId)
    print('*****  AVAILABLE LOCATIONS  *****')
    for location in locations:
        print('Id: %s,  Location: %s' % (location['location']['location']['id'], location['location']['location']['longName']))
    itemPrices = client['SoftLayer_Product_Package'].getItemPrices(id=packageId, mask=objectMask)
    items = client['SoftLayer_Product_Package'].getItems(id=packageId, mask='mask[prices]')
    x = PrettyTable(["Price Id", "Item Id", "Description", "Datacenter conflicts", "Pricing Location", 'Price conflicts', 'Item conflicts'])
    x.align["Price Id"] = "l"  # Left align city names
    x.padding_width = 1
    for price in itemPrices:
        dcConflicts = ''
        pricingLocation = ''
        conflictItems = ''
        conflictPrices = ''
        # Get location conflicts
        if  len(price['item']['locationConflicts']) > 0:
            for locationConflicts in price['item']['locationConflicts']:
                for location in locations:
                    if locationConflicts['resourceTableId'] == location['location']['location']['id']:
                        dcConflicts = dcConflicts + ' ' + location['location']['location']['longName']
        else:
            dcConflicts = "None"
        # Get Pricing location
        if 'pricingLocationGroup' in price:
            for priceLocation in price['pricingLocationGroup']['locations']:
                pricingLocation = pricingLocation + ' ' + priceLocation['longName']
        else:
            pricingLocation = 'Standard price'
        # Get item conflicts
        if len(price['item']['conflicts']) > 0:
            for conflict in price['item']['conflicts']:
                for item in items:
                    if conflict['resourceTableId'] == item['id']:
                        conflictItems = conflictItems + ' ' + str(conflict['resourceTableId'])
                        for priceConf in item['prices']:
                            conflictPrices = conflictPrices + ' ' + str(priceConf['id']) 
        if conflictItems == '':
            conflictItems = 'None'
            conflictPrices = 'None'
        x.add_row([price['id'], price['item']['id'], price['item']['description'], dcConflicts, pricingLocation, conflictPrices, conflictItems])
    print(x)
except SoftLayer.SoftLayerAPIError as e:
    print("Unable to get item prices faultCode=%s, faultString=%s" % (e.faultCode, e.faultString))
    exit(1)