Skip to content

Instantly share code, notes, and snippets.

@underscorephil
underscorephil / gist:3519545
Created August 29, 2012 22:11
Cancel Multiple Servers
<?php
require_once('SoftLayer/SoapClient.class.php');
/**
* Set your SoftLayer API username and key.
*/
$apiUsername = '';
$apiKey = '';
@underscorephil
underscorephil / gist:3693460
Created September 10, 2012 20:00
Retrieve Transcode FTP Credentials
function _getFtpCredentials() {
$accountClient = SoftLayer_SoapClient::getClient('SoftLayer_Account', null, API_USER, API_KEY);
$transcodeAccount = array_shift($accountClient->getTranscodeAccounts());
$transcodeAccountClient = SoftLayer_SoapClient::getClient('SoftLayer_Network_Media_Transcode_Account', $transcodeAccount->id, API_USER, API_KEY);
return($transcodeAccountClient->getFtpAttributes());
}
@underscorephil
underscorephil / gist:3693506
Created September 10, 2012 20:09
Create Object Storage Client
function _getObjectStorageClient() {
$options = array('adapter' => ObjectStorage_Http_Client::SOCKET, 'timeout' => 10);
$host = 'https://dal05.objectstorage.softlayer.net'; // the SoftLayer Object Storage API host
$username = OBJSTOR_USER; // user name and password is display at https://manage.softlayer.com/ObjectStorage/index
$password = API_KEY;
return new ObjectStorage($host, $username, $password, $options);
}
@underscorephil
underscorephil / gist:3777178
Created September 24, 2012 17:32
Command Line Order CCI
import SoftLayer.API
import pprint
def table_print(data, title_row):
max_widths = {}
data_copy = [dict(title_row)] + list(data)
for col in data_copy[0].keys():
max_widths[col] = max([len(str(row[col])) for row in data_copy])
cols_order = [tup[0] for tup in title_row]
@underscorephil
underscorephil / gist:3790139
Created September 26, 2012 19:44
Python Upgrade CCI
# So we can talk to the SoftLayer API, grab the current date
# and structured list/dict output
import SoftLayer.API
import datetime
from pprint import pprint as pp
# Find the priceId for the RAM item matching our defined memory allotment
def getMemoryPrice(memoryCapacity):
packageClient = SoftLayer.API.Client('SoftLayer_Product_Package', 46, apiUsername, apiKey)
mask[
id;
uplinkComponent[
id;
hardware[
fullyQualifiedDomainName;
id;
hardwareChassis[
id;
hardwareFunction.code
@underscorephil
underscorephil / gist:4067337
Last active October 12, 2015 18:18
Order a monthly billed virtual server in Python based on an existing image template
import SoftLayer.API
from pprint import pprint as pp
apiUsername = ''
apiKey = ''
templateId =
client = SoftLayer.API.Client('SoftLayer_Product_Order', None, apiUsername, apiKey)
@underscorephil
underscorephil / gist:4067364
Last active October 12, 2015 18:18
Retrieve required price options
import SoftLayer
apiUsername = ''
apiKey = ''
package = 46
client = SoftLayer.Client(username=apiUsername, api_key=apiKey)
categoryObjectMask = "mask[isRequired, itemCategory[id, name]]"
configurations = client['Product_Package'].getConfiguration(
@underscorephil
underscorephil / template_id_by_name.py
Last active February 2, 2017 17:57
Retrieve imageTemplateId by name
import SoftLayer
from pprint import pprint as pp
apiUsername = ''
apiKey = ''
def getImageTemplateId(templateName):
client = SoftLayer.Client(username=apiUsername, api_key=apiKey)
templates = client['Account'].getBlockDeviceTemplateGroups()
for template in templates:
@underscorephil
underscorephil / gist:4125357
Created November 21, 2012 15:14
Get required price options for package
<?php
require_once('softlayer-api-php-client/SoftLayer/SoapClient.class.php');
/**
* Set your SoftLayer API username and key.
*/
$apiUsername = '';
$apiKey = '';
$packageId = 46;