Author Archive
API Addition - Backbone Graphs
(This post refers to SoftLayer API version 1. Check out API version 3 for our latest updates.)
Due to popular demand, we rolled out a change today which allows querying of our backbone connection graphs. For the uninitiated, backbone graphs show the network usage between the SoftLayer datacenter and the Internet. This functionality was accomplished by adding two new methods to the SoftLayer API.
getBackboneList
Retrieves an array of id and name pairs for all SoftLayer’s Backbone providers
getBackboneImage(intBackboneId)
Retrieves a PNG image for display or local storage
Both of the methods are available via the SOAP and XML-RPC interfaces. We will be updating the documentation and examples for these methods and a few other additions (Top Secret) over the next few weeks.
1 commentQuick example
We are ushering in a new era at SoftLayer with the release of the SoftLayer API. The API opens endless possibilities for our customers to integrate SoftLayer specific functionality into their corporate infrastructure and / or software products. With the API, you can provide datacenter specific control for your server or custom management of SoftLayer services to your customer base. For server resellers, this allows unbranded SoftLayer functionality to their customers via integration into their current customer portal. The API utilizes SOAP or XML-RPC for a communication protocol, by using a non-language specific protocol like SOAP or XML-RPC integration can be made with most current programming languages.
With the growing adoption of PHP on the web, I am going to show you a quick example utilizing PHP 5 with SOAP support enabled. For this example, we are going to pull the list of servers associated with an account and format the results into an html table. This should provide a brief overview to how easy integration into a system utilizing PHP could be.
Let start by defining a few variables we will use which are commented below:
<?php
// Enables or disables the WSDL caching feature
ini_set(“soap.wsdl_cache_enabled”, “0″);
// Your API Access key, that you generated in the customer portal
define(‘AUTH_KEY’,
‘000000000000000000000000000000000000000000000000000′);
// Your Customer Portal Username
define(‘AUTH_USER’,‘SL00000′);
// Where our SOAP server is located
define(‘SOAP_SERVER_LOCATION ’,
‘https://api.service.softlayer.com/soap/v1/SL-Service.html’);
?>
Our first step after setting our configuration options is to create the SOAP client connection:
<?php
$client = new SoapClient(null, array(‘location’ => SOAP_SERVER_LOCATION,
‘uri’ => SOAP_SERVER_LOCATION) );
?>
Next we will setup a few variables to be used with a try / catch statement. The try / catch statement will perform the call to the SOAP server:
<?php
# Did our SOAP call complete?
$bolResult = false;
# What was the returned error message
$strErrorMessage = “”;
# Lets store our results in an array
$arrResult = array();
try {
$arrResult = $client->__call(“getServerList”, array() ,null ,
new SoapHeader(‘myUrn’, ‘authenticate’,
array(AUTH_USER, AUTH_KEY) ) );
$bolResult = true
} catch( SoapFault $e ) {
$strErrorMessage = $e->getMessage();
}
?>
You might have noticed that we created a SOAP header that was placed in the call. This was used to pass the login credentials for authentication on the server.
At this point, there should be a response or an error message. Next we will do some basic formatting for the web to show the results.
<?php
if($bolResult){
echo ‘<table cellpadding=”2″>’.“\n”;
if(count($arrResult)){
foreach($arrResult as $arrServer){
echo ‘<tr>’;
echo ‘<td>’.$arrServer['ID'].‘</td>’;
echo ‘<td>’.$arrServer['SERVERNAME'].‘</td>’;
echo ‘<td>’.$arrServer['PUBLIC_IP_ADDRESS'].‘</td>’;
echo ‘<td>’.$arrServer['PRIVATE_IP_ADDRESS'].‘</td>’;
echo ‘<td>’.$arrServer['MGMT_IP_ADDRESS'].‘</td>’;
echo “</tr>\n”;
}
} else {
echo “<tr><td>No Servers Found!</td></tr>”;
}
echo “</table>\n”;
}else{
echo “There was an error with your SOAP call<br>\n”;
echo “Error Response:<br>\n”;
echo $strErrorMessage.“<br>\n”;
}
echo “Done!<br>\n”;
?>
This sums up how to make a request using PHP 5 with SOAP support enabled. Using the SOAP or XML-RPC protocol make the API easy to integrate into most languages, but makes it difficult to cover every language in an example. For that reason, I have included some raw SOAP requests below. If you can send a RAW HTTP POST request to our SOAP server in the format below, chances are your language can integrate into the SoftLayer API.
Example SOAP Request (no parameters)
<?xml version=”1.0″ encoding=”UTF-8″?>
<SOAP-ENV:Envelope
xmlns:xsi=”http://www.w3.org/1999/XMLSchema-instance”
xmlns:SOAP-ENV=”http://schemas.xmlsoap.org/soap/envelope/”
xmlns:ns1=”http://schemas.xmlsoap.org/soap/encoding/”
xmlns:xsd=”http://www.w3.org/1999/XMLSchema”
SOAP-ENV:encodingStyle=”http://schemas.xmlsoap.org/soap/encoding/”>
<SOAP-ENV:Header>
<ns2:authenticate>
<xsd:string>SL00000</xsd:string>
<xsd:string>0000000</xsd:string>
</ns2:authenticate>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<ns1:getServerList/>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Example SOAP Request (with parameters)
<?xml version=”1.0″ encoding=”UTF-8″?>
<SOAP-ENV:Envelope
xmlns:xsi=”http://www.w3.org/1999/XMLSchema-instance”
xmlns:SOAP-ENV=”http://schemas.xmlsoap.org/soap/envelope/”
xmlns:ns1=”http://schemas.xmlsoap.org/soap/encoding/”
xmlns:xsd=”http://www.w3.org/1999/XMLSchema”
SOAP-ENV:encodingStyle=”http://schemas.xmlsoap.org/soap/encoding/”>
<SOAP-ENV:Header>
<ns2:authenticate>
<xsd:string>SL00000</xsd:string>
<xsd:string>0000000</xsd:string>
</ns2:authenticate>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<namesp1:getServerSoftwareDetails xmlns:namesp1=”ns1″>
<param0 xsi:type=”xsd:int”>0000</param0>
</namesp1:getServerSoftwareDetails>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Additional Resources:
http://www.php.net/manual/en/ref.soap.php
http://en.wikipedia.org/wiki/SOAP
http://www.xmlrpc.com/