Skip to content

Instantly share code, notes, and snippets.

@underscorephil
Created September 26, 2012 19:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save underscorephil/3790139 to your computer and use it in GitHub Desktop.
Save underscorephil/3790139 to your computer and use it in GitHub Desktop.
Python Upgrade CCI
# So we can talk to the SoftLayer API, grab the current date
# and structured list/dict output
import SoftLayer.API
import datetime
from pprint import pprint as pp
# Find the priceId for the RAM item matching our defined memory allotment
def getMemoryPrice(memoryCapacity):
packageClient = SoftLayer.API.Client('SoftLayer_Product_Package', 46, apiUsername, apiKey)
objectMask = "mask[capacity;prices.id;categories[name,id]]"
packageClient.set_object_mask(objectMask)
items = packageClient.getItems()
for item in items:
if len(filter(lambda x: x.get('id') == 3, item['categories'])) \
and item.get('capacity') == str(memoryCapacity):
return item['prices'][0]['id']
# Create the upgrade order container and send the order to the API. Replace
# verifyOrder() with placeOrder() after testing
def upgradeOrder(virtualGuestId, memoryPriceId):
orderClient = SoftLayer.API.Client('SoftLayer_Product_Order', None, apiUsername, apiKey)
orderContainer = {}
orderContainer['complexType'] = 'SoftLayer_Container_Product_Order_Virtual_Guest_Upgrade'
orderContainer['virtualGuests'] = [{'id': virtualGuestId}]
orderContainer['prices'] = [{'id': memoryPriceId}]
orderContainer['properties'] = [{'name': 'MAINTENANCE_WINDOW', 'value': str(datetime.datetime.now())}]
return orderClient.verifyOrder(orderContainer)
# Define our arguments and start the process
if __name__ == "__main__":
import argparse
argsparse = argparse.ArgumentParser(description='Upgrade a CCI\'s Memory')
argsparse.add_argument('virtualGuestId', metavar='Virtual Guest ID', type=int,
help='ID of the target CCI.')
argsparse.add_argument('memoryCapacity', metavar='Ram GBs', type=int,
help='Amount of RAM in GB.')
args = argsparse.parse_args()
apiUsername = ''
apiKey = ''
pp(upgradeOrder(args.virtualGuestId, getMemoryPrice(args.memoryCapacity)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment