December 18, 2012

Classes
Tags blog

Simplified CCI Creation

<p>The SoftLayer API is a thorough beast...many ins and outs, options and choices. It is aimed to impart the greatest le

The SoftLayer API is a thorough beast...many ins and outs, options and choices. It is aimed to impart the greatest level of control to our customers and partners as possible. Our ordering system is a prime example. With it you are able to not only choose the standard assortment of specifications for a cloud server, but also if you want your storage stored locally vs on a SAN or even how you want us to contact you if there is an issue with a particular CCI...

However with great choice comes great complexity.

I am an avid supporter of the lazy developer as the lazy tend to find the simple and efficient solution. It is also true that our ordering API in the past has not necessarily catered towards the simple and efficient. Now however, we hope to inspire glee into the hearts of SLAPI developers lazy or not with the release of SoftLayer_Virtual_Guest::createObject. This new method will provide a simplified way to create a Cloud Computing Instance order.

What first jumped out at me with this new sytem is the amount of information required to place the order has been significantly reduced by the implementation of default values. When placing an order through SoftLayer_Virtual_Guest::createObject only 7 data points are required compared to the 19 of the old system.

The number of needed properties is not the only improvement, actually I would venture to say its not even the coolest...This new ordering process also comes with a new way to gather the possible values for your order. A quick call to SoftLayer_Virtual_Guest::getCreateObjectOptions will return all of the possible values to choose from in a organized list just begging to be put into your shopping cart.

'blockDevices': [{'itemPrice': {'hourlyRecurringFee': '0',
                                 'item': {'description': '25 GB (SAN)'},
                                 'recurringFee': '0'},
                   'template': {'blockDevices': [{'device': '0',
                                                  'diskImage': {'capacity': 25}}],
...
 'datacenters': [{'template': {'datacenter': {'name': 'ams01'}}},
                 {'template': {'datacenter': {'name': 'dal01'}}},
 
...
 'memory': [{'itemPrice': {'hourlyRecurringFee': '.03',
                           'item': {'description': '1 GB'},
                           'recurringFee': '21'},
...

Once you have decided which options to go with you need to put the values into a SoftLayer_Virtual_Guest template object and pass to SoftLayer_Virtual_Guest::createObject

import SoftLayer.API
from pprint import pprint as pp
 
api_username = 'arst'
api_key = '1234arst'
 
client = SoftLayer.Client(
    username=api_username,
    api_key=api_key
)
 
newCCI = {
    'hostname': 'test1',
    'domain': 'example.com',
    'startCpus': 1,
    'maxMemory': 1024,
    'hourlyBillingFlag': 'true',
    'operatingSystemReferenceCode': 'UBUNTU_LATEST',
    'localDiskFlag': 'false'
}
 
result = client['Virtual_Guest'].createObject(newCCI)
pp(result)

To check if the new CCI has completed the provisioning process we can look for the provisionDate:

client = SoftLayer.Client(
    username= "arst"
    api_key = "1234arst"
) 
 
object_mask = 'mask.provisionDate'
 
cci = client['Virtual_Guest'].getObject(mask=object_mask)
 
if ( 'provisionDate' in cci and cci['provisionDate'] != ):
    print 'CCI %s is online' % cci['hostname']
else:
    print 'CCI %s is provisioning' % cci['hostname']

While this new process should be straight forward, please do not hesitate to reach out if you have any questions, concerns or suggestions for future improvements.

-Phil

Example snippets for SoftLayer_Virtual_Guest::createObject:
https://gist.github.com/4271418 - Python
https://gist.github.com/4271461 - PHP
https://gist.github.com/4318794 - Ruby