Created
June 26, 2012 20:37
-
-
Save softlayer/2998774 to your computer and use it in GitHub Desktop.
Retrieve Passwords for all servers...print in a table
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once('SoftLayer/SoapClient.class.php'); | |
/** | |
* Set your SoftLayer API username and key. | |
*/ | |
$apiUsername = 'USER HERE'; | |
$apiKey = 'KEY HERE'; | |
// Create a API client for the SoftLayer_Account service | |
$client = SoftLayer_SoapClient::getClient('SoftLayer_Account', null, $apiUsername, $apiKey); | |
/** | |
* Create an object mask to pull in information which is not normally included by the function we are calling(getHardware). | |
* We want to pull in the ip address, and the password information for each server returned by getHardware() | |
*/ | |
$mask = new SoftLayer_ObjectMask; | |
$mask->hardware->operatingSystem->passwords; | |
$mask->hardware->primaryIpAddress; | |
$client->setObjectMask($mask); | |
try { | |
// Pull in the hardware information | |
$result = $client->getHardware(); | |
$passwords = array(); | |
print('<table>'); | |
foreach ($result as $server) { | |
// if it dosent have an OS or OS->passwords, it is probably not a server | |
if (!isset($server->operatingSystem) || !isset($server->operatingSystem->passwords)) | |
continue; | |
// Make a quick and dirty table of the information we need | |
print(sprintf('<tr><td><a href="https://manage.softlayer.com/Hardware/view/%s">%s</a></td><td>%s</td><td> %s:%s</td></tr>', | |
$server->id, $server->hostname, $server->primaryIpAddress, $server->operatingSystem->passwords[0]->username, | |
$server->operatingSystem->passwords[0]->password)); | |
} | |
print('</table>'); | |
} catch ( Exception $e) { | |
die( $e->getMessage()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment