Skip to content

Instantly share code, notes, and snippets.

@ryanrhanson
ryanrhanson / dns.php
Last active December 14, 2015 16:29
Loop through dns records on account, storing them in 'zones/$domain.tld.db'
<?php
/*
This script will take all dns records on a SoftLayer account and create a dns zone file for them in the 'zones' subdirectory. If this subdirectory does not exist, it will be created.
If single_use is set to true, you can supply your API Username and Key as arguments to the script. single_use also assumes that it is in the same directory as the SoftLayer folder from the PHP API Client. If single_use is false, it will draw from a file in the 'configuration' subdirectory named apiconfig.php, which should define apiUsername, apiKey, and the path to the SoapClient.class.php file.
*/
$single_use = true;
if ($single_use) {
require_once('SoftLayer/SoapClient.class.php');
@ryanrhanson
ryanrhanson / ccikvm.php
Last active December 14, 2015 22:29
Retrieve all CCI KVM IPs and ports on an account, along with root password on file (as this should be kvm password)
<?php
/*
/ ccikvm.php - Used to pull KVM credentials for all cloud instances on an account.
/ With single_use true, you need to supply the api username and password as the first and second arguments.
/ This assumes that you have ccikvm.php in the same directory as the 'SoftLayer' folder in the PHP api client.
/ Syntax: php ccikvm.php $apiUsername $apiKey
/
/ If single_use is false, this will look for configuration/apiconfig.php, which will need to contain the
/ apiUsername, apiKey, and the path to the SoftLayer php client directory. Only useful if you have a lot
/ of scripts to work with.
@ryanrhanson
ryanrhanson / domdel.php
Last active December 16, 2015 04:29
Domain deletion script - Removes all dns zones on an account
<?php
$single_use = true;
if ($single_use) {
if(!isset($_SERVER['argv'][1]) || !isset($_SERVER['argv'][2])){
die("single_use is set, please supply API Username and Key");
}
require_once('SoftLayer/SoapClient.class.php');
$apiUsername = $argv[1];
$apiKey = $argv[2];
@ryanrhanson
ryanrhanson / virtdisks.php
Last active December 18, 2015 00:38
Grabbing virtual block device and disk image info for cloud instances
<?php
// This relies on the Softlayer PHP API Client, available at https://github.com/softlayer/softlayer-api-php-client.
// Please make sure you have set this up before running the script. To run this, just drop it in the same directory
// as the "SoftLayer" folder and run 'php virtdisks.php' from the terminal. It will prompt for three things:
// API User - This is your SL Username
// API Key - Available at https://manage.softlayer.com/Administrative/apiKeychain or https://control.softlayer.com/account/user/profile/
// Cloud Instance - The CCI Id, found by clicking on the CCI at https://manage.softlayer.com/CloudLayer/computing and examining the "viewinstance" url of the next page.
// This script will grab all block devices for the given CCI, then loop through them to grab further information, such as disk image capacity and so on.
<?php
// This relies on the Softlayer PHP API Client, available at https://github.com/softlayer/softlayer-api-php-client.
// Please make sure you have set this up before running the script. To run this, just drop it in the same directory
// as the "SoftLayer" folder and run 'php virtdisks.php' from the terminal. It will prompt for three things:
// API User - This is your SL Username
// API Key - Available at https://manage.softlayer.com/Administrative/apiKeychain or https://control.softlayer.com/account/user/profile/
// apiconfig.php needs to have apiUsername, apiKey, and the path to the SLApi file that used to be in this script.
require_once('configuration/apiconfig.php');
@ryanrhanson
ryanrhanson / dns_bulkAddARecords.php
Created June 18, 2013 03:49
Add A records in bulk to a dns zone.
<?php
/*
This relies on the Softlayer PHP API Client, available at https://github.com/softlayer/softlayer-api-php-client.
Please make sure you have set this up before running the script. To run this, just drop it in the same directory as the "SoftLayer" folder and run 'php dns_bulkAddARecords.php' from the terminal. It will prompt for three things:
API User - This is your SL Username
API Key - Available at https://manage.softlayer.com/Administrative/apiKeychain or https://control.softlayer.com/account/user/profile/
Domain name - Domain to modify
File name - File to read from, with following format:
$host $target
@ryanrhanson
ryanrhanson / cancelsubnet.php
Created October 22, 2013 17:46
Cancel Subnet by IP
<?php
// Grab an IP address
$ip = readline("IP: ");
require_once dirname(__FILE__) . '/SoftLayer/SoapClient.class.php';
$apiUsername = 'set me';
$apiKey = 'set me too';
@ryanrhanson
ryanrhanson / last5logins.py
Last active December 29, 2015 17:49
Due to an Internal Server Error with http://sldn.softlayer.com/reference/services/SoftLayer_User_Customer/getLoginAttempts and http://sldn.softlayer.com/reference/services/SoftLayer_Account/getUsers, this is a temporary workaround to grab the last 5 login attempts for each portal user.
#Last 5 login attempts for User1
#- Successful login from 123.45.67.89 at 2013-11-28T15:29:32-06:00
#- Failed login from 123.45.67.89 at 2013-11-28T15:29:23-06:00
#- Failed login from 123.45.67.89 at 2013-11-28T15:29:22-06:00
#- Successful login from 123.45.67.89 at 2013-11-27T15:13:49-06:00
#- Successful login from 123.45.67.89 at 2013-11-26T08:35:12-06:00
#
#Last 5 login attempts for User2
#- Successful login from 123.45.67.89 at 2013-11-16T04:51:42-06:00
#- Successful login from 123.45.67.89 at 2013-11-16T04:50:29-06:00
@ryanrhanson
ryanrhanson / images.rb
Last active January 1, 2016 09:19
Lists all instances on an account, prompts you to enter an ID for one of them. Creates an image template from this instance, and loops through all templates on an account until it finds one with a matching transaction id.
require './api.rb'
require 'date'
slapi = AuthApi.new
#api.rb and slapi are used in another file to handle my connection to the SoftLayer API.
#Feel free to include that information in this file if you wish.
begin
@ryanrhanson
ryanrhanson / osreferencecodes.php
Last active January 4, 2016 20:59
Lists out all operating system reference codes available for ccis.
<?php
// apiconfig.php needs to have apiUsername, apiKey, and the path to the SLApi file that used to be in this script.
require_once('configuration/apiconfig.php');
$guestClient = SoftLayer_SoapClient::getClient('SoftLayer_Virtual_Guest', null, $apiUsername, $apiKey);
$objectMask = new SoftLayer_ObjectMask();
$objectMask->operatingSystems->itemPrice;