OpenStack Compute API

Follow

Mammoth Cloud servers can be controlled using the OpenStack Compute API. This article will walk through the process of using the "nova" command-line client.

 

Installing the client

OpenStack has a command line client named Nova. Nova is written in python, so we need to install Python and then install Nova itself.

 

Installing Python

The nova command-line client is a Python application, so if you are running Windows you will first need to install Python itself. You can get Python here:

Download the 32-bit or 64-bit version as appropriate and run the installer. Once its finished, open a Windows command prompt ("cmd").

 

Installing Nova

With python installed, you can use "pip" - the python package manager - to install Nova. The python installer should have placed pip in your PATH already, so simply run:

pip install python-novaclient

Wait a few minutes while it downloads and installs. You may see some errors about unable to compile various things - this is an optional optimization and is harmless.

 

Setting up your environment

The nova command-line client requires that you set up some environment variables. The variables are:

Variable

Value

Description

OS_AUTH_URL

https://api.mammoth.com.au/v2.0

This tells nova where the API server is located.

OS_USERNAME

Your Mammoth Cloud email address

This is the username that is authenticated against the API.

OS_PASSWORD

Your Mammoth Cloud account password or API key

This is the secret used to authenticate against the API. While you can use the password that you login to mPanel with, the preferred option is to go to https://www.mammoth.com.au/mpanel/profile/overview and obtain your API key.

OS_TENANT_NAME

mammoth

This is used for multi-tenant private clouds. As Mammoth is a public cloud we have a single tenant, "mammoth".

OS_COMPUTE_API_VERSION

2.latest

This requests the OpenStack client use the latest API version that our server supports.

These variables need to be set within a Windows command prompt using the SET command. A good approach to avoid redoing this each time you want to use nova is to create a shortcut to cmd.exe that sets the values for you. To do so, right-click your desktop and select "New shortcut". Enter the location as:     

cmd /k "mode con: cols=150 lines=50&& set OS_AUTH_URL=https://api.mammoth.com.au/v2.0&& set OS_TENANT_NAME=mammoth&& set OS_USERNAME=user@example.com&& set OS_PASSWORD=32characterapikey&& set OS_COMPUTE_API_VERSION=2.latest"

Just edit the line to contain your email and API key (be careful not to add a space before the && symbols as that would add a space to the end of environment variable.). Name your new shortcut "Mammoth Cloud" and double-click to open Command Prompt. Check your environment is working:

C:\>echo "%OS_AUTH_URL%"
"https://api.mammoth.com.au/v2.0"

C:\>echo "%OS_TENANT_NAME%"
"mammoth"

C:\>echo "%OS_USERNAME%"
"user@example.com"

C:\>echo "%OS_PASSWORD%"
"1234567890abcdefghijklmnopqrstuv"

Double-check the values are correct and that there is no space between the value and the terminating quotation mark.

 

Using the nova client

With the environment setup, you can now use Nova. (All of the above is a once off; in the future you can just open the "Mammoth Cloud" command prompt and start working)

 

Server list

Start by seeing what servers you have:

C:\>nova list
 
+--------------------------------------+------------------------+--------+------------+-------------+----------------------+
| ID                                   | Name                   | Status | Task State | Power State | Networks             |
+--------------------------------------+------------------------+--------+------------+-------------+----------------------+
| 56cd309d-028c-41b5-afca-a2d000ed6cb2 | linux.local            | ACTIVE | N/A        | N/A         | public=103.16.128.27 |
+--------------------------------------+------------------------+--------+------------+-------------+----------------------+

Here I have a single VPS, and its permanent ID is 56cd309d-028c-41b5-afca-a2d000ed6cb2.

 

Reboot a server

This ID can be used with other nova commands: for example, if I want to reboot my linux.local server:

C:\>nova reboot 56cd309d-028c-41b5-afca-a2d000ed6cb2

If you have mPanel open, you should see your server reboot.  If the server is not responding to the reboot request (perhaps because its run out of memory), then you can force a reboot with:

C:\>nova reboot 56cd309d-028c-41b5-afca-a2d000ed6cb2 --hard

This is equivalent to the "Power-cycle" button in mPanel.

 

Create a new server

New servers are created with nova using the "boot" command, but before doing so we need to select a plan and an operating system which nova refers to as "flavor" and "image" respectively. These can be listed with flavor-list and image-list respectively:

C:\>nova flavor-list
+----------+------------+-----------+------+-----------+------+-------+-------------+-----------+
| ID       | Name       | Memory_MB | Disk | Ephemeral | Swap | VCPUs | RXTX_Factor | Is_Public |
+----------+------------+-----------+------+-----------+------+-------+-------------+-----------+
| gp-1024  | gp.micro   | 1024      | 20   | 0         |      | 1     |             | N/A       |
| co-1024  | co.small   | 1024      | 40   | 0         |      | 2     |             | N/A       |
| gp-2048  | gp.small   | 2048      | 40   | 0         |      | 2     |             | N/A       |
| co-2048  | co.medium  | 2048      | 80   | 0         |      | 4     |             | N/A       |
| gp-4096  | gp.medium  | 4096      | 80   | 0         |      | 4     |             | N/A       |
| co-4096  | co.large   | 4096      | 150  | 0         |      | 8     |             | N/A       |
| gp-8192  | gp.large   | 8192      | 150  | 0         |      | 6     |             | N/A       |
| co-8192  | co.xlarge  | 8192      | 300  | 0         |      | 12    |             | N/A       |
| gp-16384 | gp.xlarge  | 16384     | 300  | 0         |      | 8     |             | N/A       |
| co-16384 | co.2xlarge | 16384     | 600  | 0         |      | 16    |             | N/A       |
+----------+------------+-----------+------+-----------+------+-------+-------------+-----------+

 

C:\>nova image-list
+--------------------------------------+--------------------------+--------+--------+
| ID                                   | Name                     | Status | Server |
+--------------------------------------+--------------------------+--------+--------+
| 9310ba82-31c5-4cd3-add3-d7dfc6fc86a1 | CentOS 6.5 (32bit)       | active |        |
| 9310ba82-31c5-4cd3-add3-d7dfc6fc86a2 | CentOS 6.5 (64bit)       | active |        |
| 07140ec2-335c-49f3-b9e8-10c1c0ad1001 | Debian 7 (32bit)         | active |        |
| 07140ec2-335c-49f3-b9e8-10c1c0ad1002 | Debian 7 (64bit)         | active |        |
| 07140ec2-335c-49f3-b9e8-10c1c0ad3375 | Ubuntu 12.04 LTS (32bit) | active |        |
| 07140ec2-335c-49f3-b9e8-10c1c0ad3376 | Ubuntu 12.04 LTS (64bit) | active |        |
| d91a14c9-e057-40ce-8c8c-4ad7ea48dcc3 | Windows 2008 R2 (64bit)  | active |        |
| 002c3b0c-fa4e-4685-a4cc-2156bf7a221f | Windows 2012 R2 (64bit)  | active |        |
+--------------------------------------+--------------------------+--------+--------+

As with the "list" command, you need to grab the ID for each that you want. For my example I'm going to create an Ubuntu 12.04 64-bit server on the gp.micro plan named "test.example.com":

C:\>nova boot --flavor gp.1024 --image 07140ec2-335c-49f3-b9e8-10c1c0ad3376 text.example.com
+----------------+-----------------------------------------------------------------+
| Property       | Value                                                           |
+----------------+-----------------------------------------------------------------+
| accessIPv4     | 103.16.128.123                                                  |
| accessIPv6     | 2404:9400:1:0:216:3eff:fef0:154                                 |
| adminPass      | BuUHrcV4                                                        |
| created        | -                                                               |
| flavor         | Apartment (002c3b0c-fa4e-4685-a4cc-2156bf7a210b)                |
| hostId         | bnecompute3                                                     |
| id             | f827d5a3-326d-431c-9649-a2e000f55074                            |
| image          | Ubuntu 12.04 LTS (64bit) (07140ec2-335c-49f3-b9e8-10c1c0ad3376) |
| metadata       | -                                                               |
| name           | text.example.com                                                |
| progress       | -                                                               |
| public network | 103.16.128.123                                                  |
| status         | ERROR                                                           |
| tenant_id      | -                                                               |
| updated        | -                                                               |
| user_id        | -                                                               |
+----------------+-----------------------------------------------------------------+

Check mPanel's service list at https://www.mammoth.com.au/mpanel/list (or run "nova list") and you will find you have a second server. The adminPass line tells you the password which you can SSH to your server with.

 

Cancelling a server

Once you are finished with a server, you can cancel it to shut it down and terminate billing. To do so, use nova's "delete" command using the server's ID. (Use "nova list" to get the ID again if necessary):

nova delete f827d5a3-326d-431c-9649-a2e000f55074

This is equivalent to selecting "Cancel Service" within mPanel:

C:\>nova list
+--------------------------------------+------------------------+-----------+------------+-------------+-----------------------+
| ID                                   | Name                   | Status    | Task State | Power State | Networks              |
+--------------------------------------+------------------------+-----------+------------+-------------+-----------------------+
| 56cd309d-028c-41b5-afca-a2d000ed6cb2 | linux.local            | ACTIVE    | N/A        | N/A         | public=103.16.128.27  |
| f827d5a3-326d-431c-9649-a2e000f55074 | text.example.com       | SUSPENDED | N/A        | N/A         | public=103.16.128.123 |
+--------------------------------------+------------------------+-----------+------------+-------------+-----------------------+

 

Further exploration

In this article we have demonstrated the basics of listing your cloud servers, creating a new VPS, rebooting it and finally destroying it. However, this is just the tip of the iceberg - some of the other more useful nova commands include:

  • nova rebuild - equivalent to "Reinstall" in mPanel, deletes all the data puts a fresh copy of the operating system in place

  • nova resize - equivalent to "Change Plan" in mPanel, allows you to size an existing server up or down

  • nova root-password - equivalent to "Reset Password" in mPanel, if you have lost the password for the VPS

Have more questions? Submit a request

Comments

Powered by Zendesk