Created
March 11, 2010 04:06
-
-
Save softlayer/328806 to your computer and use it in GitHub Desktop.
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
# So we can talk to the SoftLayer API: | |
import xmlrpclib | |
# For nice debug output: | |
import pprint | |
# API Connection Details. | |
# 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. | |
virtualGuestUrl = "http://api.service.softlayer.com/xmlrpc/v3/SoftLayer_Virtual_Guest" | |
productOrderUrl = "http://api.service.softlayer.com/xmlrpc/v3/SoftLayer_Product_Order" | |
# 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 | |
# Define all API headers in a single nested dictionary. The | |
# SoftLayer_Product_Order service doesn't require an | |
# initialization parameter, so we only have to set init params | |
# for the SoftLayer_Virtual_Guest service. | |
headers = { | |
'headers' : { | |
'authenticate' : { | |
'username': username, | |
'apiKey': apiKey | |
}, | |
'SoftLayer_Virtual_GuestInitParameters': { | |
'id': virtualGuestId | |
} | |
} | |
} | |
# Set up proxy objects to SoftLayer API services. | |
virtualGuestClient = xmlrpclib.ServerProxy(virtualGuestUrl) | |
productOrderClient = xmlrpclib.ServerProxy(productOrderUrl) | |
# Get the template used to order our CCI. | |
template = virtualGuestClient.getOrderTemplate(headers, '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(headers, 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