blob: 7e6ae70ad43ef405df69e59fccf8b57739e39d31 [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
Jake Yip5441b3d2023-06-10 00:17:53 +100034 export OS_CLOUD=devstack
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
Bharat Kunwar951e14d2019-08-08 16:20:19 +000044 # Update security default group
45 # -----------------------------
46
47 # Add tcp/22 and icmp to default security group
48 default=$(openstack security group list -f value -c ID)
49 openstack security group rule create $default --protocol tcp --dst-port 22
50 openstack security group rule create $default --protocol icmp
Dean Troyer38e38fb2014-01-10 12:05:51 -060051
52 # Create A Flavor
53 # ---------------
54
55 # Get OpenStack admin auth
56 source $TOP_DIR/openrc admin admin
57
58 # Name of new flavor
Dean Troyerdc97cb72015-03-28 08:20:50 -050059 # set in ``local.conf`` with ``DEFAULT_INSTANCE_TYPE=m1.micro``
Dean Troyer38e38fb2014-01-10 12:05:51 -060060 MI_NAME=m1.micro
61
62 # Create micro flavor if not present
Carlos Goncalvesbac2e4d2016-11-11 15:02:57 +010063 if [[ -z $(openstack flavor list | grep $MI_NAME) ]]; then
64 openstack flavor create $MI_NAME --id 6 --ram 128 --disk 0 --vcpus 1
Dean Troyerf5633dd2012-03-28 11:21:40 -050065 fi
Dean Troyerf5633dd2012-03-28 11:21:40 -050066
Dean Troyerf5633dd2012-03-28 11:21:40 -050067fi