openstack-manuals/doc/src/docbkx/api-quick-start/src/docbkx/cli-uses.xml

161 lines
9.9 KiB
XML

<?xml version="1.0" encoding="UTF-8"?>
<chapter xmlns="http://docbook.org/ns/docbook"
xmlns:xi="http://www.w3.org/2001/XInclude"
xmlns:xlink="http://www.w3.org/1999/xlink"
xml:id="Setting-Up-Python-novaclient"
version="5.0">
<title>Setting Up python-novaclient</title>
<para>For more serious scripting work, you can use a client like the python-novaclient or openstack-compute clients. The python-novaclient implements the Compute 1.1 API while the openstack-compute client works against the Rackspace Cloud Servers public cloud which is the OpenStack Compute 1.0 API. You only need a username and password to use the python-novaclient tool. </para>
<para>Installing the python-novaclient gives you a <code>nova</code> shell command that enables
Compute API interactions from the command line. You install the client, and then provide
your username 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.</para>
<para>To install python-novaclient, download the tarball from
<link xlink:href="http://pypi.python.org/pypi/python-novaclient/2.6.3#downloads">http://pypi.python.org/pypi/python-novaclient/2.6.3#downloads</link> and then install it in your favorite python environment. </para>
<programlisting>
$ curl -O http://pypi.python.org/packages/source/p/python-novaclient/python-novaclient-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
</programlisting>
<para>Now that you have installed the python-novaclient, confirm the installation by entering:</para><programlisting>
$ nova help
usage: nova [--username USERNAME] [--apikey APIKEY] [--projectid PROJECTID]
[--url URL] [--version VERSION]
&lt;subcommand&gt; ...
</programlisting>
<para>In return, you will get a listing 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 them as environment variables: </para>
<para><programlisting>
export NOVA_USERNAME=joecool
export NOVA_API_KEY=coolword
export NOVA_PROJECT_ID=coolu
</programlisting>
</para><para>Using the Identity Service, you are supplied with an authentication endpoint, which nova recognizes as the NOVA_URL. </para>
<para>
<programlisting>
export NOVA_URL=http://hostname:5000/v2.0
export NOVA_VERSION=1.1
</programlisting>
</para>
<section xml:id="Launching-Images-a09140"><title>Listing Images</title><para>Before you can go about the business of building your cloud, you want 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 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:
<programlisting>
$ nova image-list
+----+-------------------------------------------------------+--------+
| 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 |
+----+-------------------------------------------------------+--------+
</programlisting></para>
<para>Next you need to know the relative sizes of each of these. </para>
<para><programlisting>
$ 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 | | | |
+----+-----------+-----------+------+----------+-------+------------+----------+
</programlisting></para>
<para>You can also narrow down the list by using grep to find only the CentOS images with a command like this: </para>
<para>
<programlisting>
$ nova image-list | grep 'CentOS'
| 6 | CentOS_5.4_x64 | ACTIVE |
| 24 | CentOS_5.6_x64_v5.7.14_Dev1 | ACTIVE |
</programlisting>
</para>
<para>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. </para></section>
<section xml:id="Listing-Images-a01518"><title>Launching Instances </title>
<para>
To launch a server, you choose an image you want to match up to a size, 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 we got previously, we 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 which has an ID of 2. Put those parameters in with the "boot" command and you can create a new virtual server.
</para>
<para>
<programlisting>
$ 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 |
+-----------+--------------------------------------+
</programlisting>
</para>
<para>Now, you can view this server in your new cloud by using the nova list
command:<programlisting>
$ nova list
+------+------------+--------+--------------------------------+
| ID | Name | Status | Networks |
+------+------------+--------+--------------------------------+
| 1805 | testserver | ACTIVE | private=10.4.96.81 |
+------+------------+--------+--------------------------------+
</programlisting></para>
<para>There are three statuses you may see - ACTIVE, BUILDING, and UNKNOWN. The BUILDING status is transient and you likely will not see it. If you see UNKNOWN, run <code>nova list</code> again until it goes away.</para>
<para>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.</para>
<programlisting>
$ 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 |
+-----------------+----------------------------------------------------------+
</programlisting>
<para>You can now launch that image again, but add more information to the server when you
boot it so that you can more easily identify it amongst your ever-growing elastic cloud.
Use the -meta option with a key=value pair, where you can make up the string for both the
key and the value. For example, you could add a description and also the creator of the
server.
<programlisting>$ nova boot testserver --meta description='Use for testing purposes' --meta creator=joecool</programlisting></para>
</section></chapter>