There are many ways to order several virtual servers, in your case the method SoftLayer_Virtual_Guest::generateOrderTemplate returns the container type SoftLayer_Container_Product_Order_Virtual_Guest that can be send to the method SoftLayer_Product_Order::verifyOrder or SoftLayer_Product_Order::placeOrder.
If you look the example for Virtual Servers in the SoftLayer_Product_Order::placeOrder page. You'll notice that you need to modify the quantity AND virtualGuest parameters as following.
'virtualGuests': [
{
'domain': 'exampledomain.com',
'hostname': 'testhost1'
},
{
'domain': 'exampledomain.com',
'hostname': 'testhost2'
},
{
'domain': 'exampledomain.com',
'hostname': 'testhost3'
}
],
'quantity': 3
Then your python code should looks like this:
"""
Create a VSI using the simplified way.
The script creates an order template by using the method generateOrderTemplate(), we'll
modify the response in order to create several virtual servers.
See below for more information.
Important manual pages:
http://sldn.softlayer.com/reference/services/SoftLayer_Virtual_Guest/generateOrderTemplate/
http://sldn.softlayer.com/reference/datatypes/SoftLayer_Container_Product_Order_Virtual_Guest
http://sldn.softlayer.com/reference/datatypes/SoftLayer_Container_Product_Order
http://sldn.softlayer.com/reference/services/SoftLayer_Product_Order/verifyOrder/
http://sldn.softlayer.com/reference/services/SoftLayer_Product_Order/placeOrder/
http://sldn.softlayer.com/reference/datatypes/SoftLayer_Virtual_Guest
License: http://sldn.softlayer.com/article/License
Author: SoftLayer Technologies, Inc. <sldn@softlayer.com>
"""
import SoftLayer
# Your SoftLayer API username.
USERNAME = 'set me'
API_KEY = 'set me'
# To get the configuration options to create the server call the
# SoftLayer_Virtual_Guest::getCreateObjectOptions method.
vmorderparmers = {
'hostname': 'testhost',
'domain': 'exampledomain.com',
'datacenter': {'name': 'sjc01'},
'startCpus': 1,
'maxMemory': 1024,
'localDiskFlag': True,
'hourlyBillingFlag': True,
'operatingSystemReferenceCode': 'CENTOS_6_64',
'blockDevices': [
{
'device': '0',
'diskImage': {'capacity': 100}
}
]
}
# Declare the API client
client = SoftLayer.create_client_from_env(username=USERNAME, api_key=API_KEY)
try:
container = client['SoftLayer_Virtual_Guest'].generateOrderTemplate(vmorderparmers)
# In order to create several VSI we modify the following parameters in the response
container['quantity'] = 3
# If you set quantity greater than 1 then you need to define
# hostname/domain per virtual server you wish to order.
container['virtualGuests'] = [
{
'domain': 'exampledomain.com',
'hostname': 'testhost1'
},
{
'domain': 'exampledomain.com',
'hostname': 'testhost2'
},
{
'domain': 'exampledomain.com',
'hostname': 'testhost3'
}
]
"""
Now we are able to verify or place the order.
verifyOrder() will check your order for errors. Replace this with a call to
placeOrder() when you're ready to order. Both calls return a receipt object
that you can use for your records.
"""
receipt = client['SoftLayer_Product_Order'].verifyOrder(container)
print (receipt)
except SoftLayer.SoftLayerAPIError as e:
"""
If there was an error returned from the SoftLayer API then bomb out with the
error message.
"""
print('Unable to create the VSI. %s, %s ' % (e.faultCode, e.faultString))
I hope this help you.