Skip to content

Instantly share code, notes, and snippets.

@ryanrhanson
Last active December 18, 2015 00:38
Show Gist options
  • Save ryanrhanson/5697607 to your computer and use it in GitHub Desktop.
Save ryanrhanson/5697607 to your computer and use it in GitHub Desktop.
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.
$single_use = true;
if ($single_use) {
require_once('SoftLayer/SoapClient.class.php');
$apiUsername = readline("API User: ");
$apiKey = readline("API Key: ");
$cci = readline("Cloud Instance: ");
}
else {
require_once('configuration/apiconfig.php');
}
$client = SoftLayer_SoapClient::getClient('SoftLayer_Virtual_Guest', $cci, $apiUsername, $apiKey);
$virtinfo = $client->getBlockDevices();
foreach ($virtinfo as $diskimages){
$client2 = SoftLayer_SoapClient::getClient('SoftLayer_Virtual_Disk_Image', $diskimages->diskImageId, $apiUsername, $apiKey);
$imageinfo = $client2->getObject();
echo "VBD ID: " . $diskimages->id . "\n\r";
echo "VBD UUID: " . $diskimages->uuid . "\n\r";
echo "VDI ID: " . $imageinfo->id . "\n\r";
echo "VDI ID: " . $imageinfo->uuid . "\n\r";
echo "Capacity: " . $imageinfo->capacity . $imageinfo->units . "\n\r";
echo "Name: " . $imageinfo->name . "\n\r";
echo "Description: " . $imageinfo->description . "\n\r";
echo "Bootable?: " . $diskimages->bootableFlag . "\n\r";
echo "Storage Repo: " . $imageinfo->storageRepositoryId . "\n\r";
echo "Device #: " . $diskimages->device . "\n\r";
echo "Guest ID: " . $diskimages->guestId . "\n\r";
echo "=-=-=-=-=-=\n\r";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment