Skip to content

Instantly share code, notes, and snippets.

@underscorephil
Created May 8, 2013 20:36
Show Gist options
  • Save underscorephil/5543455 to your computer and use it in GitHub Desktop.
Save underscorephil/5543455 to your computer and use it in GitHub Desktop.
SoftLayer_Virtual_Guest::createObject using an existing CCI to populate the config values in addition to a image template.
import SoftLayer.API
from pprint import pprint as pp
api_username = ''
api_key = ''
image_template_name = ''
guestId = 1234
hostname = 'host1'
domain_name = 'example.com'
client = SoftLayer.Client(
username=api_username,
api_key=api_key,
)
def getImageTemplateGUID(templateName):
mask = "mask[name,globalIdentifier]"
templates = client['Account'].getBlockDeviceTemplateGroups(mask=mask)
for template in templates:
if template['name'] == templateName:
return template['globalIdentifier']
mask = '''
mask[
startCpus,
maxMemory,
networkComponents.maxSpeed,
blockDevices[device, diskImage.capacity],
operatingSystemReferenceCode,
localDiskFlag,
blockDeviceTemplateGroup
]'''
guest = client['Virtual_Guest'].getObject(id=guestId, mask=mask)
guest['hostname'] = hostname
guest['domain'] = domain_name
guest['hourlyBillingFlag'] = True
guest['blockDevices'] = [guest['blockDevices'][0]]
guest['networkComponents'] = [guest['networkComponents'][0]]
# operatingSystemReferenceCode & blockDevices are not necessary when ordering with an image template
del guest['operatingSystemReferenceCode']
del guest['blockDevices']
guest['blockDeviceTemplateGroup'] = {'globalIdentifier': getImageTemplateGUID(image_template_name)}
order_template = client['Virtual_Guest'].createObject(guest)
pp(order_template)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment