Archive for the 'Implementations' Category
Dot Net? You Bet!
Greetings fellow SLAPI enthusiasts! When the call went out for examples I figured why not cowboy up and try my hand at with a .NET example. After all, being an MCP in a largely PHP shop makes me as qualified as anyone. Plus I am constantly pushing the Microsoft Kool-Aid around the office so this was a chance to put my money where my mouth is.
Unfortunately, there was just one catch—I’m not a .NET programmer. I’ve got 10 years of experience writing drivers, protocol suites, and firmware. In other words, C/C++ with a little bit of assembler thrown in when push comes to shove. Sure I can write a c-sharp application, but I’m pretty green at it and until a month ago if someone had told me they had a problem with their WSDL (pronounced wiz’duhl) I would have wondered why they were telling me instead of their urologist!
That said, what follows is a pretty basic SLAPI example, done in both C# and VB.NET (because I’m ambi-dot-dextrous). Don’t expect anything more than a DOS-style command console for the UI. I’m used to letting the Microsoft’s control panel give the user any feedback and usually consider my code to be ready to ship if it can run for 24 hours without blue-screening the box!
My chops are on display at the SLDN API Wiki. Let me know what you think!
No commentsPerls of Wisdom
It’s been a little over a week since our API launch. I haven’t heard from anyone who doesn’t like it, so that must mean we’re doing it right. We’ve been spending time lately catching up on little quirks and documentation bugs. Our first example is up. Its for you Perl jockeys, and really exemplifies the flexibility and power of object masks in your API handling code. We’ve got a .NET one coming up soon. You guys are going to love how easy it is to use this in Visual Studio. We’ve got plans for PHP and Java coming up too. If there’s a language or implementation you want to see please let us know!
In other news, SoftLayer has recently launched a shiny new Facebook group. Sign in and join up to talk with us and get your hands-on exclusive content (which currently is videos of me rambling about the API). As always, we’re here if you have questions, concerns, or just want to chat. See you next time!
No commentsTime for some morning Java
(This post refers to SoftLayer API version 1. Check out API version 3 for our latest updates.)
We’ve put a Java SOAP example up on our downloads page. This was written in Eclipse 3.2.2, and for your convenience the example package contains our Eclipse project files. The code should run on JVM version 1.4 and above. We’d love to hear your feedback on this example. Reply here or post on our forums and let us know what you think. See ya’ll later!
No commentsAPI Hacking Fun With Python
(This post refers to SoftLayer API version 1. Check out API version 3 for our latest updates.)
Hello! I’m Shawn, one of new “Code Writing Professionals” at SoftLayer. When a call went out for examples using SoftLayer’s new API, I immediately signed up to write the INTERCAL, Prolog, and Apollo Guidance Computer modules. I was told to make those low priority projects, and to perhaps focus on hacking with Python instead. If you just want to see the finished code without all the Python evangelization, skip to the end of the post. For those of you who haven’t hacked with Python yet, follow along for the ride!
In case you don’t know, Python is an incredibly simple and clean looking programming language. Many people have picked it up in just a few minutes! If you already program in another programming language (like C, Java, PHP, SH, or Perl (shiver)), Python may look a bit strange. But it’s not too strange at all. In fact, the only “strange” bits in Python are it’s reliance on whitespace (you have to line up your code) and the lack of braces.
Any good FORTRAN coder will tell you that whitespace is good.
If you run a flavor of UNIX, Linux, or BSD, you most likely have Python already installed. If you are running Windows or if your distribution doesn’t come with a recent Python package installed you will need to install Python. You Linux guys can install it with your favorite package manager (it’s usually named python). Windows users (or UNIX haxxors who prefer tarballs), pick up the latest version of Python from ActiveState. (You will also want to check out ActiveState’s free(!) Komodo Edit)
Install Python and we are ready to go!
Open up a UNIX Terminal or the Windows command line (Start->Run… type CMD {enter}), then type “python”. This boots up the Interactive Python Interpreter. One of the cool things about Python is that you can whip up a Python Interpreter and just start typing in program fragments. It’s like the “immediate” mode in QBASIC for DOS, but neater. You should see something like this:
![]()
The first step is to import the XML-RPC library for Python. In keeping with Python’s “Batteries Included” approach, the most useful libraries come standard with any complete download of the Python interpreter, and this includes the standard XML-RPC library. To do this, type:
import xmlrpclib
Now Python has all the functionality needed to make and receive XML-RPC calls loaded into the interpreter. Let’s set up some variables to make hacking with the library much easier. In the interpreter, type:
url = "http://api.service.softlayer.com/xmlrpc/v1/SL-Service.html"
key = "YOUR SOFTLAYER API KEY"
usr = "YOUR SOFTLAYER API USERNAME"
Now we need to set up a Server Proxy. This is an object that we can make method calls against that does all the dirty work of compiling the XML and parsing the data… all the boring stuff. Using the proxy we get to make XML-RPC calls as if all the work was being done on the local machine. This is easy to do. Type this into the interpreter:
server = xmlrpclib.ServerProxy(url)
Now you have your proxy. If you print out the server variable (print server) you will see that server is an instance of the ServerProxy class made to communicate with the SoftLayer XML-RPC server. Now, let’s actually do something!
serverList = server.getServerList(key, usr)
This invokes the XML-RPC getServerList method, which retrieves your list of servers and stashes it into serverList. Let’s see what you got:
print serverList
The data is returned as a LIST of DICTIONARIES, with one DICTIONARY per server. Let’s loop through this list and display the servername of all your servers:
for thisServer in serverList:
print thisServer["SERVERNAME"]
The two space indentation at the beginning of the second line are required or else the code won’t work. Hit enter twice, and Python will print out the Servername (hostname + domain name) for all servers in your account. You can pull more data out of the dictionary easily:
for thisServer in serverList:
print thisServer["SERVERNAME"], thisServer["PUBLIC_IP_ADDRESS"]
You can make all the method calls listed in the SoftLayer API Documentation by calling them as methods of the server class:
server.getBandwidthList(key, usr, "192.168.1.1")
server.getServerNetworkDetails(key, usr, "192.168.1.1")
server.rebootServer(key, usr, "192.168.1.1", "Soft Reboot")
Python is easy to pick up and play with, and with it’s XML-RPC library, it’s probably the fastest way for people to hack with the SoftLayer API. The complete code listing to display all your servernames is below:
# Quickie Python XML-RPC Demo for the SoftLayer API
# Written by Shawn Boles, SoftLayer Development
# API Connection Details
url = "http://api.service.softlayer.com/xmlrpc/v1/SL-Service.html"
key = "PUT YOUR SOFTLAYER API KEY HERE..."
usr = "PUT YOUR API USERNAME HERE..."
# This is the XML-RPC Library for Python. It comes standard!
import xmlrpclib
# Set up the proxy object for the SoftLayer server. You can make
# calls against this object as if the processing is local.
server = xmlrpclib.ServerProxy(url)
# Make a method call on getServerList from the API.
# Don't forget to pass the key and usr variables as the first
# two parameters, in that order!
serverList = server.getServerList(key, usr)
# Loop through all servers, displaying their servernames.
for myserver in serverList:
print myserver["SERVERNAME"]
Only 8 lines of code, ignoring comments and empty lines. Hacking indeed! When a new API method comes out you can pop open a command line and slap together a test case in a minute or two to try it out!
Extra Credit: Let’s do something a little more useful with our new |33+ Python API Hacking Skilz:
# Display all my servers and IP addresses, using the SoftLayer API
# Written by Shawn Boles, SoftLayer Development
# API Connection Details
url = "http://api.service.softlayer.com/xmlrpc/v1/SL-Service.html"
key = "PUT YOUR SOFTLAYER API KEY HERE..."
usr = "PUT YOUR API USERNAME HERE..."
# This is the XML-RPC Library for Python. It comes standard!
import xmlrpclib
# Set up the proxy object for the SoftLayer server. You can make
# calls against this object as if the processing is local.
server = xmlrpclib.ServerProxy(url)
# Make a method call on getServerList from the API.
# Don't forget to pass the key and usr variables as the first
# two parameters, in that order!
serverList = server.getServerList(key, usr)
# Loop through all servers, displaying their servernames.
for myserver in serverList:
# Get the list of Server Details from the API for each server:
serverDetail = server.getServerDetails(key, usr, myserver["ID"])
# "Unfold" the Server Details data structure and give us access
# to only the IP information...
prettyServerDetail = serverDetail[2][0]
try:
print myserver["SERVERNAME"], \
"\n\tPublic IP:", prettyServerDetail["PRIMARY_PUBLIC_IP"], \
"(", prettyServerDetail["PUBLIC_PORT_SPEED"], "),", \
"\n\tPrivate IP:", prettyServerDetail["PRIMARY_PRIVATE_IP"], \
"(", prettyServerDetail["PRIVATE_PORT_SPEED"], "),", \
"\n\tManage IP:", prettyServerDetail["MGMT_IP"], "\n"
except KeyError:
print "NONE\n"
pass
Here’s a direct link to the sample file for your editing pleasure.
In no time at all you will be hacking apps for your API no sweat! And you aren’t locked down to command line tools, either. Python comes with just about every GUI kit, can be used to make your own Python-powered control panel…
Have fun hacking!
No commentsLet’s get this party started.
(This post refers to SoftLayer API version 1. Check out API version 3 for our latest updates.)
Howdy, everyone. The SoftLayer dev team has been growing a bit lately to handle new portal additions and adding fancy new methods to the API for ya’ll. So far we’ve gotten some great feedback on the API and how to make our application servers work better for you and your businesses. Now that we’ve got the API out and some extra head count what say we kick into high gear?
Here’s our game plan. We know how smart our customers are. We know how they think (we hope). They’re geeks who find perverse joy in taking things apart, reassembling them, and building cool new toys out of the leftover parts. We want you to give that a try with our API. Our Implementations Forum has a good start, but we’re looking for something to really knock our socks off. So far the coolest thing we’ve seen is a Yahoo! widget. Who can top that?
Email us, post to the forum, or leave a comment here with sweet implementation goodness. Surprise us. Show us what wacky stuff you can do with your server and our API. If you don’t code then that’s fine. Send us your ideas. Maybe someone will pick up on it. To get the ball rolling we’ll write an app or two of our own. Even better we’ll release the source of our app to get ya’ll started. Let’s see what kind of cool programs we can write.
2 commentsShow off your project
Everyone at SoftLayer is excited about the API. But we can’t wait to see what our customers are going to be doing with it. You can go to the implementations page to see some examples of ways to use the API. What we would really like to put on that page is a list of applications developed by our customers. If you create a use for the API that is new and unique, or if you just want to show the world how cool you are - send us an email at sldn@softlayer.com and tell us about it and we will feature your project on the implementation page.
No commentsQuick 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/