Skip to content

Instantly share code, notes, and snippets.

@Juice10
Created October 23, 2015 13:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Juice10/5b93fac6669b2cf3d5c1 to your computer and use it in GitHub Desktop.
Save Juice10/5b93fac6669b2cf3d5c1 to your computer and use it in GitHub Desktop.
List SoftLayer package ids for ordering via SoftLayer_Product_Order (in python). For ordering see: https://softlayer.github.io/python/create_server_from_template/
import SoftLayer
from pprint import pprint as pp
# HELP: please scroll to the very bottom to see how this works
class example():
def __init__(self):
self.client = SoftLayer.Client()
def main(self):
"""
Gets ALL packages, and prints their name and id
"""
mask = "mask[hourlyBillingAvailableFlag]"
result = self.client['Product_Package'].getAllObjects();
for product in result:
print str(product['id']) + " - " + product['name']
# result has a LOT of stuff in it, only print it out if you are ready
# pp.pprint(result)
def getPackage(self, package_id=0):
"""
Gets a specific package and prints out some useful information
"""
mask = "mask[items[prices]]"
# Not all packages are available in all locations, you can check that with getLocations()
locations = self.client['Product_Package'].getLocations(id=package_id)
print "\n\nLOCATIONS\n"
for location in locations:
print str(location['id']) + " - " + location["longName"]
result = self.client['Product_Package'].getObject(mask=mask,id=package_id)
# result has a LOT of output
# pp(result)
print "\n\nOPTIONS\n"
for item in result['items']:
print str(item['id']) + " - " + item['description'] + " --- " + item['keyName']
for prices in item['prices']:
print "\t" + str(prices['id']) + " - locationGroupId: " + str(prices['locationGroupId']) # more on locationGroupId: http://sldn.softlayer.com/blog/cmporter/Location-based-Pricing-and-You
# # Will only get the server items for this package
# serverItems = self.client['Product_Package'].getActiveServerItems(id=package_id)
# print "\n\nSERVER ITEMS\n"
# pp(serverItems)
#
# # Will only get the RAM items for the package
# ramItems = self.client['Product_Package'].getActiveRamItems(id=package_id)
# print "\n\nRAM ITEMS\n"
# pp(ramItems)
def getAllLocations(self):
mask = "mask[id,locations[id,name]]"
result = self.client['SoftLayer_Location_Group_Pricing'].getAllObjects(mask=mask);
pp(result)
if __name__ == "__main__":
main = example()
# # step 1, run main() to get list of (virtual) hardware to select
# main.main()
# step 2, once (virtual) hardware is selected run getPackage(HARDWAREID) to see possible selectable items for this hardware
main.getPackage(46) # 46 is cloud server
# # if you are lost you can always run the following:
# main.getAllLocations()
# Oops you scrolled to far, go up a little bit to step 1 to see how this script works
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment