rbc-tools - Command line tools for RedBridge Cloud

(Magnus Bengtsson)

We are proud to announce the first release of rbc-tools, the command line tools for managing resources in RedBridge Cloud!

With rbc-tools you can easily start, stop and deploy instances in RBC, manage networks, VPN's and ssh-keys. rbc-tools makes scripting your cloud easy and fast.

To install rbc-tools, make sure you have a recent python environment installed and python-pip or python-setuptools installed. Using pip is the recommended way to install rbc-tools:

pip install rbc-tools

Once the install has been completed, create a config file for rbc-tools, and place it in your home directory:

mkdir -p ~/.rbc
cat > ~/.rbc/rbc.cfg <<EOF
[main]
apikey = <your api key as found in the Portal>
secretkey = <your secret key as found in the Portal>
endpoint = api.rbcloud.net
EOF

You can also create a config file in the current directory ./rbc.cfg or use environment variables:

export RBC_APIKEY=XXXXX; export RBC_SECRETKEY=XXXX

With the tools setup you should now be able to execute the rbc-tools commands. In this preview release the following commands are available:

rbc-ipaddresses
rbc-offerings
rbc-staticnat
rbc-vpns
rbc-instances
rbc-networks
rbc-portforward
rbc-sshkeys
rbc-templates

Run the command with '--help' to see how to use the command. Running '--help' on the rbc-instances command should give you the following output:

$ rbc-instances --help
Manage instances in RedBridge Cloud

Usage:
  rbc-instances list [-n] [--short ] [--search=SEARCH] [--group=GROUP] [--tags=TAGS]
  rbc-instances get [-n] INSTANCE
  rbc-instances destroy [-n] INSTANCE
  rbc-instances stop [-n] INSTANCE
  rbc-instances start [-n] INSTANCE
  rbc-instances reboot [-n] INSTANCE
  rbc-instances deploy [-n] [--nowait] [-i NUM] [-g GROUP] [-t TEMPLATE]
                       [-o OFFERING] [-w NETWORK] [-z ZONE] [-s SSHKEY]
                       [-d USER-DATA | -f FILE] [--tags=TAGS] INSTANCE

Examples:
  # Deploy 4 small instances with ssh key in group my-group and supply user-data
  rbc-instances deploy -i 4 -g my-group -t rbc/fedora-20-cloudimg-x86_64-10GB -o small -w default -s mykey -f /path/to/userdata  my-instance-name


Arguments:
  INSTANCE  Instance name

Options:
  -n --noheader                      Do not show the table header
  --nowait                           Do not wait for instances to start
  --short                            Short disply, only shows name
  --search=SEARCH                    Search instances matching STRING
  --tags=TAGS                        List or add tags to instances. Tags should be
                                     specified in key/value pairs: tagkey:tagvalue,app:myapp
  -i NUM --number=NUM                Number of instances to deploy [default: 1]
  -g GROUP --group=GROUP             Name of instance group
  -t TEMPLATE --template=TEMPLATE    Name of the template to use
                                     (use "rbc-templates list featured" to get featured templates)
  -o OFFERING --offering=OFFERING    Name of offering to use
                                     (use "rbc-offerings list" to get valid offerings)
  -w NETWORK --network=NETWORK       Name of the network to use
                                     (use "rbc-networks list" to get vaild networks)
  -z ZONE --zone=ZONE                Zone to use for deployment
                                     (use "rbc-zones list" to get vaild zones)
  -s SSHKEY --sshkey=SSHKEY          Name of SSH key to use
                                     (use "rbc-ssh-keys list" to get vaild key names)
  -d USER-DATA --user-data=USER-DATA A string with user data available for the instance
  -f FILE --user-data-file=FILE      A file containing user-data (must not exceed 2KB)
  -h --help      Show this screen.
  --version      Show version.

As you can see the command accepts a lot of arguments, but once you start using the tools it should be quite straight forward.

Apart from the ability to script things in RedBridge Cloud, the command line tools also offers functionality not currently included in the Control Panel. THe tools offers ways to create and manafge ssh-keys and the possibility to supply user data to your instances. User data may be read by the instance during initialization. In RBC user data are provided by the network by running a simple http request. Since all RedBridge maintained templates includes the excellent Cloud-Init package for bootstrapping instances user data may be used to provide a cloud-config.

A sample cloud config may for instance install and configure a web server etc. Let's update the system and then install apache and php5  by supplying the below config as user-data file:

#cloud-config
apt_update: true
packages:
 - apache2
 - php5

Following the example in the help text, let's deploy 4 small Ubuntu 14.04 instances with user-data and ssh key login.

  • First, to be able to give needed arguments, we need to at least know the template name, the network name and the offering name:
rbc-offerings list compute
name    description               storagetype
------  ------------------------  -------------
large   2*2GHz CPU, 7GB RAM       shared
medium  2*2GHz CPU, 3.5GB RAM     shared
micro   1*500MHz CPU, 256 MB RAM  shared
mini    1*1GHz CPU, 0.75 GB RAM   shared
small   1*2GHz CPU, 1.75GB RAM    shared
xlarge  4*2GHz CPU, 15GB RAM      shared

rbc-networks list
name     zone       offering    cidr         domain            snat           vpn    state
-------  ---------  ----------  -----------  ----------------  -------------  -----  -----------
default  se-sth-z1  dynamic     10.1.0.0/16  rbcloud.internal  xxx.xx.xxx.xx  No     Implemented

rbc-templates list --search 14.04 featured
name                                                   zone       ostype             created                   passwordenabled
-----------------------------------------------------  ---------  -----------------  ------------------------  -----------------
rbc/ubuntu-14.04-server-cloudimg-amd64-20GB-201461111  se-sth-z1  Other PV (64-bit)  2014-06-11T13:09:39+0200  Yes
  • Now that we have needed variables (offering, network name and template name), we need to create a ssh-key to use:
rbc-sshkeys generate demo
-----BEGIN RSA PRIVATE KEY-----
MIICXQIBAAKBgQC0D7u/OG9XKVI1lr+JdtNFQ5WVUFvYW1WhEESa0EqPGN1cuOea
xkQniwXYGMRsWaL+/Zzy8I/jv7SjfEc+Qb1Eo3XicaIsl0805c0/RLCZg4eSxM7S
xLRRWsceq2gYPjvMbYnIDDCgnn/XvU35XVUkgmK/rziELJweI9IRWXNvGQIDAQAB
AoGAN6lBbWwhpv0EB8LQ9MqBpsCspdqQecJKJx7jRkQrOC8Ehtw15Ddz7BFivhlx
5tiStWZqtQK+SDYDviH11/30ZpVgR0EbLYuztSC9vTH2uvXUGCqahCARQ8evRnN2
6t9QmKKVUlEW7yxqQnOLqTfO1MowZGMp7cq8h7oSa5WegwECQQDl6jnfyoNDabzk
/R1u8lComlpKgNPnTfRzOTPgtPA1deTk7iuOuyS8f1nMw7rk/1+jyb/y6DawP+3k
2uL7E1c5AkEAyH2JI2Hu0QsthNBpNXb0C6bZSrhb9lBW9BOIRPbu/aWrcgo0ukzA
7Gint8askJIpy73tgccvpJcX41mfabv24QJBAI7jRNiaqX2KB4Vg8Zv0KMDAPQE0
k32bayL5GA69JNR00q6cfqGUGT60/wBNXKfZNn06c3rpaqOa96RVjN9xo7ECQAYj
AY2Zs8umQfBsyKugRnwM0V3eIsJ5VxAFgQhLXqlY5tSIx3BkZQtXcLrJVALg1nKs
D5cHV8f77/k/hweff0ECQQCIIwn3XJLI1dhjbEYi7TQL9RLwMbyx7CRpAiUb16pP
BiUEkDp5A+isY8v2glQtjt8GSuuWBPPDrpoR220I3ndX
-----END RSA PRIVATE KEY-----
  • Now save this key to ~/.ssh/demo.

To deploy the 4 Ubuntu 14.04 instances, just run:

rbc-instances deploy -i 4 -g demo -t rbc/ubuntu-14.04-server-cloudimg-amd64-20GB-201461111 -o small -w default -s demo -f demo.user-data ubuntu-demo
name             zone       state    offering    group    network    ipaddress    sshkey    password    template                                               created
---------------  ---------  -------  ----------  -------  ---------  -----------  --------  ----------  -----------------------------------------------------  ------------------------
ubuntu-demo-3e7  se-sth-z1  Running  small       demo     default    10.1.0.139   demo      qR5bnrwyc   rbc/ubuntu-14.04-server-cloudimg-amd64-20GB-201461111  2014-07-31T16:34:51+0200
ubuntu-demo-3e9  se-sth-z1  Running  small       demo     default    10.1.0.35    demo      kD9pkxaca   rbc/ubuntu-14.04-server-cloudimg-amd64-20GB-201461111  2014-07-31T16:34:51+0200
ubuntu-demo-ca8  se-sth-z1  Running  small       demo     default    10.1.0.106   demo      yA6uwxnns   rbc/ubuntu-14.04-server-cloudimg-amd64-20GB-201461111  2014-07-31T16:34:50+0200
ubuntu-demo-f0f  se-sth-z1  Running  small       demo     default    10.1.0.234   demo      yE3kcixbj   rbc/ubuntu-14.04-server-cloudimg-amd64-20GB-201461111  2014-07-31T16:34:50+0200

Once the instances have booted, you should be able to logon to them using the ssh key as the user "ubuntu" (All RedBridge provided templates uses the distroname as the login username, i.e centos for CentOS machines and fedora for Fedora machines).

The best way to connect to instances in RedBridge Cloud is to use the included cloud based VPN, this may be enabled in the control panel or by using the rbc-vpns command line tool.

ssh 10.1.0.139 -l ubuntu -i ~/.ssh/demo
Welcome to Ubuntu 14.04 LTS (GNU/Linux 3.13.0-24-generic x86_64)

 * Documentation:  https://help.ubuntu.com/

  System information as of Thu Jul 31 14:35:04 UTC 2014

  System load: 0.0               Memory usage: 3%   Processes:       77
  Usage of /:  55.4% of 1.32GB   Swap usage:   0%   Users logged in: 0

  Graph this data and manage this system at:
    https://landscape.canonical.com/

  Get cloud support with Ubuntu Advantage Cloud Guest:
    http://www.ubuntu.com/business/services/cloud

0 packages can be updated.
0 updates are security updates.



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.

ubuntu@ubuntu-demo-3e7:~$

Destroying the instances are just as simple:

for i in $(rbc-instances list --search demo -n --short); do rbc-instances destroy $i;done
name             zone       state      offering    group    network    ipaddress    sshkey    password    template                                               created
---------------  ---------  ---------  ----------  -------  ---------  -----------  --------  ----------  -----------------------------------------------------  ------------------------
ubuntu-demo-3e7  se-sth-z1  Destroyed  small       demo     default    10.1.0.139   demo      None        rbc/ubuntu-14.04-server-cloudimg-amd64-20GB-201461111  2014-07-31T16:34:51+0200
name             zone       state      offering    group    network    ipaddress    sshkey    password    template                                               created
---------------  ---------  ---------  ----------  -------  ---------  -----------  --------  ----------  -----------------------------------------------------  ------------------------
ubuntu-demo-3e9  se-sth-z1  Destroyed  small       demo     default    10.1.0.35    demo      None        rbc/ubuntu-14.04-server-cloudimg-amd64-20GB-201461111  2014-07-31T16:34:51+0200
name             zone       state      offering    group    network    ipaddress    sshkey    password    template                                               created
---------------  ---------  ---------  ----------  -------  ---------  -----------  --------  ----------  -----------------------------------------------------  ------------------------
ubuntu-demo-ca8  se-sth-z1  Destroyed  small       demo     default    10.1.0.106   demo      None        rbc/ubuntu-14.04-server-cloudimg-amd64-20GB-201461111  2014-07-31T16:34:50+0200
name             zone       state      offering    group    network    ipaddress    sshkey    password    template                                               created
---------------  ---------  ---------  ----------  -------  ---------  -----------  --------  ----------  -----------------------------------------------------  ------------------------
ubuntu-demo-f0f  se-sth-z1  Destroyed  small       demo     default    10.1.0.234   demo      None        rbc/ubuntu-14.04-server-cloudimg-amd64-20GB-201461111  2014-07-31T16:34:50+0200

The rbc-tools are in a early preview stage, but feel free to test them, you can also contribute to them if you want, all code are available on github: https://github.com/redbridge/rbc-tools