Skip to content

Instantly share code, notes, and snippets.

@softlayer
Created July 1, 2010 00:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save softlayer/459389 to your computer and use it in GitHub Desktop.
Save softlayer/459389 to your computer and use it in GitHub Desktop.
<?php
/**
* Print a report containing a single server's details.
*
* Print a report for a single server containing:
*
* - id number
* - hostname
* - domain
* - notes
* - the datacenter the server is located in
* - the server's monthly cost
* - inbound and outbound bandwidth usage for the current billing cycle
* - IP addresses
* - network port speeds
* - a list of the server's hardware components.
*
* These properties are all local or relational to the
* SoftLayer_Hardware_Server data type and can be retrieved with a single API
* call. See below for more details.
*
* This assumes the SoftLayer API PHP client
* <http://github.com/softlayer/softlayer-api-php-client> is installed in the
* directory '/SoftLayer' in this script's path and that you wish to use the
* SOAP client instead of our XML-RPC client.
*
* @see http://sldn.softlayer.com/reference/datatypes/SoftLayer_Hardware_Server
* @see http://sldn.softlayer.com/reference/services/SoftLayer_Hardware_Server/getObject
* @license <http://sldn.softlayer.com/article/License>
* @author SoftLayer Technologies, Inc. <sldn@softlayer.com>
*/
// Include XmlrpcClient.class.php if you'd like to use our XML-RPC client
// instead.
require_once(dirname(__FILE__) . '/SoftLayer/SoapClient.class.php');
/**
* Your SoftLayer API username and key.
*
* Generate an API key at the SoftLayer Customer Portal:
* https://manage.softlayer.com/Administrative/apiKeychain
*/
$apiUsername = 'set me!';
$apiKey = 'set me too!';
/**
* The id of the server we wish to edit.
*
* Call the getHardware() method from the SoftLayer_Hardware API service to get
* a list of hardware on your account, including id numbers.
*
* @var int
*/
$serverId = 1234;
// Make a connection to the SoftLayer_Hardware_Server service.
$client = SoftLayer_SoapClient::getClient('SoftLayer_Hardware_Server', $serverId, $apiUsername, $apiKey);
/**
* Retrieve related server information.
*
* Every property we need for our report is a relational property to the
* SoftLayer_Hardware_Server data type and can be retrieved in an object mask.
*
* @var SoftLayer_ObjectMask
*/
$objectMask = new SoftLayer_ObjectMask();
$objectMask->cost;
$objectMask->datacenter;
$objectMask->components->hardwareComponentModel->hardwareGenericComponentModel->hardwareComponentType;
$objectMask->networkComponents;
$objectMask->inboundPublicBandwidthUsage;
$objectMask->outboundPublicBandwidthUsage;
$client->setObjectMask($objectMask);
// Get our server record from the SoftLayer API.
try {
$server = $client->getObject();
} catch (Exception $e) {
die('Unable to retrieve server cost: ' . $e->getMessage());
}
// Print general server information first.
echo <<<EOT
Details for server {$server->id}:
Hostname: {$server->hostname}
Domain: {$server->domain}
Notes: {$server->notes}
Monthly Cost: \${$server->cost}
Datacenter: {$server->datacenter->longName}
Inbound Public Bandwidth Usage: {$server->inboundPublicBandwidthUsage} GB
Outbound Public Bandwidth Usage: {$server->outboundPublicBandwidthUsage} GB
EOT;
// Print network port speeds and primary IP addresses.
foreach ($server->networkComponents as $component) {
// Remote management card IP addresses are stored in the ipmiIpAddress
// property.
$ipAddress = ($component->name == 'mgmt') ? $component->ipmiIpAddress : $component->primaryIpAddress;
print <<<EOT
Port {$component->name}{$component->port} IP: {$ipAddress}
Port {$component->name}{$component->port} Speed: {$component->speed}mbps
EOT;
}
// Print out the server's hardware components.
foreach ($server->components as $component) {
print <<<EOT
{$component->hardwareComponentModel->hardwareGenericComponentModel->hardwareComponentType->type}: {$component->hardwareComponentModel->hardwareGenericComponentModel->capacity} {$component->hardwareComponentModel->hardwareGenericComponentModel->units} {$component->hardwareComponentModel->manufacturer} {$component->hardwareComponentModel->name}
EOT;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment