问题描述
上下文:
在softlayer的虚拟访客配置页面上( https://www.softlayer.com/Store/orderComputingInstance/1640,1644,2202 ),JavaScript会根据以下限制对价格商品进行很多显示/隐藏:
On softlayer configure page for a virtual guest ( https://www.softlayer.com/Store/orderComputingInstance/1640,1644,2202 ), the JavaScript do a lot of show / hide on price items based on some restrictions like:
- 当您选择Windows作为操作系统时,Linux的MySQL隐藏(价格对价格的限制)
- 达拉斯不提供私有节点(受价格限制的位置)
我的问题:
构建一个用于配置虚拟访客的Web界面,我需要构建一个与 priceConflicts
完全相同的哈希,该哈希显示在配置页面上.
Building a web interface to configure a virtual guest, I need to build a hash exactly like priceConflicts
that is shown on configure page.
致电 SoftLayer_Product_Package.getItemLocationConflicts
,我可以获取价格限制的位置,但是当我致电 SoftLayer_Product_Package.getItemConflicts
时,返回的是 SoftLayer_Product_Item_Resource_Conflict_Item
的数组具有4个属性 itemId
, packageId
, resourceTableId
和 message
,这正是对 http://sldn.softlayer.com/reference/datatypes/SoftLayer_Product_Item_Resource_Conflict_Item
calling SoftLayer_Product_Package.getItemLocationConflicts
I can get the location to price restrictions, but when I call SoftLayer_Product_Package.getItemConflicts
is returned an array of SoftLayer_Product_Item_Resource_Conflict_Item
with 4 attributes itemId
, packageId
, resourceTableId
and message
, that is exactly what is describe for http://sldn.softlayer.com/reference/datatypes/SoftLayer_Product_Item_Resource_Conflict_Item
有些奇怪的东西:
- 根据文档: http://sldn.softlayer.com/reference/services/SoftLayer_Product_Package/getItemConflicts 返回值应该是SoftLayer_Product_Item_Resource_Conflict的数组,而不是SoftLayer_Product_Item_Resource_Conflict_Item的数组
- 根据文档: http://sldn.softlayer.com/reference/datatypes/SoftLayer_Product_Item_Resource_Conflict_Item 有一个资源关系属性,但是当我使用mask
mask [resource]
调用时,返回以下错误:属性'resource'对'SoftLayer_Product_Item_Resource_Conflict'无效.
- According to documentation: http://sldn.softlayer.com/reference/services/SoftLayer_Product_Package/getItemConflicts return values was supposed to be an array of SoftLayer_Product_Item_Resource_Conflict, not an array of SoftLayer_Product_Item_Resource_Conflict_Item
- According to documenation: http://sldn.softlayer.com/reference/datatypes/SoftLayer_Product_Item_Resource_Conflict_Item there's a resource relational property, but when I call with a mask
mask[resource]
the following error is returned: Property 'resource' not valid for 'SoftLayer_Product_Item_Resource_Conflict'.
那么,我如何获得创建像 priceConflicts
哈希这样的结构所需的信息?
So, how do I get the information needed to create a struct like priceConflicts
hash?
谢谢
推荐答案
在两种情况下,它均返回 SoftLayer_Product_Item_Resource_Conflict
For both cases it returns an array of SoftLayer_Product_Item_Resource_Conflict
您需要假设
-
对于 SoftLayer_Product_Package :: getItemLocationConflicts 方法中,"itemId"与位置存在位置冲突"与"resourceTableId"具有相同的标识符.
ForSoftLayer_Product_Package::getItemLocationConflictsmethod, the "itemId" has a "location conflict" with the locationwhich has the same identifier as "resourceTableId".
您可以使用以下方法检索位置标识符: SoftLayer_Location_Datacenter :: getDatacenters .因此,您需要匹配标识符以获取位置
You can retrieve location identifiers with the following method:SoftLayer_Location_Datacenter::getDatacenters.So you will need to match the identifier, to get the location
我可以提供一个Python脚本,它将帮助您获取所有这些信息
I can provide a Python script which will help you to get all of this information
"""
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. <[email protected]>
"""
# 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)
这篇关于如何创建priceConflicts哈希,例如在商店包装上配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!