我们如何使用API​​实现排除功能

编程入门 行业动态 更新时间:2024-10-26 14:30:28
本文介绍了我们如何使用API​​实现排除功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我们看到,在SoftLayer的客户门户中,将自动检测到特定配置的排除. 例如,在验证订单之前,我们无法选择Windows操作系统的VSI的25 GB First Disk. 我知道我们有用于Product_Order服务的verifyOrder方法,但它至少需要我们提供所有配置. 我们还有其他方法可以检测到无效的配置吗?

As we see, in SoftLayer's customer portal the exclusion of the specific configuration is automatically detected. For example, we cannot select VSI's 25 GB First Disk with Windows OS before verifying the order. I know we have verifyOrder method for Product_Order service but it require us to provide all the configuration at least. Do we have any other way to detect the invalid configuration?

推荐答案

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

The form is updated according the conflicts between items, to get that information you should use the following method:

  • SoftLayer_Product_Package :: getItemConflicts

由于有时项目和位置之间存在冲突,因此还有另一种方法可以提供帮助:

Also another method that can help, due to sometimes there are conflict between item and location:

  • SoftLayer_Product_Package :: getItemLocationConflicts

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

You can try the following script that I created, it will provide enough information from a specific package: the available locations, the location conflicts for items and the conflicts between items

""" 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: sldn.softlayer/reference/services/SoftLayer_Product_Package/getRegions sldn.softlayer/reference/services/SoftLayer_Product_Package/getItemPrices sldn.softlayer/reference/datatypes/SoftLayer_Product_Package/getItemPrices sldn.softlayer/article/object-masks @License: sldn.softlayer/article/License @Author: SoftLayer Technologies, Inc. <sldn@softlayer> """ # 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)

我希望这会有所帮助,如果您有任何疑问或意见,请告诉我

I hope it helps, let me know if you have any doubt or comment

更多推荐

我们如何使用API​​实现排除功能

本文发布于:2023-10-26 01:13:38,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1528642.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何使用   功能   API

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!