如何像商店包配置一样创建 priceConflicts 哈希
How to create a priceConflicts hash like on store package configure
上下文:
在虚拟访客 (https://www.softlayer.com/Store/orderComputingInstance/1640,1644,2202) 的软层配置页面上,JavaScript 根据一些限制对价格项目进行大量显示/隐藏,例如:
- MySQL for Linux 在您选择 Windows 作为操作系统时隐藏(价格限制)
- 私人节点在达拉斯不可用(位置到价格限制)
我的问题:
构建用于配置虚拟访客的 Web 界面,我需要构建一个与配置页面上显示的 priceConflicts
完全相同的哈希。
调用 SoftLayer_Product_Package.getItemLocationConflicts
我可以获得价格限制的位置,但是当我调用 SoftLayer_Product_Package.getItemConflicts
时 return 编辑了一个 SoftLayer_Product_Item_Resource_Conflict_Item
的数组,其中包含 4 个属性 itemId
、packageId
、resourceTableId
和 message
,这正是 http://sldn.softlayer.com/reference/datatypes/SoftLayer_Product_Item_Resource_Conflict_Item
的描述
一些奇怪的事情:
- 根据文档:http://sldn.softlayer.com/reference/services/SoftLayer_Product_Package/getItemConflicts return 值应该是 SoftLayer_Product_Item_Resource_Conflict 的数组,而不是 SoftLayer_Product_Item_Resource_Conflict_Item
的数组
- 根据文档:http://sldn.softlayer.com/reference/datatypes/SoftLayer_Product_Item_Resource_Conflict_Item 有一个资源关系 属性,但是当我使用掩码
mask[resource]
调用时,出现以下错误 returned:属性 'resource' 对 'SoftLayer_Product_Item_Resource_Conflict' 无效。
那么,如何获取创建像 priceConflicts
散列这样的结构所需的信息?
谢谢
对于这两种情况,它 returns 一个 SoftLayer_Product_Item_Resource_Conflict
的数组
你需要假设
对于
SoftLayer_Product_Package::getItemLocationConflicts
方法,"itemId" 有一个带有位置的 "location conflict"
与 "resourceTableId" 具有相同的标识符。
您可以使用以下方法检索位置标识符:
SoftLayer_Location_Datacenter::getDatacenters。
所以你需要匹配标识符,才能得到位置
- 对于
SoftLayer_Product_Package::getItemConflicts
方法,"itemId" 与 "resourceTableId" 有冲突
对应另一个"itemId"。您应该将这些值与
结果来自
SoftLayer_Product_Package::getItems
As your said, JavaScript does a lot of show / hide on price items
based on some restrictions.
我可以提供一个 Python 脚本来帮助您获取所有这些信息
Updated
"""
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)
上下文:
在虚拟访客 (https://www.softlayer.com/Store/orderComputingInstance/1640,1644,2202) 的软层配置页面上,JavaScript 根据一些限制对价格项目进行大量显示/隐藏,例如:
- MySQL for Linux 在您选择 Windows 作为操作系统时隐藏(价格限制)
- 私人节点在达拉斯不可用(位置到价格限制)
我的问题:
构建用于配置虚拟访客的 Web 界面,我需要构建一个与配置页面上显示的 priceConflicts
完全相同的哈希。
调用 SoftLayer_Product_Package.getItemLocationConflicts
我可以获得价格限制的位置,但是当我调用 SoftLayer_Product_Package.getItemConflicts
时 return 编辑了一个 SoftLayer_Product_Item_Resource_Conflict_Item
的数组,其中包含 4 个属性 itemId
、packageId
、resourceTableId
和 message
,这正是 http://sldn.softlayer.com/reference/datatypes/SoftLayer_Product_Item_Resource_Conflict_Item
一些奇怪的事情:
- 根据文档:http://sldn.softlayer.com/reference/services/SoftLayer_Product_Package/getItemConflicts return 值应该是 SoftLayer_Product_Item_Resource_Conflict 的数组,而不是 SoftLayer_Product_Item_Resource_Conflict_Item 的数组
- 根据文档:http://sldn.softlayer.com/reference/datatypes/SoftLayer_Product_Item_Resource_Conflict_Item 有一个资源关系 属性,但是当我使用掩码
mask[resource]
调用时,出现以下错误 returned:属性 'resource' 对 'SoftLayer_Product_Item_Resource_Conflict' 无效。
那么,如何获取创建像 priceConflicts
散列这样的结构所需的信息?
谢谢
对于这两种情况,它 returns 一个 SoftLayer_Product_Item_Resource_Conflict
的数组你需要假设
对于 SoftLayer_Product_Package::getItemLocationConflicts 方法,"itemId" 有一个带有位置的 "location conflict" 与 "resourceTableId" 具有相同的标识符。
您可以使用以下方法检索位置标识符: SoftLayer_Location_Datacenter::getDatacenters。 所以你需要匹配标识符,才能得到位置
- 对于 SoftLayer_Product_Package::getItemConflicts 方法,"itemId" 与 "resourceTableId" 有冲突 对应另一个"itemId"。您应该将这些值与 结果来自 SoftLayer_Product_Package::getItems
As your said, JavaScript does a lot of show / hide on price items based on some restrictions.
我可以提供一个 Python 脚本来帮助您获取所有这些信息
Updated
"""
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)