Skip to content

Instantly share code, notes, and snippets.

@bmpotter
bmpotter / hw-create-options.txt
Last active August 29, 2015 14:27
Example output of Hardware::getCreateObjectOptions() method
{'datacenters': [{'template': {'datacenter': {'name': 'ams01'}}},
{'template': {'datacenter': {'name': 'ams03'}}},
{'template': {'datacenter': {'name': 'dal01'}}},
{'template': {'datacenter': {'name': 'dal05'}}},
{'template': {'datacenter': {'name': 'dal06'}}},
{'template': {'datacenter': {'name': 'dal09'}}},
{'template': {'datacenter': {'name': 'fra02'}}},
{'template': {'datacenter': {'name': 'hkg02'}}},
{'template': {'datacenter': {'name': 'hou02'}}},
{'template': {'datacenter': {'name': 'lon02'}}},
@bmpotter
bmpotter / calc-preset-hourly-price.py
Last active August 29, 2015 14:27
Code for calculating the precise price of hourly bare metal pre-set configurations
import os
import pprint
import SoftLayer
client = SoftLayer.Client(username=os.environ['SLUSERNAME'], api_key=os.environ['SLAPIKEY'], endpoint_url=SoftLayer.API_PUBLIC_ENDPOINT)
pkgId = 200
mask = 'id, description, keyName, totalMinimumRecurringFee, configuration, configuration.price.hourlyRecurringFee, configuration.price.item.keyName'
# http://sldn.softlayer.com/reference/services/SoftLayer_Product_Package/getActivePresets
presets = client['Product_Package'].getActivePresets(id=pkgId, mask=mask)
@bmpotter
bmpotter / get-bare-metal-provision-status.py
Last active August 29, 2015 14:27
Get the status of a bare metal server that is in the process of being provisioned
import os
import pprint
import SoftLayer
client = SoftLayer.Client(username=os.environ['SLUSERNAME'], api_key=os.environ['SLAPIKEY'], endpoint_url=SoftLayer.API_PUBLIC_ENDPOINT)
# Call this repeatedly while the bare metal server is being provisioned, until provisionDate is filled in.
mask = 'mask[id,fullyQualifiedDomainName,provisionDate,hardwareStatus,lastTransaction[elapsedSeconds,transactionStatus[friendlyName]],operatingSystem[id,passwords[password,username]]]'
hostname = 'simplebmi'
domain = 'test.com'
filterStr = {"hardware":{"hostname":{"operation":hostname},"domain":{"operation":domain}}}
@bmpotter
bmpotter / get-bare-metal-pkgs.py
Last active August 29, 2015 14:27
Get the SoftLayer product packages that can be used to order custom monthly bare metal servers
import os
import pprint
import SoftLayer
client = SoftLayer.Client(username=os.environ['SLUSERNAME'], api_key=os.environ['SLAPIKEY'], endpoint_url=SoftLayer.API_PUBLIC_ENDPOINT)
mask = 'id, name, description, type.keyName, items.id, items.description, items.categories.categoryCode'
# We only want pkgs that include a server category because there are some older packages without a server category
# that can not be used any more.
filterStr = {
"items": {"categories": {"categoryCode": {"operation":"server"} } },
@bmpotter
bmpotter / bare-metal-pkgs.txt
Created August 12, 2015 14:51
Sample output of query the custom bare metal product pkgs using https://gist.github.com/bmpotter/664ee9af622ce08da9a4
[{'id': 56,
'name': 'Quad Processor Multi Core Nehalem EX',
'server': ['Quad Intel Xeon E7-4850 (10 Cores, 2.00 GHz)'],
'type': {'keyName': 'BARE_METAL_CPU'}},
{'id': 126,
'name': 'Single Xeon 1200 Series (Sandy Bridge / Haswell)',
'server': ['Single Intel Xeon E3-1270 v3 (4 Cores, 3.50 GHz)',
'Single Intel Xeon E3-1270 (4 Cores, 3.40 GHz)'],
'type': {'keyName': 'BARE_METAL_CPU'}},
{'id': 142,
@bmpotter
bmpotter / pkg.253.tor01.txt
Created August 13, 2015 09:56
Example output of getOrderItemsDict() for pkg 253 in Toronto from order-custom-monthly-bare-metal.py
{'av_spyware_protection': {'catName': 'Anti-Virus & Spyware Protection',
'isRequired': False,
'items': {'MCAFEE_VIRUSSCAN_ANTIVIRUS_WINDOWS': {'description': 'McAfee VirusScan Enterprise',
'fee': '0',
'hourlyFee': '0',
'id': 397,
'locationGroupId': '',
'priceId': 594}}},
'bandwidth': {'catName': 'Public Bandwidth',
'isRequired': True,
@bmpotter
bmpotter / getOrderItemsDict.py
Last active October 14, 2015 12:05
Get all of the item price objects for the given pkg, keyed by the keyName
import os
import sys
from pprint import pprint as pp
import SoftLayer
def getOrderItemsDict(client, pkgId, location=None, displayFiltered=False):
'''Get all of the item price objects for the given pkg, keyed by the keyName, with the id as the value,
and organize these keyName/id pairs by category. The issue here is that keyName is the same between accounts,
the id is not. But it is the id that we need to pass into the order.
If location==None, return only the location independent price objects.
@bmpotter
bmpotter / order-preset-bare-metal.py
Created August 12, 2015 12:58
Example of ordering an hourly pre-set configuration bare metal server
import os
import pprint
import SoftLayer
client = SoftLayer.Client(username=os.environ['SLUSERNAME'], api_key=os.environ['SLAPIKEY'], endpoint_url=SoftLayer.API_PUBLIC_ENDPOINT)
hw = {
'datacenter': {'name': 'tor01'},
'hostname': 'simplebmi',
'domain': 'test.com',
'hourlyBillingFlag': True,
@bmpotter
bmpotter / order-preset-bare-metal.py-2.py
Last active October 20, 2016 21:59
An alternative/better way to order hourly pre-set bare metal svr configurations
import os
import sys
from pprint import pprint as pp
import SoftLayer
# !!!!! To run this you must also get getOrderItemsDict() and supporting functions
# from: https://gist.github.com/bmpotter/db0c5feda536f2d502cd
def getPresetsDict(client, pkgId=200):
@bmpotter
bmpotter / order-custom-monthly-bare-metal.py
Last active May 24, 2017 20:12
Example of ordering a monthly custom bare metal server
import os
import pprint
import SoftLayer
# !!!!! To run this you must also get getOrderItemsDict() and supporting functions
# from: https://gist.github.com/bmpotter/db0c5feda536f2d502cd
# Main - Order a bare metal svr using the more involved, but more flexible, product package method.