0
votes

Is there a simple method to order portable storage given the input datacenter such as WDC06 and size 500 GB.

At the moment the method I know of is painful, complex and manual, if I have do this in a new datacenter. First get the configuration through Product_Package and then going through long list of items to find the right product id, itemId ... etc. This call also requires that I should know the pkgid before hand.

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

Please if you can share some code samples if this ordering process can be simplified.

1

1 Answers

0
votes

I have not idea how you are ordering the portable storage,but you need to use the placeOrder method and get the proper prices for the disk size that you want to order, this literature can help you to understand how to make orders:

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

The process to pick the correct prices is hard, but you can use the object filters to get them:

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

and here a sample using the 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