Allow the Getting Started script to run non-interactively

Related: #84

Signed-off-by: Zane Bitter <zbitter@redhat.com>
This commit is contained in:
Zane Bitter 2012-05-14 16:03:49 +02:00
parent 0cd65f8cac
commit 645d093c45
7 changed files with 56 additions and 42 deletions

View File

@ -311,6 +311,9 @@ def create_options(parser):
help="Print more verbose output") help="Print more verbose output")
parser.add_option('-d', '--debug', default=False, action="store_true", parser.add_option('-d', '--debug', default=False, action="store_true",
help="Print more verbose output") help="Print more verbose output")
parser.add_option('-y', '--yes', default=False, action="store_true",
help="Don't prompt for user input; assume the answer to "
"every question is 'yes'.")
parser.add_option('-H', '--host', metavar="ADDRESS", default="0.0.0.0", parser.add_option('-H', '--host', metavar="ADDRESS", default="0.0.0.0",
help="Address of heat API host. " help="Address of heat API host. "
"Default: %default") "Default: %default")

View File

@ -29,7 +29,7 @@ Options:
--help | -h --help | -h
Print usage information. Print usage information.
--heatpw <pw> | -n <pw> --password <pw> | -p <pw>
Specify the password for the 'heat' MySQL user that will Specify the password for the 'heat' MySQL user that will
use to connect to the 'heat' MySQL database. By default, use to connect to the 'heat' MySQL database. By default,
the password 'heat' will be used. the password 'heat' will be used.
@ -66,11 +66,6 @@ MYSQL_HEAT_PW=${MYSQL_HEAT_PW_DEFAULT}
HEAT_CONFIG="/etc/heat/heat-engine.conf" HEAT_CONFIG="/etc/heat/heat-engine.conf"
ASSUME_YES="" ASSUME_YES=""
if [ $# -eq 0 ]
then
usage
fi
case "$1" in case "$1" in
rpm) rpm)
echo "Installing on an RPM system." echo "Installing on an RPM system."
@ -90,6 +85,9 @@ case "$1" in
SERVICE_STATUS="service $SERVICE_MYSQLD status" SERVICE_STATUS="service $SERVICE_MYSQLD status"
SERVICE_ENABLE="" SERVICE_ENABLE=""
;; ;;
*)
usage
;;
esac esac
while [ $# -gt 0 ] while [ $# -gt 0 ]
@ -98,7 +96,7 @@ do
-h|--help) -h|--help)
usage usage
;; ;;
-n|--novapw) -p|--password)
shift shift
MYSQL_HEAT_PW=${1} MYSQL_HEAT_PW=${1}
;; ;;
@ -111,7 +109,6 @@ do
;; ;;
*) *)
# ignore # ignore
shift
;; ;;
esac esac
shift shift

View File

@ -34,7 +34,7 @@ Installing OpenStack on Fedora 16
Note: on Fedora 16 you have to enable the `Preview Repository`_ to install the required OpenStack Essex release. Note: on Fedora 16 you have to enable the `Preview Repository`_ to install the required OpenStack Essex release.
A script called "``openstack``" in the tools directory of the repository will install and start OpenStack for you on Fedora 16/17:: A script called "``openstack``" in the tools directory of the repository will install and start OpenStack for you on Fedora 16/17::
./tools/openstack install ./tools/openstack install -y -r ${MYSQL_ROOT_PASSWORD}
If you use this method, you will need to manually create a guest network. How this is done depends on your environment. An example network create operation: If you use this method, you will need to manually create a guest network. How this is done depends on your environment. An example network create operation:
@ -90,9 +90,9 @@ Setup the MySQL database for Heat
:: ::
./bin/heat-db-setup rpm heat-db-setup rpm -y -r ${MYSQL_ROOT_PASSWORD}
Note: the first argument is either ``rpm`` for RPM-based distros (such as Fedora) or ``deb`` for Debian-based distros (such as Ubuntu). Note: the first argument is either ``rpm`` for RPM-based distros (such as Fedora) or ``deb`` for Debian-based distros (such as Ubuntu). To prompt for confirmation when e.g. installing MySQL Server, omit the ``-y`` option. Run ``heat-db-setup --help`` for detailed documentation.
Register heat with keystone Register heat with keystone
--------------------------- ---------------------------
@ -128,7 +128,7 @@ Create a JEOS
:: ::
sudo -E heat jeos_create F16 x86_64 cfntools sudo -E heat -y jeos_create F16 x86_64 cfntools
Note: The ``-E`` option to ``sudo`` preserves the environment, specifically the keystone credentials, when ``jeos_create`` is run as root. Note: The ``-E`` option to ``sudo`` preserves the environment, specifically the keystone credentials, when ``jeos_create`` is run as root.

View File

@ -178,7 +178,7 @@ def jeos_create(options, arguments, jeos_path, cfntools_path):
if image['name'] == distro + '-' + arch + '-' + instance_type: if image['name'] == distro + '-' + arch + '-' + instance_type:
image_registered = True image_registered = True
runoz = None runoz = options.yes and 'y' or None
if os.access(qcow2_filename, os.R_OK): if os.access(qcow2_filename, os.R_OK):
while runoz not in ('y', 'n'): while runoz not in ('y', 'n'):
runoz = raw_input('An existing JEOS was found on disk.' \ runoz = raw_input('An existing JEOS was found on disk.' \

View File

@ -1,8 +1,26 @@
#!/bin/bash #!/bin/bash
cat << EOF | mysql -u root -p
DROP USER 'heat'@'localhost'; DATABASE=heat
DROP USER 'heat'@'%';
DROP DATABASE heat; while [ $# -gt 0 ]; do
case $1 in
heat|nova|keystone|glance)
DATABASE=$1
;;
-r|--rootpw)
shift
MYSQL_ROOT_PW_ARG="--password=$1"
;;
*)
;;
esac
shift
done
cat << EOF | mysql -u root ${MYSQL_ROOT_PW_ARG}
DROP USER '${DATABASE}'@'localhost';
DROP USER '${DATABASE}'@'%';
DROP DATABASE ${DATABASE};
flush privileges; flush privileges;
EOF EOF

View File

@ -7,6 +7,7 @@
# sleep 1 = systemd's definition of start is different from mine # sleep 1 = systemd's definition of start is different from mine
BASE_DIR=`dirname $0`
action=$1 action=$1
if [ -z "$action" ] if [ -z "$action" ]
@ -72,18 +73,9 @@ function os_erase() {
sudo systemctl start mysqld.service sudo systemctl start mysqld.service
sleep 1 sleep 1
cat << EOF | mysql -u root -p $BASE_DIR/heat-db-drop nova $*
DROP USER 'nova'@'localhost'; $BASE_DIR/heat-db-drop keystone $*
DROP USER 'nova'@'%'; $BASE_DIR/heat-db-drop glance $*
DROP USER 'keystone'@'localhost';
DROP USER 'keystone'@'%';
DROP USER 'glance'@'localhost';
DROP USER 'glance'@'%';
DROP DATABASE nova;
DROP DATABASE keystone;
DROP DATABASE glance;
flush privileges;
EOF
sudo vgchange -an nova-volumes sudo vgchange -an nova-volumes
sudo losetup -d /dev/loop0 sudo losetup -d /dev/loop0
@ -100,9 +92,9 @@ function os_install() {
sudo systemctl start mysqld.service sudo systemctl start mysqld.service
sleep 1 sleep 1
# Configure the databases # Configure the databases
sudo openstack-nova-db-setup sudo openstack-nova-db-setup $*
sudo openstack-glance-db-setup sudo openstack-glance-db-setup $*
sudo openstack-keystone-db-setup sudo openstack-keystone-db-setup $*
# Create a keystone RC file # Create a keystone RC file
mkdir -p $HOME/.openstack mkdir -p $HOME/.openstack
@ -143,17 +135,18 @@ EOF
os_start os_start
sleep 1 sleep 1
echo "Installation Complete." echo "Installation Complete."
echo "Testing nova and glance. If any errors are displayed, the install failed." echo "Testing nova and glance. If any errors are displayed, the install failed..."
nova flavor-list nova flavor-list
glance index glance index
echo
echo "note: This tool does not create a network. Creating a network" echo "note: This tool does not create a network. Creating a network"
echo "depends on your environment. An example network create operation:" echo "depends on your environment. An example network create operation:"
echo echo
echo "sudo nova-manage network create demonet 10.0.0.0/24 1 256 --bridge=demonetbr0" echo " sudo nova-manage network create demonet 10.0.0.0/24 1 256 --bridge=demonetbr0"
echo echo
echo "The network range here, should *not* be the one used on your existing physical network." echo -e "The network range here should *not* be one used on your existing physical\n network."
echo "It should be a range dedicated for the network that OpenStack will configure. So if" echo "It should be a range dedicated for the network that OpenStack will configure."
echo "10.0.0.0/24 clashes with your local network, pick another range." echo "If 10.0.0.0/24 clashes with your local network, pick another range."
} }
@ -167,10 +160,12 @@ case $action in
os_stop os_stop
;; ;;
erase) erase)
os_erase shift
os_erase $*
;; ;;
install) install)
os_install shift
os_install $*
;; ;;
status) status)
os_status os_status

View File

@ -1,8 +1,9 @@
#!/bin/bash #!/bin/bash
TOOLS_DIR=`dirname $0` TOOLS_DIR=`dirname $0`
if [ "$1" = "-y" ]; then if [ "$1" = "-y" ] || [ "$1" = "--yes" ]; then
SKIP_ASK=y SKIP_ASK=y
shift
fi fi
user_wants() { user_wants() {
@ -31,12 +32,12 @@ if [ -n "$HEAT_PIDS" ]; then
fi fi
if user_wants 'Drop Heat database tables?'; then if user_wants 'Drop Heat database tables?'; then
$TOOLS_DIR/heat-db-drop $TOOLS_DIR/heat-db-drop $*
echo 1>&2 echo 1>&2
fi fi
if user_wants 'Erase OpenStack installation?'; then if user_wants 'Erase OpenStack installation?'; then
$TOOLS_DIR/openstack erase $TOOLS_DIR/openstack erase $*
echo 1>&2 echo 1>&2
fi fi