Skip to content

Instantly share code, notes, and snippets.

@softlayer
Created April 21, 2010 21:26
Show Gist options
  • Save softlayer/374419 to your computer and use it in GitHub Desktop.
Save softlayer/374419 to your computer and use it in GitHub Desktop.
# So we can talk to the SoftLayer API:
import SoftLayer.API
# For nice debug output:
import pprint
# Grab these from the SoftLayer portal.
username = "set me!"
apiKey = "set me too!"
# The id of the CCI that we wish to duplicate.
virtualGuestId = 1234
# We're going to connect to two API services.
# Use SoftLayer_Virtual_Guest to get the order template from our
# CCI and use SoftLayer_Product_Order to verify and place an
# order for a new CCI.
virtualGuestClient = SoftLayer.API.Client("SoftLayer_Virtual_Guest", virtualGuestId, username, apiKey)
productOrderClient = SoftLayer.API.Client("SoftLayer_Product_Order", None, username, apiKey)
# Get the template used to order our CCI.
template = virtualGuestClient.getOrderTemplate('MONTHLY')
# Set template information for the new order.
# First, declare the template as a
# SoftLayer_Container_Product_Order_Virtual_Guest type, so the API knows
# you're trying to place an order for a virtual guest.
template['complexType'] = 'SoftLayer_Container_Product_Order_Virtual_Guest'
# We want to order one CCI.
template['quantity'] = 1
# Location id 3 = Dallas.
template['location'] = 3
# Set the hostname and domain for our new CCI. If ordering more
# than one CCI then define another hostname/domain pair accordingly.
template['virtualGuests'] = [
{
'hostname' : 'newcci',
'domain' : 'example.org'
}
]
# Verify the order container is right. If this returns an error
# then fix your order container and re-submit. Once ready then place
# your order with the placeOrder() method.
result = productOrderClient.verifyOrder(template)
# Both verifyOrder() and placeOrder() return a completed purchase
# order that you can use as a receipt.
pprint.pprint(result);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment