如何使用SoftLayer API订购便携式存储

时间:2018-01-16 05:00:56

标签: storage ibm-cloud-infrastructure

在给定输入数据中心(如WDC06和500 GB)的情况下,是否有一种简单的方法来订购便携式存储。

目前,我所知道的方法是痛苦的,复杂的和手动的,如果我在新的数据中心中这样做的话。首先通过Product_Package获取配置,然后浏览长项目列表以找到正确的产品ID,itemId ......等。此调用还要求我事先了解pkgid

categories = client['Product_Package'].getConfiguration(id=pkgId, mask='isRequired, itemCategory.id, itemCategory.name, itemCategory.categoryCode')

如果可以简化此订购流程,请分享一些代码示例。

1 个答案:

答案 0 :(得分:0)

我不知道您如何订购便携式存储设备,但是您需要使用placeOrder方法并获得您想要订购的磁盘大小的正确价格,这些文献可以帮助您了解如何订单:

https://sldn.softlayer.com/blog/cmporter/location-based-pricing-and-you https://sldn.softlayer.com/blog/bpotter/going-further-softlayer-api-python-client-part-3

选择正确价格的过程很难,但您可以使用对象过滤器来获取它们:

https://sldn.softlayer.com/article/object-filters

这里是使用softlayer Python client的示例:

import SoftLayer

# Your SoftLayer API username and key.
API_USERNAME = 'set me'
API_KEY = 'set me'

datacenter = "wdc06" # lower case
size = "500" # the size of the disk
diskDescription = "optional value"

client = SoftLayer.Client(username=API_USERNAME, api_key=API_KEY)
package = 198 # this package is always the same
# Using a filter to get the price for an especific disk size
# into an specific datacenter
filter = {
    "itemPrices": {
        "pricingLocationGroup": {
            "locations": {
                "name": {
                    "operation": datacenter
                }
            }
        },
        "item": {
            "capacity": {
                "operation": size
            }
        }
    }
}
price = client['SoftLayer_Product_Package'].getItemPrices(id=package, filter=filter)
# In case the request do not return any price we will look for the standard price
if not price:
   filter = {
    "itemPrices": {
        "locationGroupId": {
            "operation": "is null"
            },
        "item": {
            "capacity": {
                "operation": size
                }
            }
        }
    }
   price = client['SoftLayer_Product_Package'].getItemPrices(id=package, filter=filter)
if not price:
    print ("there is no a price for the selected datacenter %s and disk size %s" % (datacenter, size))
    sys.exit(0)

# getting the locationId for the order template
filter = {
    "regions": {
        "location": {
            "location": {
                "name": {
                    "operation": datacenter
                }
            }
        }
    }
}
location = client['SoftLayer_Product_Package'].getRegions(id=package, filter=filter)
# now we are creating the ordertemplate
orderTemplate = {
    "complexType": "SoftLayer_Container_Product_Order_Virtual_Disk_Image",
    "packageId": package,
    "location": location[0]["location"]["location"]["id"],
    "prices": [{"id": price[0]["id"]}],
    "diskDescription": diskDescription
}

#When you are ready to order change "verifyOrder" by "placeOrder"
order = client['SoftLayer_Product_Order'].verifyOrder(orderTemplate)
print order