Channels ▼
RSS

Tools

Project of the Month: OpenStack, A Universal Cloud Front End


Starting a Machine Instance with Tools for Automated Scripting

You can easily start an instance using the Dashboard, but it's likely you'll want to launch instances from the command-line for easy scripting. Installing the python-novaclient gives you a nova shell command that enables Compute API interactions from the command line. You install the client, and then provide your user name and password, set as environment variables for convenience, and then you can have the ability to send commands to your cloud on the command-line.

To install python-novaclient, download the tarball from install it in your favorite python environment.

$ curl -O http://pypi.python.org/packages/source/p/python-novaclient/pythonnovaclient-2.6.3.tar.gz
$ tar -zxvf python-novaclient-2.6.3.tar.gz
$ cd python-novaclient-2.6.3
$ sudo python setup.py install

Now that you have installed the python-novaclient, confirm the installation by entering:

$ nova help

You should see a list of all the commands and parameters for the nova command-line client. By setting up the required parameters as environment variables, you can fly through these commands on the command line. You can add --username on the nova command, or set these parameters as environment variables:

export NOVA_USERNAME=joecool
export NOVA_API_KEY=coolword
export NOVA_PROJECT_ID=coolu

The Project ID is the same as the Tenant depending on the authentication service you are using. When cloud administrators set up OpenStack, they should assign an authentication endpoint, which nova recognizes as the NOVA_URL.

export NOVA_URL=http://hostname:5000/v2.0
export NOVA_VERSION=1.1

Before you can go about building your cloud, you need to know what images are available to you by asking the image service what kinds of configurations are available. The image service could be compared to iTunes for your cloud: You can view the playlist of available images before using your favorite image to create a new instance in the cloud. To get the list of images, their names, status, and ID, use this command:

$ nova image-list

Here's an example of what you could see in return:

+----+-------------------------------------------------------+--------+
| ID |                          Name                         | Status |
+----+-------------------------------------------------------+--------+
| 1  | aki-tty                                               | ACTIVE |
| 2  | ari-tty                                               | ACTIVE |
| 3  | ami-tty                                               | ACTIVE |
| 6  | CentOS_5.4_x64                                        | ACTIVE |
| 14 | maverick-kernel                                       | ACTIVE |
| 15 | maverick                                              | ACTIVE |
| 20 | ubuntu-kernel                                         | ACTIVE |
| 21 | ubuntu-ramdisk                                        | ACTIVE |
| 22 | ubuntu                                                | ACTIVE |
| 24 | CentOS_5.6_x64_v5.7.14_Dev1                           | ACTIVE |
+----+-------------------------------------------------------+--------+    

Next you need to know the relative sizes of each of these, using the flavor-list parameter.

$ nova flavor-list       
+----+-----------+-----------+------+----------+-------+------------+----------+
| ID |    Name   | Memory_MB | Swap | Local_GB | VCPUs | RXTX_Quota | RXTX_Cap |
+----+-----------+-----------+------+----------+-------+------------+----------+
| 1  | m1.tiny   | 512       |      | 0        |       |            |          |
| 2  | m1.small  | 2048      |      | 20       |       |            |          |
| 3  | m1.medium | 4096      |      | 40       |       |            |          |
| 4  | m1.large  | 8192      |      | 80       |       |            |          |
| 5  | m1.xlarge | 16384     |      | 160      |       |            |          |
| 89 | Boom      | 2         |      | 20       |       |            |          |
+----+-----------+-----------+------+----------+-------+------------+----------+

You can also narrow down the list by using grep to find, for example, only the CentOS images with a command like this:

$ nova image-list | grep 'CentOS'
| 6  | CentOS_5.4_x64                                        | ACTIVE |
| 24 | CentOS_5.6_x64_v5.7.14_Dev1                           | ACTIVE |

With the information about what is available to you, you can choose the combination of image and flavor to create your virtual servers and launch instances.

To launch a server, choose an image, find the ID for the image and the ID for the flavor so you can size it, and create the command with the IDs. From the information just presented, you know that an Ubuntu Maverick image has an ID of 15, and if you want to start small with about 2 GB of memory and 20 GB of disk space, you'd choose the m1.small flavor — it has an ID of 2 in this particular example. Put those parameters in with the boot command and you can create a new virtual server.

 $ nova boot --flavor=2 --image=15 testserver
 +-----------+--------------------------------------+
|  Property |                Value                 |
+-----------+--------------------------------------+
| adminPass | ****************                     |
| created   | 2011-09-01T21:40:41Z                 |
| flavor    | m1.small                             |
| hostId    |                                      |
| id        | 1805                                 |
| image     | maverick                             |
| metadata  | {}                                   |
| name      | testserver                           |
| progress  | 0                                    |
| status    | BUILD                                |
| updated   | 2011-09-01T21:40:41Z                 |
| uuid      | ce044452-f22e-4ea4-a3ec-d1cde80cf996 |
+-----------+--------------------------------------+

Now, you can view this server in your new cloud by using the nova list command:

$ nova list
+------+------------+--------+--------------------------------+
|  ID  |    Name    | Status |            Networks            |
+------+------------+--------+--------------------------------+
| 1805 | testserver | ACTIVE | private=10.4.96.81             |
+------+------------+--------+--------------------------------+

There are three status options: ACTIVE, BUILDING, and UNKNOWN. The BUILDING status is transient and you likely will not see it. If you see UNKNOWN, run nova list again until it goes away.

To view all the information about a particular server, use nova show with the ID of the server that you got from the nova list command.

$ nova show 1805
+-----------------+----------------------------------------------------------+
|     Property    |                          Value                           |
+-----------------+----------------------------------------------------------+
| created         | 2011-09-01T21:40:41Z                                     |
| flavor          | m1.small                                                 |
| hostId          | 58a7430169aa42cde5ce2456b0cb5bb5ac1ab0703bab6420e8a49e6e |
| id              | 1805                                                     |
| image           | maverick                                                 |
| metadata        | {}                                                       |
| name            | testserver                                               |
| private network | 10.4.96.81                                               |
| progress        | 100                                                      |
| status          | ACTIVE                                                   |
| updated         | 2011-09-01T21:40:46Z                                     |
| uuid            | ce044452-f22e-4ea4-a3ec-d1cde80cf996                     |
+-----------------+----------------------------------------------------------+

With this basic walkthrough of nova commands, you started building your cloud!


Related Reading


More Insights






Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

 
Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.
 

Video