Skip to content

Instantly share code, notes, and snippets.

@sl-will
sl-will / gist:ef51ed3243fd073085ce
Last active July 14, 2017 19:27
SL API - REST - Upgrade a VSI
Virtual_Guest has a built in for item prices using getUpgradeItemPrices. This is a shortcut for iterating through the packages by hand and will only return valid upgrade items for the VSI. See https://gist.github.com/sl-will/6868575de6dc7263968f for more information on working with orders and products and https://gist.github.com/sl-will/e3274c68e0e9f5eafcd1 for general REST usage.
curl -s -H 'Accept: application/json' https://$APIUSER:$APIKEY@api.softlayer.com/rest/v3/SoftLayer_Virtual_Guest/11111/getUpgradeItemPrices?objectMask=categories.categoryCode;currentPriceFlag;hourlyRecurringFee;id;recurringFee
For RAM, these have the categoryCode of "ram" and item.keyName and item.description describe the amount. 2GB, for example, would be item 1645:
{
"categories": [
{
"categoryCode": "ram"
@sl-will
sl-will / gist:8416e99f568846959a12
Created March 5, 2015 00:04
SL API - Perl - Add advanced monitoring alarm subscriber Monitoring_Agent::setActiveAlarmSubscriber
#!/usr/bin/perl
# Pulling credentials from ENV, or set as hard values
$apiUser = $ENV{APIUSER};
$apiKey = $ENV{APIKEY};
$soapUrl= $ENV{APISOAPURL};
# Use the path to the SoftLayer API and include it
use lib $ENV{APIPERLINCLUDE};
use SoftLayer::API::SOAP;
@sl-will
sl-will / gist:5cec9332bf4f2a6854f7
Last active August 29, 2015 14:05
SL API - Ruby - Create NS Record
# Create an NS record using an existing ID for Dns_Domain
# http://sldn.softlayer.com/reference/services/SoftLayer_Dns_Domain/createNsRecord
require 'softlayer_api'
username = 'your-username'
api_key = 'yourlongapikey'
dns_domain = SoftLayer::Service.new('SoftLayer_Dns_Domain', :username => username, :api_key => api_key)
@sl-will
sl-will / gist:fbe6fb1af43dee92aaf8
Last active August 29, 2015 14:02
SL API - Python - Associate a VLAN to a Vyatta Gateway
# Note: tab = 2 spaces
import SoftLayer
from pprint import pprint as pp
# Set apikey and apiuser per your API credentials
apiuser='Your API User'
apikey='Your API Key'
# Initiate the client and authenticate
@sl-will
sl-will / gist:c099b21a1127027c9791
Last active August 29, 2015 14:01
SL API - Ruby - Append a firewall rule
# This code will append a firewall to the end of the rules chain for a standard (per server) firewall.
username = 'your username'
apikey = 'your apikey'
# The firewall of the ID, can be found with an object mask of firewallServiceComponent.id on SoftLayer_Hardware or SoftLayer_Virtual_Guest data type
# For example, SoftLayer_Account::getVirtualGuests with a mask of id and firewallServiceComponent for a full list
firewall_id = 123456
@sl-will
sl-will / gist:6868575de6dc7263968f
Created May 17, 2014 23:29
SL API - REST - Basics used in product orders
# The below commands will get the basic information used in ordering products
# All calls are assumed with an env variable of $APIUSER and $APIKEY for the API username and key
# The following examples can be piped to Python for better formatting, for example:
# curl api.softlayer.com/args | python -m json.tool | less
# Related gist for integrating with scripting https://gist.github.com/sl-will/e3274c68e0e9f5eafcd1
# Get a list of all datacenter locations, optionally with the region adding "groups.name" to the object mask
# Returns array [ {"id":int, "longName":string} ]
@sl-will
sl-will / gist:e3274c68e0e9f5eafcd1
Created May 17, 2014 21:40
SL API - REST/Bash - Basic bash script for RESTful calls
#!/bin/bash
# This script provides a basic command line shortcut for testing API calls using the SoftLayer RESTful API
# Note that using object masks uses semicolons which either must be escaped or the whole call wrapped in quotes
# Can pipe out to Python for better JSON formatting using: | python -m json.tool
# Requires curl. Usage (with "api" as script name):
# ./api SoftLayer_Class_Name/123456/editObject.json -X POST -d '{json object}'
# ./api "SoftLayer_Class_Name/getObjects.json?objectMask=myMask.description;myMask.id;id"
# Fill these two variables in
@sl-will
sl-will / gist:11275434
Last active August 29, 2015 14:00
SL API - Ruby - SoftLayer_Monitoring_Agent::getGraph
username = 'your username'
api_key = 'your api key'
virtual_guest_id = 000000
# Get the monitoring agents for virtual_guest_id
virtual_guest = SoftLayer::Service.new('SoftLayer_Virtual_Guest', :username => username, :api_key => api_key)
# For the sake of simplicity, we are just using the first entry, otherwise we would iterate through it