Api 筛选参数以对性能存储进行后期验证和下订单请求

Api 筛选参数以对性能存储进行后期验证和下订单请求,api,ibm-cloud-infrastructure,Api,Ibm Cloud Infrastructure,我正在尝试使用JavaREST客户端进行BPM和软层集成。在我最初的分析(以及帮助形成堆栈溢出)中,我发现 步骤1)我们需要获取getPriceItem列表,以便为下一个请求提供所有ID https://username:api_key@api.softlayer.com/rest/v3/SoftLayer_Product_Package/2/getItemPrices?objectMask=mask[id,item[keyName,description],pricingLocationGro

我正在尝试使用JavaREST客户端进行BPM和软层集成。在我最初的分析(以及帮助形成堆栈溢出)中,我发现

步骤1)我们需要获取getPriceItem列表,以便为下一个请求提供所有ID

https://username:api_key@api.softlayer.com/rest/v3/SoftLayer_Product_Package/2/getItemPrices?objectMask=mask[id,item[keyName,description],pricingLocationGroup[locations[id, name, longName]]]
然后使用相应的API进行验证和下订单POST调用

我被
步骤1)
绊住了,因为这里的过滤似乎有点棘手。我得到了超过20000行的json响应

我希望在自定义BPM UI上显示类似的数据(就像SL Performance storage UI一样)。(一个下拉框用于选择存储类型,第二个下拉框用于显示位置,第三个下拉框用于显示大小,第四个下拉框用于显示IOPS),用户可以在其中选择项目并放置请求

在这里,我发现SL与此类似,用于填充下拉列表-

我们不能像SL一样使用
control.softlayer.com
而不是
api.softlayer.com
吗?在这种情况下,我们可以使用类似的逻辑在UI上显示数据

谢谢
Anupam

这里使用API介绍了性能存储的步骤。对于持久存储,步骤类似,您只需查看categoryCode的值,并根据需要进行修改

您可以使用以下方法获取位置:

你只需要知道仓库的包装

GET https://api.softlayer.com/rest/v3.1/SoftLayer_Product_Package/222/getRegions
然后,您可以使用SoftLayer_Product_Package::getItems或SoftLayer_Product_Package::getItemPrices方法和过滤器获取存储大小,例如

GET https://api.softlayer.com/rest/v3.1/SoftLayer_Product_Package/222/getItemPrices?objectFilter={"itemPrices": {"categories": {"categoryCode": {"operation": "performance_storage_space"}},"locationGroupId": { "operation": "is null"}}}
注意:我们正在筛选数据,以获得类别代码为“性能\存储\空间”的价格,我们希望标准价格locationGroupId=null

然后,您可以获得IOPS,您可以使用与上面相同的方法,但是IOPS和存储空间之间存在依赖关系,例如

GET https://api.softlayer.com/rest/v3.1/SoftLayer_Product_Package/222/getItemPrices?objectFilter={"itemPrices": { "attributes": { "value": { "operation": 20 } },  "categories": { "categoryCode": {    "operation": "performance_storage_iops" } },    "locationGroupId": {    "operation": "is null" } } }
注意:在本例中,我们假设所选存储空间为“20”,IOPS的价格有一个名为atributes的记录,该记录告诉我们IOPS的有效存储空间,然后我们有其他过滤器仅获取IOPS价格类别代码=性能\存储\ IOPS,我们只需要标准价格locationGroupId=null

要选择存储类型,我认为没有方法。我看到的唯一方法是调用SoftLayer_Product_Package::getAllObjects方法并过滤数据,以获得耐久性、性能和便携式存储的软件包

这里举一个使用Softlayer的Python客户端进行订购的示例

"""
Order a block storage (performance ISCSI).

Important manual pages:
http://sldn.softlayer.com/reference/services/SoftLayer_Product_Order
http://sldn.softlayer.com/reference/services/SoftLayer_Product_Order/verifyOrder
http://sldn.softlayer.com/reference/services/SoftLayer_Product_Order/placeOrder
http://sldn.softlayer.com/reference/services/SoftLayer_Product_Package
http://sldn.softlayer.com/reference/services/SoftLayer_Product_Package/getItems
http://sldn.softlayer.com/reference/services/SoftLayer_Location
http://sldn.softlayer.com/reference/services/SoftLayer_Location/getDatacenters
http://sldn.softlayer.com/reference/services/SoftLayer_Network_Storage_Iscsi_OS_Type
http://sldn.softlayer.com/reference/services/SoftLayer_Network_Storage_Iscsi_OS_Type/getAllObjects
http://sldn.softlayer.com/reference/datatypes/SoftLayer_Location
http://sldn.softlayer.com/reference/datatypes/SoftLayer_Container_Product_Order_Network_Storage_Enterprise
http://sldn.softlayer.com/reference/datatypes/SoftLayer_Product_Item_Price
http://sldn.softlayer.com/blog/cmporter/Location-based-Pricing-and-You
http://sldn.softlayer.com/blog/bpotter/Going-Further-SoftLayer-API-Python-Client-Part-3
http://sldn.softlayer.com/article/Object-Filters
http://sldn.softlayer.com/article/Python
http://sldn.softlayer.com/article/Object-Masks

License: http://sldn.softlayer.com/article/License
Author: SoftLayer Technologies, Inc. <sldn@softlayer.com>
"""

import SoftLayer
import json

# Values "AMS01", "AMS03", "CHE01", "DAL05", "DAL06" "FRA02", "HKG02", "LON02", etc.
location = "AMS01"

# Values "20", "40", "80", "100", etc.
storageSize = "40"

# Values between "100" and "6000" by intervals of 100.
iops = "100"

# Values "Hyper-V", "Linux", "VMWare", "Windows 2008+", "Windows GPT", "Windows 2003", "Xen"
os = "Linux"

PACKAGE_ID = 222

client = SoftLayer.Client()
productOrderService = client['SoftLayer_Product_Order']
packageService = client['SoftLayer_Product_Package']
locationService = client['SoftLayer_Location']
osService = client['SoftLayer_Network_Storage_Iscsi_OS_Type']

objectFilterDatacenter = {"name": {"operation": location.lower()}}
objectFilterStorageNfs = {"items": {"categories": {"categoryCode": {"operation": "performance_storage_iscsi"}}}}
objectFilterOsType = {"name": {"operation": os}}

try:
    # Getting the datacenter.
    datacenter = locationService.getDatacenters(filter=objectFilterDatacenter)
    # Getting the performance storage NFS prices.
    itemsStorageNfs = packageService.getItems(id=PACKAGE_ID, filter=objectFilterStorageNfs)
    # Getting the storage space prices
    objectFilter = {
        "itemPrices": {
            "item": {
                "capacity": {
                    "operation": storageSize
                }
            },
            "categories": {
                "categoryCode": {
                    "operation": "performance_storage_space"
                }
            },
            "locationGroupId": {
                "operation": "is null"
            }
        }
    }
    pricesStorageSpace = packageService.getItemPrices(id=PACKAGE_ID, filter=objectFilter)
    # If the prices list is empty that means that the storage space value is invalid.
    if len(pricesStorageSpace) == 0:
        raise ValueError('The storage space value: ' + storageSize + ' GB, is not valid.')
    # Getting the IOPS prices
    objectFilter = {
        "itemPrices": {
            "item": {
                "capacity": {
                    "operation": iops
                }
            },
            "attributes": {
                "value": {
                    "operation": storageSize
                }
            },
            "categories": {
                "categoryCode": {
                    "operation": "performance_storage_iops"
                }
            },
            "locationGroupId": {
                "operation": "is null"
            }
        }
    }
    pricesIops = packageService.getItemPrices(id=PACKAGE_ID, filter=objectFilter)
    # If the prices list is empty that means that the IOPS value is invalid for the configured storage space.
    if len(pricesIops) == 0:
        raise ValueError('The IOPS value: ' + iops + ', is not valid for the storage space: ' + storageSize + ' GB.')
    # Getting the OS.
    os = osService.getAllObjects(filter=objectFilterOsType)
    # Building the order template.
    orderData = {
        "complexType": "SoftLayer_Container_Product_Order_Network_PerformanceStorage_Iscsi",
        "packageId": PACKAGE_ID,
        "location": datacenter[0]['id'],
        "quantity": 1,
        "prices": [
            {
                "id": itemsStorageNfs[0]['prices'][0]['id']
            },
            {
                "id": pricesStorageSpace[0]['id']
            },
            {
                "id": pricesIops[0]['id']
            }
        ],
        "osFormatType": os[0]
    }
    # verifyOrder() will check your order for errors. Replace this with a call to
    # placeOrder() when you're ready to order. Both calls return a receipt object
    # that you can use for your records.
    response = productOrderService.verifyOrder(orderData)
    print(json.dumps(response, sort_keys=True, indent=2, separators=(',', ': ')))
except SoftLayer.SoftLayerAPIError as e:
    print("Unable to place the order. faultCode=%s, faultString=%s" % (e.faultCode, e.faultString))
“”“
订购块存储(性能ISCSI)。
重要手册页:
http://sldn.softlayer.com/reference/services/SoftLayer_Product_Order
http://sldn.softlayer.com/reference/services/SoftLayer_Product_Order/verifyOrder
http://sldn.softlayer.com/reference/services/SoftLayer_Product_Order/placeOrder
http://sldn.softlayer.com/reference/services/SoftLayer_Product_Package
http://sldn.softlayer.com/reference/services/SoftLayer_Product_Package/getItems
http://sldn.softlayer.com/reference/services/SoftLayer_Location
http://sldn.softlayer.com/reference/services/SoftLayer_Location/getDatacenters
http://sldn.softlayer.com/reference/services/SoftLayer_Network_Storage_Iscsi_OS_Type
http://sldn.softlayer.com/reference/services/SoftLayer_Network_Storage_Iscsi_OS_Type/getAllObjects
http://sldn.softlayer.com/reference/datatypes/SoftLayer_Location
http://sldn.softlayer.com/reference/datatypes/SoftLayer_Container_Product_Order_Network_Storage_Enterprise
http://sldn.softlayer.com/reference/datatypes/SoftLayer_Product_Item_Price
http://sldn.softlayer.com/blog/cmporter/Location-based-Pricing-and-You
http://sldn.softlayer.com/blog/bpotter/Going-Further-SoftLayer-API-Python-Client-Part-3
http://sldn.softlayer.com/article/Object-Filters
http://sldn.softlayer.com/article/Python
http://sldn.softlayer.com/article/Object-Masks
许可证:http://sldn.softlayer.com/article/License
作者:SoftLayer Technologies,Inc。
"""
导入软层
导入json
#值“AMS01”、“AMS03”、“CHE01”、“DAL05”、“DAL06”、“FRA02”、“HKG02”、“LON02”等。
location=“AMS01”
#值“20”、“40”、“80”、“100”等。
storageSize=“40”
#以100为间隔在“100”和“6000”之间的值。
iops=“100”
#值“Hyper-V”、“Linux”、“VMWare”、“Windows 2008+”、“Windows GPT”、“Windows 2003”、“Xen”
os=“Linux”
包ID=222
client=SoftLayer.client()
productOrderService=client['SoftLayer\u Product\u Order']
packageService=客户端['SoftLayer\u产品\u软件包']
locationService=客户端['SoftLayer\u Location']
osService=客户端['SoftLayer\网络\存储\ Iscsi\操作系统\类型']
objectFilterDatacenter={“名称”:{“操作”:location.lower()}
objectFilterStorageNfs={“项”:{“类别”:{“类别代码”:{“操作”:“性能存储”{U iscsi”}}
objectFilterOsType={“名称”:{“操作”:os}
尝试:
#获取数据中心。
数据中心=locationService.getDatacenters(筛选器=objectFilterDatacenter)
#获取性能存储NFS价格。
itemsStorageNfs=packageService.getItems(id=PACKAGE\u id,filter=objectFilterStorageNfs)
#获取存储空间价格
objectFilter={
“项目价格”:{
“项目”:{
“能力”:{
“操作”:存储大小
}
},
“类别”:{
“类别代码”:{
“操作”:“性能存储空间”
}
},
“locationGroupId”:{
“操作”:“为空”
}
}
}
pricesStorageSpace=packageService.getItemPrices(id=PACKAGE\u id,filter=objectFilter)
#如果价目表为空,则表示存储空间值无效。
如果len(pricesStorageSpace)==0:
raise VALUERROR('存储空间值:'+storageSize+'GB,无效。'))
#获取IOPS价格
objectFilter={
“项目价格”:{
“项目”:{
“能力”:{
“啊