November 23, 2017


get_storage_space_prices_for_location.py

get_storage_space_prices_for_location.py
"""
Get the storage space prices to order an endurance space.

The script retrieves all the storage spaces prices which
meet an IOPS requirement and these prices are valid to
an arbitrary location.

Important manual pages:
http://sldn.softlayer.com/reference/services/SoftLayer_Product_Package
http://sldn.softlayer.com/reference/services/SoftLayer_Product_Package/getItems

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

import SoftLayer
import json

USERNAME = 'set me'
API_KEY = 'set me'

# The package id to order endurance object storage.
packageId = 240

# value = 200 is for 2 IOPS per GB.
# value = 100 is for 0.25 IOPS per GB.
# value = 300 is for 4 IOPS per GB.
iops = 100

# The list of location group ids
# from where we wish to get the prices.
locationGroupIds = [505]

# Declares the API client.
client = SoftLayer.Client(username=USERNAME, api_key=API_KEY)
productPackage = client['SoftLayer_Product_Package']

# Declares an object filter in order to get only the standard prices
# which are for storage spaces and meet the requirements for
# the configured IOPS.
objectFilter = {"items": {"prices": {"capacityRestrictionMaximum": {"operation": iops}, "categories": {"categoryCode": {"operation": "performance_storage_space"}}, "locationGroupId": {"operation": "in", "options": [{"name": "data", "value": [505]}]}}}}

try:
    items = productPackage.getItems(id=packageId, filter=objectFilter)
    print(json.dumps(items, sort_keys=True, indent=2, separators=(',', ': ')))
except SoftLayer.SoftLayerAPIError as e:
    print("Unable to get the prices. faultCode=%s, faultString=%s" % (e.faultCode, e.faultString))

Feedback?

If this article contains any error, or leaves any of your questions unanswered, please help us out by opening up a github issue.
Open an issue