Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save sudorandom/6257385 to your computer and use it in GitHub Desktop.
Save sudorandom/6257385 to your computer and use it in GitHub Desktop.
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