IBM SoftLayer Melbourne PoD open!

Image courtesy of http://www.computerworld.com.au/slideshow/556788/pictures-ibm-softlayer-melbourne-data-centre/
Image courtesy of http://www.computerworld.com.au/slideshow/556788/pictures-ibm-softlayer-melbourne-data-centre/

As per the press release, IBM SoftLayer Melbourne is open for business as of Tuesday 7th October 2014!

Using the SoftLayer API we can create a very short Python script to buildĀ a new virtual Ubuntu image in the new Melbourne SoftLayer datacenter. Before you begin you need a SoftLayer account and your API key which you can find under Account | Users then click on View to see your API key.

To create a virtual image you simply call the SoftLayer_Virtual_Guest::createObject API.

The parameters for this call are fairly self explanatory – with the exception of datacenter.name. How do you know what the datacenter name for Melbourne is? (without going to the customer portal that is!)

locations_api

The answer: simply call the SoftLayer_Location::getDatacenters API. For simplicity I do this via the HTTP REST API using curl, with some python json post processing to make it easy to read:

$ curl -s https://SLxxxx:API_KEY@api.softlayer.com/rest/v3/SoftLayer_Location/getDatacenters.json | python -m json.tool

An array of locations will scroll up the screen – but the important one is Melbourne:

{
"id": 449596,
"longName": "Melbourne 1",
"name": "mel01"
},

There is the magic short name – mel01.

With that information we can now create the short script to provision the guest:

import SoftLayer

client = SoftLayer.Client(username='SLxxxx', api_key='API_KEY')
client_object = client['Virtual_Guest'].createObject({
'hostname': 'test',
'domain': 'myhost.com',
'startCpus': 1,
'maxMemory': 1024,
'hourlyBillingFlag': 'true',
'operatingSystemReferenceCode': 'UBUNTU_LATEST',
"datacenter": {
"name": "mel01"
},
'localDiskFlag': 'false'
});

for key, value in client_object.iteritems():
	print key, " -> ", value

Save the file as test_build_melbourne.py.

Before you can execute it, ensure you have the python Softlayer Library installed. See https://pypi.python.org/pypi/SoftLayer for instructions.

When you are ready – give it a whirl:

$ python test_build_melbourne.py

It will sit there for a moment then return some values about the new virtual guest, then will continue executing in the background.
By using the SoftLayer sl command line interface (CLI) to the API, you can see the progress of your virtual build and find out when it is ready. Ensure you setup your sl CLI following these instructions.

provision-1

Then after a few minutes:

provision-2

After that, you can grab your root password from the password repository in the portal. You can find your passwords under Devices | Manage | Passwords:

portal_password

Your host should be listed, and just click on the password field:

portal_root_password

Side note: you can also use the API to get at your passwords:

curl 'https://SLXXXX:APT_KEY@api.softlayer.com/rest/v3/SoftLayer_Account/getVirtualGuests.json?objectMask=mask\[softwareComponents\[passwords\]\]' | python -m json.tool

Armed with your root password, you can ssh in:

$ ssh root@168.1.xxx.yyy
Password:
Welcome to Ubuntu 14.04.1 LTS (GNU/Linux 3.13.0-35-generic x86_64)

* Documentation: https://help.ubuntu.com/
Last login: Tue Oct 7 06:48:35 2014 from
root@test:~#

If your ssh session is slow to respond while you are trying to login, add the following line to your /etc/ssh/sshd_config file and reboot:

UseDNS no

From my Melbourne location, the pings are nice and quick as they should be:

$ ping 168.1.xxx.yyy
PING 168.1.xxx.yyy (168.1.xxx.yyy): 56 data bytes
64 bytes from 168.1.xxx.yyy: icmp_seq=0 ttl=55 time=9.301 ms
64 bytes from 168.1.xxx.yyy: icmp_seq=1 ttl=55 time=8.006 ms
64 bytes from 168.1.xxx.yyy: icmp_seq=2 ttl=55 time=7.800 ms

If you are finished for now – you can cancel your virtual guest – as you can create a new one whenever you need it using your python script.

To cancel:

sl vs cancel 6461446

For a couple of hours work, how much will this cost me?

$ curl -s https://SLxxxxxx:API_KEY@api.softlayer.com/rest/v3/SoftLayer_Account/getBalance.xml

.04

A grand total of $US0.04 cents.

There you have it. A very quick “getting started” tutorial for creating a virtual image via three different ways of using the API (REST, CLI and Python).

Advertisements