September 1, 2014


Required price IDs for package

For any package retrieve a list of options organized by required category
import SoftLayer
package = 46

client = SoftLayer.Client()
categoryObjectMask = "mask[isRequired, itemCategory[id, name]]"

configurations = client['Product_Package'].getConfiguration(
    id=package, mask=categoryObjectMask)

pricesObjectMask = "mask[id;item.description;categories.id]"

prices = client['Product_Package'].getItemPrices(
    id=package, mask=pricesObjectMask)

headerFormat = '%s - %s:'
priceFormat = '    %s -- %s'
for configuration in configurations:
    if (not configuration['isRequired']):
        continue
    print headerFormat % (configuration['itemCategory']['name'],
                          configuration['itemCategory']['id'])
    for price in prices:
        if ('categories' not in price):
            continue
        if any((category.get('id') == configuration['itemCategory']['id']
                for category in price['categories'])):
            print priceFormat % (price['id'], price['item']['description'])