过滤参数以对性能存储进行 POST 验证和下订单请求 [英] Filter parameters to POST verify and place order request for Performance storage

查看:14
本文介绍了过滤参数以对性能存储进行 POST 验证和下订单请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 Java REST 客户端进行 BPM 和 SoftLayer 集成.在我最初的分析(以及帮助表单堆栈溢出)中,我发现

I am trying to do BPM and SoftLayer integration using Java REST client. On my initial analysis(as well as help form stack overflow),I found

步骤 1) 我们获取 getPriceItem 列表以获取下一个请求的所有 ID.

Step 1) we to get getPriceItem list to have all IDs for next request.

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 调用.

and then do verify and place order POST call using respective APIs.

我被困在 Step 1) 上,因为这里的过滤似乎有点棘手.我收到超过 20000 行的 json 响应.

I am stucked on Step 1) as filtering here seems to be bit tricky. I am getting a json response of over 20000 lines.

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

I wanted to show similar data(just like SL Performance storage UI ) on my custom BPM UI . (One drop down to select type of storage, 2nd to show location, 3rd to show size and 4th would be IOPS) where user can select the items and place request.

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

Here I found, SL is something similar to this for populating the drop downs-

https://control.softlayer.com/sales/productpackage/getregions?_dc=1456386930027&categoryCode=performance_storage_iscsi&packageId=222&page=1&start=0&limit=25

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

Can't we have implementation where we can use control.softlayer.com just like SL instead of api.softlayer.com? In that case we can use similar logic to display data on UI.

谢谢阿努帕姆

推荐答案

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

Here, using the API, the steps for performance storage. For endure storage the steps are similar you just need to review the value for categoryCode and modify if it needed

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

you can get the locations using this method:

http://sldn.softlayer.com/reference/services/SoftLayer_Product_Package/getRegions

您只需要知道存储的包装,例如

you just need to know the package of the storage e.g.

GET https://api.softlayer.com/rest/v3.1/SoftLayer_Product_Package/222/getRegions

然后,您可以获得存储大小,您可以使用 SoftLayer_Product_Package::getItems 或 SoftLayer_Product_Package::getItemPrices 方法和过滤器,例如

then, you can get the storage size for that you can use the SoftLayer_Product_Package::getItems or SoftLayer_Product_Package::getItemPrices methods and a filter e.g.

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"}}}

注意:我们正在过滤数据以获得类别代码为performance_storage_space"的价格,我们希望标准价格 locationGroupId = null

Note: We are filtering the data to get the prices whose category code is "performance_storage_space" and we want the standard price locationGroupId = null

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

then, you can get the IOPS, you can use the same approach like above, but there is a dependency between the IOPS and storage space e.g.

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 价格 categoryCode = performance_storage_iops 我们只想要标准价格 locationGroupId=null

Note: In the example we assume that selected storage space was "20", the prices for IOPS have an record called atributes, this record tell us the valid storage spaces of the IOPS, then we have other filters to get only the IOPS prices categoryCode = performance_storage_iops and we want only the standard prices locationGroupId=null

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

To selecting the storage type I do not think there is a method the only way I see is that you call the SoftLayer_Product_Package::getAllObjects method and filter the data to get the packages for endurance, performance and portable storage.

以防万一这里使用 Softlayer 的 Python 客户端进行订购的示例

Just in case here an example using the Softlayer's Python client to order

"""
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))

这篇关于过滤参数以对性能存储进行 POST 验证和下订单请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆