Ubuntu has just released their latest LTS, 10.4 “Lucid Lynx” today, and immediately Linode made it as an available distribution for deployment. Definitely kudos to team Linode there. I have actually been holding onto creating a new VPS (to run git + back trackers for some of my projects) because of pending release of Ubuntu 10.04 LTS. There is nothing stopping me now :)

Well. I am doing it a bit differently today, and decided to do it via API. I went with Ataraxia Consulting’s Python binding as it’s a language I am fluent in. These are the steps that I took.

Downloading Python Binding

The Python binding is hosted with git so I basically just clone it. It comes with a nice shell.py that initialises and turns it into a Python shell with tab completion. You will also need your API Key ready, which can be found on your Linode profile page (generate one if it does not yet exist).

$ git clone http://git.atxconsulting.com/linode
Initialized empty Git repository in linode/.git/
got 7424e15c260d1150025e9909a23bfce698e6c592
$ cd linode/
$ ./shell.py
Enter API Key: (enter in your Linode API key here)
Python 2.6.4 (r264:75706, Apr 27 2010, 11:22:46)
[GCC 4.3.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.

Okay. Let’s get rocking!

Creating New Linode

What I am trying to do is to create a new Linode 360 in their Dallas location (always check Linode’s availability though, although available Linodes have been abundant lately). Since I am keeping it long term, I want to prepay for 12 months. So the API I really want to call is linode.create. Under the shell I will get the data centre ID and plan ID via API.

>>> [dc['DATACENTERID'] for dc in linode.avail_datacenters()
...   if 'Dallas' in dc['LOCATION']]
>>> [p['PLANID'] for p in linode.avail_linodeplans() if '360' in p['LABEL']]
>>> linode.linode_create(DatacenterID=2, PlanID=1, PaymentTerm=12)
{u'LinodeID': 12345}

Then to rename it to something else (instead of linode12345).

>>> linode.linode_update(LinodeID=12345, Label='MyNewVPS')
{u'LinodeID': 12345}

Creating Disks

I can’t seem to be able to find an API equivalent to the Deploy a Linux Distribution functionality on the control panel, so I guess I have to go through the long way by creating disks, creating configs, etc before I can boot the Linode. I want to create a Linode with 256MB of swap, and then everything else goes into one partition. I also need to find out the Distribution ID for the 32bit Ubuntu 10.04.

>>> [d['DISTRIBUTIONID'] for d in linode.avail_distributions()
... if ('Ubuntu 10.04' in d['LABEL']) and (not d['IS64BIT'])]
>>> linode.linode_disk_createfromdistribution(
...   LinodeID=12345, DistributionID=64, Label='Root Partition',
...   Size=(16384-256), rootPass='passw0rd', 
...   rootSSHKey=open('../.ssh/id_dsa.pub').read())
{u'DiskID': 12345, u'JobID': 12345}
>>> linode.linode_disk_create(LinodeID=47347, Label='Swap Partition',
...   Type='swap', Size=256)
{u'DiskID': 54321, u'JobID': 54321}

You have to note down the actual DiskID because we will need them later when we create the config. Also note that I am using a random password + my SSH public key when I set up the root partition.

Create Config

The next task is to create a boot configuration, which needs to include (1) the kernel to boot with (2) the disk arrangement. We need to use the latest 32bit paravirt kernel.

>>> [_['KERNELID'] for _ in linode.avail_kernels()
... if ('Latest 2.6 Paravirt' in _['LABEL']) and ('x86_64' not in _['LABEL'])]
>>> linode.linode_config_create(LinodeID=12345, KernelID=110,
... Label='Ubuntu 10.04 Default', DiskList='12345,54321')
{u'ConfigID': 12345}

Now the configuration is done — ready to boot!

Booting the Node

Booting a linode using a existing config is pretty trivial. You would also want to get the IP address of your new Linode so you can SSH in.

>>> linode.linode_boot(LinodeID=12345, ConfigID=12345)
{u'JobID': 54321}
>>> linode.linode_ip_list(LinodeID=12345)[0]['IPADDRESS']

Done! Now log off the Python console, and SSH into your new Ubuntu 10.04 “Lucid Lynx” Linode :)

>>> exit()
$ ssh root@69.164.xxx.yyy
Linux li109-129 #1 SMP Wed Apr 28 19:25:11 UTC 2010 i686 GNU/Linux
Ubuntu 10.04 LTS

Welcome to Ubuntu!
 * Documentation:  https://help.ubuntu.com/

The programs included with the Ubuntu system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
applicable law.


/me pat on my back. Ought to put all that into a single script…