2
# Create additional nova instance types (flavors)
3
# to map to the AWS instance types we have in the templates
5
# Default nova install (via tools/openstack) gives this:
6
# +----+-----------+-----------+------+-----------+------+-------+-------------+
7
# | ID | Name | Memory_MB | Disk | Ephemeral | Swap | VCPUs | RXTX_Factor |
8
# +----+-----------+-----------+------+-----------+------+-------+-------------+
9
# | 1 | m1.tiny | 512 | 0 | 0 | | 1 | 1.0 |
10
# | 2 | m1.small | 2048 | 10 | 20 | | 1 | 1.0 |
11
# | 3 | m1.medium | 4096 | 10 | 40 | | 2 | 1.0 |
12
# | 4 | m1.large | 8192 | 10 | 80 | | 4 | 1.0 |
13
# | 5 | m1.xlarge | 16384 | 10 | 160 | | 8 | 1.0 |
14
# +----+-----------+-----------+------+-----------+------+-------+-------------+
16
# Templates define these as valid
17
# "t1.micro" : { "Arch" : "32" },
18
# "m1.small" : { "Arch" : "32" },
19
# "m1.large" : { "Arch" : "64" },
20
# "m1.xlarge" : { "Arch" : "64" },
21
# "m2.xlarge" : { "Arch" : "64" },
22
# "m2.2xlarge" : { "Arch" : "64" },
23
# "m2.4xlarge" : { "Arch" : "64" },
24
# "c1.medium" : { "Arch" : "32" },
25
# "c1.xlarge" : { "Arch" : "64" },
26
# "cc1.4xlarge" : { "Arch" : "64" }
28
# So for development purposes, we create all flavors, but with a maximum of
29
# 2vcpus, 10G disk and 2G RAM (since we're all running on laptops..)
32
# Nova rate limits actions so we need retry/sleep logic to avoid
33
# spurious failures when doing sequential operations
34
# we also sleep after every operation otherwise rate-limiting will definitely
35
# cause lots of failures
39
while [[ ${attempts} < ${MAX_TRIES} ]]
41
attempts=$((${attempts} + 1))
44
echo "Command : \"$@\" failed, retry after 1s ${attempts}/${MAX_TRIES}"
53
if [[ ${attempts} == ${MAX_TRIES} ]]
55
echo "ERROR : persistent error attempting to run command \"$@\"!"
60
# Sanity-test nova flavor-list, this should catch problems with credentials
61
# or if nova is not running. When calling from openstack install, it seems
62
# that nova gives 400 errors despite the service showing as active via
63
# systemctl, so we work around that by polling via retry_cmd before doing the
64
# final check - this should mean we wait for the service to come up but still
65
# exit if there is a non-transient problem
66
retry_cmd "nova flavor-list"
67
if ! nova flavor-list > /dev/null
69
echo "ERROR, unable to do \"nova flavor-list\""
70
echo "Check keystone credentials and that nova services are running"
74
# This list should match the flavor-creates below to be sure we remove the
75
# flavors we're about to create, and no others
76
FLAVORS="t1\.micro|m1\.tiny|m1\.small|m1\.medium|m1\.large|m1\.xlarge|m2\.xlarge|m2\.2xlarge|m2\.4xlarge|c1\.medium|c1\.xlarge|cc1\.4xlarge"
78
for f in $(nova flavor-list | grep -E "^\|\s+[0-9]+\s+\|\s+($FLAVORS)\s" | awk '{print $2}')
80
retry_cmd "nova flavor-delete $f"
83
retry_cmd "nova flavor-create --ephemeral 10 --swap 0 --rxtx-factor 1 t1.micro 1 256 0 1"
84
retry_cmd "nova flavor-create --ephemeral 10 --swap 0 --rxtx-factor 1 m1.tiny 2 256 0 1"
85
retry_cmd "nova flavor-create --ephemeral 10 --swap 0 --rxtx-factor 1 m1.small 3 512 0 1"
86
retry_cmd "nova flavor-create --ephemeral 10 --swap 0 --rxtx-factor 1 m1.medium 4 768 0 1"
87
retry_cmd "nova flavor-create --ephemeral 10 --swap 0 --rxtx-factor 1 m1.large 5 1024 0 1"
88
retry_cmd "nova flavor-create --ephemeral 10 --swap 0 --rxtx-factor 1 m1.xlarge 6 2048 0 1"
89
retry_cmd "nova flavor-create --ephemeral 10 --swap 0 --rxtx-factor 1 m2.xlarge 7 2048 0 2"
90
retry_cmd "nova flavor-create --ephemeral 10 --swap 0 --rxtx-factor 1 m2.2xlarge 8 2048 0 2"
91
retry_cmd "nova flavor-create --ephemeral 10 --swap 0 --rxtx-factor 1 m2.4xlarge 9 2048 0 2"
92
retry_cmd "nova flavor-create --ephemeral 10 --swap 0 --rxtx-factor 1 c1.medium 10 2048 0 2"
93
retry_cmd "nova flavor-create --ephemeral 10 --swap 0 --rxtx-factor 1 c1.xlarge 11 2048 0 2"
94
retry_cmd "nova flavor-create --ephemeral 10 --swap 0 --rxtx-factor 1 cc1.4xlarge 12 2048 0 2"
96
# Check we get the expected number of flavors on completion
97
num_flavors=$(nova flavor-list | grep "[0-9]. *|" | wc -l)
99
if [[ ${num_flavors} != ${expected_flavors} ]]
101
echo "ERROR : problem creating flavors, created ${num_flavors}, expected ${expected_flavors}"
2
echo "WARNING: This script now make no modifications to the current flavors"