Create a gist now

Instantly share code, notes, and snippets.

Get the SoftLayer product packages that can be used to order custom monthly bare metal servers
import os
import pprint
import SoftLayer
client = SoftLayer.Client(username=os.environ['SLUSERNAME'], api_key=os.environ['SLAPIKEY'], endpoint_url=SoftLayer.API_PUBLIC_ENDPOINT)
mask = 'id, name, description, type.keyName, items.id, items.description, items.categories.categoryCode'
# We only want pkgs that include a server category because there are some older packages without a server category
# that can not be used any more.
filterStr = {
"items": {"categories": {"categoryCode": {"operation":"server"} } },
"type": {"keyName": {"operation":"BARE_METAL_CPU"} },
}
# Due to the properties used in the mask and filter, this call takes a while, about 20 seconds.
pkgs = client['Product_Package'].getAllObjects(mask=mask, filter=filterStr)
# Delete the full list of items for each pkg and add in just the server item descriptions, so it is easier
# to see what processor models are available in each pkg.
for p in pkgs:
for i in p['items']:
for c in i['categories']:
if c['categoryCode'] == 'server':
if not 'server' in p: p['server'] = []
p['server'].append(i['description'])
del p['items']
pprint.pprint(pkgs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment