blob: 9cd0bdcc17c2c37470e0255b72347ed215104fa0 [file] [log] [blame]
Dean Troyerf5633dd2012-03-28 11:21:40 -05001#!/usr/bin/env bash
2
3# Sample ``local.sh`` for user-configurable tasks to run automatically
Joe Gordon46400262013-06-30 04:32:27 -07004# at the successful conclusion of ``stack.sh``.
Dean Troyerf5633dd2012-03-28 11:21:40 -05005
Dean Troyerdc97cb72015-03-28 08:20:50 -05006# NOTE: Copy this file to the root DevStack directory for it to work properly.
Dean Troyerf5633dd2012-03-28 11:21:40 -05007
8# This is a collection of some of the things we have found to be useful to run
Dean Troyer5547baa2012-08-31 10:55:36 -05009# after ``stack.sh`` to tweak the OpenStack configuration that DevStack produces.
Dean Troyerf5633dd2012-03-28 11:21:40 -050010# These should be considered as samples and are unsupported DevStack code.
11
Dean Troyer5547baa2012-08-31 10:55:36 -050012
Dean Troyerdc97cb72015-03-28 08:20:50 -050013# Keep track of the DevStack directory
Dean Troyerf5633dd2012-03-28 11:21:40 -050014TOP_DIR=$(cd $(dirname "$0") && pwd)
15
Dean Troyer05530ca2012-07-06 15:09:10 -050016# Import common functions
17source $TOP_DIR/functions
18
Dean Troyerf5633dd2012-03-28 11:21:40 -050019# Use openrc + stackrc + localrc for settings
20source $TOP_DIR/stackrc
21
22# Destination path for installation ``DEST``
23DEST=${DEST:-/opt/stack}
24
Dean Troyer38e38fb2014-01-10 12:05:51 -060025if is_service_enabled nova; then
Dean Troyerf5633dd2012-03-28 11:21:40 -050026
Dean Troyer38e38fb2014-01-10 12:05:51 -060027 # Import ssh keys
28 # ---------------
Dean Troyerf5633dd2012-03-28 11:21:40 -050029
Dean Troyer38e38fb2014-01-10 12:05:51 -060030 # Import keys from the current user into the default OpenStack user (usually
31 # ``demo``)
Dean Troyerf5633dd2012-03-28 11:21:40 -050032
Dean Troyer38e38fb2014-01-10 12:05:51 -060033 # Get OpenStack user auth
34 source $TOP_DIR/openrc
Dean Troyerf5633dd2012-03-28 11:21:40 -050035
Dean Troyer38e38fb2014-01-10 12:05:51 -060036 # Add first keypair found in localhost:$HOME/.ssh
37 for i in $HOME/.ssh/id_rsa.pub $HOME/.ssh/id_dsa.pub; do
38 if [[ -r $i ]]; then
Carlos Goncalvesbac2e4d2016-11-11 15:02:57 +010039 openstack keypair create --public-key $i `hostname`
Dean Troyer38e38fb2014-01-10 12:05:51 -060040 break
41 fi
42 done
43
44
45 # Create A Flavor
46 # ---------------
47
48 # Get OpenStack admin auth
49 source $TOP_DIR/openrc admin admin
50
51 # Name of new flavor
Dean Troyerdc97cb72015-03-28 08:20:50 -050052 # set in ``local.conf`` with ``DEFAULT_INSTANCE_TYPE=m1.micro``
Dean Troyer38e38fb2014-01-10 12:05:51 -060053 MI_NAME=m1.micro
54
55 # Create micro flavor if not present
Carlos Goncalvesbac2e4d2016-11-11 15:02:57 +010056 if [[ -z $(openstack flavor list | grep $MI_NAME) ]]; then
57 openstack flavor create $MI_NAME --id 6 --ram 128 --disk 0 --vcpus 1
Dean Troyerf5633dd2012-03-28 11:21:40 -050058 fi
Dean Troyerf5633dd2012-03-28 11:21:40 -050059
60
Dean Troyer38e38fb2014-01-10 12:05:51 -060061 # Other Uses
62 # ----------
Dean Troyerf5633dd2012-03-28 11:21:40 -050063
Dean Troyer38e38fb2014-01-10 12:05:51 -060064 # Add tcp/22 and icmp to default security group
Carlos Goncalvesbac2e4d2016-11-11 15:02:57 +010065 openstack security group rule create --project $OS_PROJECT_NAME default --protocol tcp --ingress --dst-port 22
66 openstack security group rule create --project $OS_PROJECT_NAME default --protocol icmp
Dean Troyerf5633dd2012-03-28 11:21:40 -050067
Dean Troyerf5633dd2012-03-28 11:21:40 -050068fi