Python 如何使用API实现排除函数

Python 如何使用API实现排除函数,python,ibm-cloud-infrastructure,Python,Ibm Cloud Infrastructure,正如我们所看到的,在SoftLayer的客户门户中,会自动检测到特定配置的排除。 例如,在验证订单之前,我们无法使用Windows操作系统选择VSI的25 GB第一个磁盘。 我知道我们有产品订单服务的verifyOrder方法,但它要求我们至少提供所有配置。 我们是否有其他方法来检测无效配置?表单会根据项目之间的冲突进行更新,要获取该信息,您应该使用以下方法: 另一种方法也有帮助,因为有时项目和位置之间存在冲突: 您可以尝试我创建的以下脚本,它将提供来自特定包的足够信息:可用位置、项目的位置冲突

正如我们所看到的,在SoftLayer的客户门户中,会自动检测到特定配置的排除。 例如,在验证订单之前,我们无法使用Windows操作系统选择VSI的25 GB第一个磁盘。 我知道我们有产品订单服务的verifyOrder方法,但它要求我们至少提供所有配置。
我们是否有其他方法来检测无效配置?

表单会根据项目之间的冲突进行更新,要获取该信息,您应该使用以下方法:

另一种方法也有帮助,因为有时项目和位置之间存在冲突:

您可以尝试我创建的以下脚本,它将提供来自特定包的足够信息:可用位置、项目的位置冲突以及项目之间的冲突

"""
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)
我希望这能有所帮助,如果您有任何疑问或意见,请告诉我