blob: d9d4c0a4c0c905bd3e1ba1cddb660841b8331aaa [file] [log] [blame]
Jesse Andrewsb0191512011-09-14 19:37:10 -07001#!/usr/bin/env bash
2
3# **exercise.sh** - using the cloud can be fun
4
5# we will use the ``nova`` cli tool provided by the ``python-novaclient``
6# package
Jesse Andrewsb19424f2011-09-14 22:03:04 -07007#
Jesse Andrewsb0191512011-09-14 19:37:10 -07008
Jesse Andrewsb19424f2011-09-14 22:03:04 -07009
10# This script exits on an error so that errors don't compound and you see
11# only the first error that occured.
12set -o errexit
13
14# Print the commands being run so that we can see the command that triggers
15# an error. It is also useful for following allowing as the install occurs.
16set -o xtrace
17
18
19# Settings
20# ========
Jesse Andrewsb0191512011-09-14 19:37:10 -070021
22HOST=${HOST:-localhost}
Jesse Andrewsb0191512011-09-14 19:37:10 -070023
Jesse Andrewsb19424f2011-09-14 22:03:04 -070024# Nova original used project_id as the *account* that owned resources (servers,
25# ip address, ...) With the addition of Keystone we have standardized on the
26# term **tenant** as the entity that owns the resources. **novaclient** still
Anthony Young0edde7d2011-10-06 07:10:24 -070027# uses the old deprecated terms project_id. Note that this field should now be
28# set to tenant_name, not tenant_id.
29export NOVA_PROJECT_ID=${TENANT:-demo}
Jesse Andrewsb19424f2011-09-14 22:03:04 -070030
31# In addition to the owning entity (tenant), nova stores the entity performing
32# the action as the **user**.
33export NOVA_USERNAME=${USERNAME:-demo}
34
35# With Keystone you pass the keystone password instead of an api key.
36export NOVA_API_KEY=${PASSWORD:-secrete}
37
38# With the addition of Keystone, to use an openstack cloud you should
39# authenticate against keystone, which returns a **Token** and **Service
40# Catalog**. The catalog contains the endpoint for all services the user/tenant
41# has access to - including nova, glance, keystone, swift, ... We currently
42# recommend using the 2.0 *auth api*.
43#
44# *NOTE*: Using the 2.0 *auth api* does mean that compute api is 2.0. We will
45# use the 1.1 *compute api*
46export NOVA_URL=${NOVA_URL:-http://$HOST:5000/v2.0/}
47
48# Currently novaclient needs you to specify the *compute api* version. This
49# needs to match the config of your catalog returned by Keystone.
Jesse Andrewsb0191512011-09-14 19:37:10 -070050export NOVA_VERSION=1.1
51
Anthony Young43876902011-09-27 00:29:28 -070052# FIXME - why does this need to be specified?
53export NOVA_REGION_NAME=RegionOne
54
Jesse Andrewsb0191512011-09-14 19:37:10 -070055
Anthony Young94c889a2011-10-11 18:07:48 +000056# Get a token for clients that don't support service catalog
57# ==========================================================
58SERVICE_TOKEN=`curl -s -d "{\"auth\":{\"passwordCredentials\": {\"username\": \"$NOVA_PROJECT_ID\", \"password\": \"$NOVA_API_KEY\"}}}" -H "Content-type: application/json" http://$HOST:5000/v2.0/tokens | python -c "import sys; import json; tok = json.loads(sys.stdin.read()); print tok['access']['token']['id'];"`
59
Jesse Andrews593828d2011-09-14 22:44:50 -070060# Launching a server
61# ==================
Jesse Andrewsb19424f2011-09-14 22:03:04 -070062
Jesse Andrews593828d2011-09-14 22:44:50 -070063# List servers for tenant:
Jesse Andrewsb0191512011-09-14 19:37:10 -070064nova list
Jesse Andrews593828d2011-09-14 22:44:50 -070065
66# List of flavors:
67nova flavor-list
68
69# Images
70# ------
71
72# Nova has a **deprecated** way of listing images.
73nova image-list
74
75# But we recommend using glance directly
Anthony Young94c889a2011-10-11 18:07:48 +000076glance -A $SERVICE_TOKEN index
Jesse Andrews593828d2011-09-14 22:44:50 -070077
78# show details of the active servers::
79#
80# nova show 1234
81#
82nova list | grep ACTIVE | cut -d \| -f2 | xargs -n1 nova show