Nubo

Nubo is a command line program that allows you to start virtual machines on different cloud providers, also making sure you can SSH into those instances once they are available.

As an example, you might want to start a new node on Amazon EC2:

$ nubo start EC2_EU_WEST ami-27013f53
Instance i-4ea89004 available on EC2_EU_WEST. Public IP: 54.247.8.150

And then install puppet on it:

$ ssh root@54.247.8.150 "apt-get -y install puppet"
Warning: Permanently added '54.247.8.150' (RSA) to the list of known hosts.
Reading package lists...
Building dependency tree...
Reading state information...
The following extra packages will be installed:
[...]

One of the biggest challenges when deploying virtual machines on multiple clouds is ensuring you can actually access those machines after they have started up. For example, different cloud providers allow you to upload your SSH public key in different ways. Certain providers automatically configure firewall rules which by default deny traffic to your instances. If your deployments need to be automated, your infrastructure code has to deal with that.

nubo abstracts away these differences for you. It uses Apache Libcloud to start virtual machines on different cloud providers and Paramiko to establish SSH connections to the instances you start. Its functionalities are also available as a Python library.

Installation

Install nubo with one of the following commands:

$ pip install nubo

Alternatively, use easy_install:

$ easy_install nubo

Usage

Invoke nubo without arguments to see the available functionalities:

$ nubo
usage: nubo [-h] {config,clouds,list,images,start,reboot,delete} ...

Start Virtual Machines on multiple clouds

positional arguments:
  {config,clouds,list,images,start,reboot,delete}
    config              set your cloud credentials
    clouds              list available clouds
    list                list running VMs
    images              list available images
    start               start a new VM
    reboot              reboot a given VM
    delete              delete a given VM

optional arguments:
  -h, --help            show this help message and exit

Run nubo config to set your cloud credentials. The following examples shows how we can configure one of the available cloud providers:

$ nubo config
 1 DIGITAL_OCEAN
 2 EC2_AP_NORTHEAST
 3 EC2_AP_SOUTHEAST
 4 EC2_AP_SOUTHEAST2
 5 EC2_EU_WEST
 6 EC2_US_EAST
 7 EC2_US_WEST
 8 EC2_US_WEST_OREGON
 9 OPENNEBULA
10 RACKSPACE
11 RACKSPACE_UK
Please choose the cloud provider you want to setup [1-11] 5
Please provide your API key: MYAPIKEY
Please provide your API secret: MYAPISECRET
EC2_EU_WEST cloud configured properly

To see which virtual machine images are available, we can use nubo images:

$ nubo images DIGITAL_OCEAN
20 images available on DIGITAL_OCEAN
 id              name
===============================
85271   wheezy
85431   postgres-base
1607    Gentoo x64
13632   Open Suse 12.1 x32
13863   Open Suse 12.2 X64
18414   Arch Linux 2012-09 x64
23593   Arch Linux 2012-09 x64
63749   Gentoo 2013-1 x64
1601    CentOS 5.8 x64
1602    CentOS 5.8 x32
1609    Ubuntu 11.10 x32 Server
1611    CentOS 6.2 x64
1615    Fedora 16 x64 Server
1618    Fedora 16 x64 Desktop
2676    Ubuntu 12.04 x64 Server
12573   Debian 6.0 x64
12574   CentOS 6.3 x64
12575   Debian 6.0 x32
12578   CentOS 6.3 x32
14097   Ubuntu 10.04 x64 Server

New virtual machine instances can be started with nubo start. Note that the command will not return until the remote machine has finished booting up and it accepts SSH connections:

$ nubo start DIGITAL_OCEAN 12573
Instance 150843 available on DIGITAL_OCEAN. Public IP: 198.199.72.211

With nubo list we can see the status of our virtual machines on a given cloud provider:

$ nubo list DIGITAL_OCEAN
1 VMs running on DIGITAL_OCEAN
  id     name    state          ip
========================================
150843   test   RUNNING   198.199.72.211

API Reference

All nubo functionalities can be accessed via its Python API. Here is a brief example of how to deploy a new virtual machine:

from nubo.clouds.base import get_cloud

Cloud = get_cloud('EC2_EU_WEST')
ec2 = Cloud()

print ec2.deploy(image_id='ami-27013f53', name='my-new-vm')

Please refer to the following API documentation for further details.

nubo.clouds.base

Support deployments on multiple cloud providers.

copyright:
  1. 2013 by Emanuele Rocca.
nubo.clouds.base.get_cloud(cloud_name)

Return a class representing the given cloud provider.

eg: get_cloud(cloud_name=’EC2_US_WEST_OREGON’)
-> <class ‘nubo.clouds.ec2.AmazonEC2’>
nubo.clouds.base.node2dict(node)

Convert a node object into a dict

class nubo.clouds.base.BaseCloud(ssh_private_key=None, login_as='root')

Bases: object

deploy(image_id, size_idx=0, location_idx=0, name='test')

Deploy a VM instance on this cloud. This method is not implemented here, it has to be specialized by the classes implementing specific cloud providers.

is_running(node_id)

Return True if the given node is running.

list_images(limit=None, keyword='')

Return a list of VM images available on this cloud.

list_nodes()

Return a list of dictionaries representing currently running nodes.

list_sizes()

Return a list of strings representing the available instance size names.

reboot(node_id)

Reboot the given instance id.

eg: reboot(‘i-bb6c3b88’) -> bool

shutdown(node_id)

Shutdown the given instance id.

eg: shutdown(‘i-bb6c3b88’) -> bool

startup(params)

Start a new instance.

Each cloud provider requires different values here.

‘name’, ‘image’, and ‘size’ are the lowest common denominator.

eg: startup(params) -> dict

nubo.clouds.digitalocean

Support deployments on DigitalOcean cloud.

copyright:
  1. 2013 by Emanuele Rocca.
class nubo.clouds.digitalocean.DigitalOcean(ssh_private_key=None, login_as='root')

Bases: nubo.clouds.base.BaseCloud

deploy(image_id, size_idx=0, location_idx=0, name='test')

Digital Ocean needs the following information: VM size, image, name, location and SSH key id.

First, we check if our SSH key is already uploaded on Digital Ocean’s cloud. If not, we upload it using libcloud’s driver.ex_create_ssh_key. Then, we call self.startup with the required arguments.

get_ssh_key_id()

Return uploaded key id if this SSH public key has been already submitted to Digital Ocean. We use libcloud’s driver.ex_list_ssh_keys in order to find it out.

Return None if the SSH key still has to be uploaded.

nubo.clouds.ec2

Support deployments on Amazon EC2.

copyright:
  1. 2013 by Emanuele Rocca.
class nubo.clouds.ec2.AmazonEC2(ssh_private_key=None, login_as='root')

Bases: nubo.clouds.base.BaseCloud

deploy(image_id, size_idx=0, location_idx=0, name='test')

Amazon EC2 needs the following information: VM size, image, name, location, SSH key name and security group name.

First, we check if our SSH key is already uploaded on Amazon’s cloud. If not, we upload it using libcloud’s driver.ex_import_keypair.

Then, we create a permissive Security Group with driver.ex_create_security_group and driver.ex_authorize_security_group_permissive.

Finally, we call self.startup with the required arguments.

get_ssh_key_id()

Return uploaded key id if this SSH public key has been already submitted to Amazon EC2. We use libcloud’s driver.ex_describe_keypairs in order to find it out.

Return None if the SSH key still has to be uploaded.

list_images(limit=20, keyword='')

Amazon also returns kernel-related info in driver.list_images. We do not care about kernels here, only about bootable VM images (AMIs).

First, we get the list of available AMIs. Then, we search for the user-specified keyword (if any).

Only 20 results are returned by default to avoid flooding users with too much output.

nubo.clouds.rackspace

Support deployments on Rackspace cloud.

copyright:
  1. 2013 by Emanuele Rocca.
class nubo.clouds.rackspace.Rackspace(ssh_private_key=None, login_as='root')

Bases: nubo.clouds.base.BaseCloud

deploy(image_id, size_idx=0, location_idx=0, name='test')

Rackspace supports libcloud’s libcloud.compute.deployment.

Pass an SSHKeyDeployment to self.driver.deploy_node.

nubo.clouds.opennebula

Support deployments on OpenNebula private clouds.

copyright:
  1. 2013 by Emanuele Rocca.
class nubo.clouds.opennebula.OpenNebula(ssh_private_key=None, login_as='root')

Bases: nubo.clouds.base.BaseCloud

Fork me on GitHub