Last active
August 29, 2015 14:27
-
-
Save bmpotter/664ee9af622ce08da9a4 to your computer and use it in GitHub Desktop.
Get the SoftLayer product packages that can be used to order custom monthly bare metal servers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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