2014-06-17 10:29:22 +02:00
|
|
|
# This file contains bash functions that may be used by guest systems (VMs).
|
|
|
|
|
|
|
|
# Sourcing this file calls functions fix_path_env and source_deploy.
|
|
|
|
|
2015-05-03 21:16:16 +05:30
|
|
|
source "$LIB_DIR/functions.sh"
|
2014-06-17 10:29:22 +02:00
|
|
|
source "$LIB_DIR/functions-common-devstack"
|
|
|
|
|
2014-09-08 10:03:37 +02:00
|
|
|
# Make devstack's operating system identification work with nounset
|
|
|
|
function init_os_ident {
|
|
|
|
if [[ -z "${os_PACKAGE:-""}" ]]; then
|
|
|
|
GetOSVersion
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2014-06-17 10:29:22 +02:00
|
|
|
function source_deploy {
|
|
|
|
if [ -n "${VM_SHELL_USER:-}" ]; then
|
|
|
|
# Already sourced
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
if mountpoint -q /vagrant; then
|
|
|
|
source "$CONFIG_DIR/deploy.vagrant"
|
|
|
|
else
|
|
|
|
source "$CONFIG_DIR/deploy.osbash"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
# If our sudo user's PATH is preserved (and does not contain sbin dirs),
|
|
|
|
# some commands won't be found. Observed with Vagrant shell provisioner
|
|
|
|
# scripts using sudo after "su - vagrant".
|
|
|
|
# Adding to the path seems preferable to messing with the vagrant user's
|
|
|
|
# sudoers environment (or working with a separate Vagrant user).
|
|
|
|
|
|
|
|
function fix_path_env {
|
|
|
|
if is_root; then return 0; fi
|
|
|
|
if echo 'echo $PATH'|sudo sh|grep -q '/sbin'; then return 0; fi
|
|
|
|
export PATH=$PATH:/sbin:/usr/sbin:/usr/local/sbin
|
|
|
|
}
|
|
|
|
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
function zero_empty_space {
|
|
|
|
echo "Filling empty disk space with zeros"
|
|
|
|
sudo dd if=/dev/zero of=/filler bs=1M 2>/dev/null || true
|
|
|
|
sudo rm /filler
|
|
|
|
}
|
|
|
|
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
2014-08-04 10:54:40 +02:00
|
|
|
# For guest scripts to let osbash know they are running; used when osbashauto
|
|
|
|
# runs scripts inside of the VM (STATUS_DIR directory must be shared between
|
|
|
|
# host and VM).
|
2014-06-17 10:29:22 +02:00
|
|
|
|
|
|
|
function indicate_current_auto {
|
|
|
|
if [ "${VM_SHELL_USER:-}" = "osbash" ]; then
|
2014-08-30 12:59:36 +02:00
|
|
|
local scr_name=${1:-$(basename "$0")}
|
|
|
|
local fpath=${2:-"/$STATUS_DIR/$scr_name.begin"}
|
2014-06-17 10:29:22 +02:00
|
|
|
mkdir -p "$STATUS_DIR"
|
2014-08-30 12:59:36 +02:00
|
|
|
touch "$fpath"
|
2014-06-17 10:29:22 +02:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
# Debug function to make a script halt execution until a tmp file is removed
|
|
|
|
|
|
|
|
function wait_for_file {
|
2014-08-04 10:34:36 +02:00
|
|
|
# If no argument is passed, use empty string (to pass nounset option)
|
2014-08-30 12:59:36 +02:00
|
|
|
local msg=${1-""}
|
|
|
|
local wait_file=remove_to_continue
|
|
|
|
[ -n "$msg" ] && wait_file=${wait_file}_${msg}
|
|
|
|
touch "/tmp/$wait_file"
|
|
|
|
while [ -e "/tmp/$wait_file" ]; do
|
2014-06-17 10:29:22 +02:00
|
|
|
sleep 1
|
|
|
|
done
|
|
|
|
}
|
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
# Copy stdin/stderr to log file
|
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
function exec_logpath {
|
2014-08-30 12:59:36 +02:00
|
|
|
local log_path=$1
|
2014-06-17 10:29:22 +02:00
|
|
|
|
|
|
|
# Append all stdin and stderr to log file
|
2014-08-30 12:59:36 +02:00
|
|
|
exec > >(tee -a "$log_path") 2>&1
|
2014-06-17 10:29:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function exec_logfile {
|
2014-08-30 12:59:36 +02:00
|
|
|
local log_dir=${1:-/home/$VM_SHELL_USER/log}
|
2014-06-17 10:29:22 +02:00
|
|
|
|
|
|
|
# Default extension is log
|
2014-08-30 12:59:36 +02:00
|
|
|
local ext=${2:-log}
|
2014-06-17 10:29:22 +02:00
|
|
|
|
2014-08-30 12:59:36 +02:00
|
|
|
mkdir -p "$log_dir"
|
2014-06-17 10:29:22 +02:00
|
|
|
|
|
|
|
# Log name based on name of running script
|
2014-08-30 12:59:36 +02:00
|
|
|
local base_name=$(basename "$0" .sh)
|
2014-06-17 10:29:22 +02:00
|
|
|
|
2014-08-30 12:59:36 +02:00
|
|
|
local prefix=$(get_next_prefix "$log_dir" "$ext")
|
|
|
|
local log_name="${prefix}_$base_name.$ext"
|
2014-06-17 10:29:22 +02:00
|
|
|
|
2014-08-30 12:59:36 +02:00
|
|
|
exec_logpath "$log_dir/$log_name"
|
2014-06-17 10:29:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
# Functions that need to run as root
|
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
function as_root_fix_mount_vboxsf_link {
|
2014-08-30 12:59:36 +02:00
|
|
|
local file=/sbin/mount.vboxsf
|
|
|
|
if [ -L $file -a ! -e $file ]; then
|
|
|
|
echo "$file is a broken symlink. Trying to fix it."
|
2014-06-17 10:29:22 +02:00
|
|
|
shopt -s nullglob
|
2014-08-30 12:59:36 +02:00
|
|
|
local new=(/opt/VBoxGuestAdditions*/lib/VBoxGuestAdditions)
|
|
|
|
if [ -n "$new" ]; then
|
|
|
|
ln -sv "$new" /usr/lib/VBoxGuestAdditions
|
2014-06-17 10:29:22 +02:00
|
|
|
else
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function as_root_inject_sudoer {
|
|
|
|
if grep -q "${VM_SHELL_USER}" /etc/sudoers; then
|
|
|
|
echo "${VM_SHELL_USER} already in /etc/sudoers"
|
|
|
|
else
|
|
|
|
echo "${VM_SHELL_USER} ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
|
|
|
|
echo "Defaults:${VM_SHELL_USER} !requiretty" >> /etc/sudoers
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# Change to a regular user to execute a guest script (and log its output)
|
|
|
|
|
|
|
|
function as_root_exec_script {
|
2014-08-30 12:59:36 +02:00
|
|
|
local script_path=$1
|
|
|
|
local script_name="$(basename "$script_path" .sh)"
|
2014-06-17 10:29:22 +02:00
|
|
|
|
2014-08-30 12:59:36 +02:00
|
|
|
echo "$(date) start $script_path"
|
2014-06-17 10:29:22 +02:00
|
|
|
|
2014-08-30 12:59:36 +02:00
|
|
|
local prefix=$(get_next_prefix "$LOG_DIR" "auto")
|
|
|
|
local log_path=$LOG_DIR/${prefix}_$script_name.auto
|
2014-06-17 10:29:22 +02:00
|
|
|
|
2014-08-30 12:59:36 +02:00
|
|
|
su - "$VM_SHELL_USER" -c "bash $script_path" >"$log_path" 2>&1
|
2014-09-10 12:19:15 +02:00
|
|
|
local rc=$?
|
|
|
|
if [ $rc -ne 0 ]; then
|
|
|
|
echo "$(date) ERROR: status $rc for $script_path" |
|
|
|
|
tee >&2 -a "$LOG_DIR/error.log"
|
|
|
|
else
|
|
|
|
echo "$(date) done"
|
|
|
|
fi
|
|
|
|
return $rc
|
2014-06-17 10:29:22 +02:00
|
|
|
}
|
|
|
|
|
2014-07-28 14:41:45 +02:00
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
# Root wrapper around devstack function for manipulating config files
|
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
function iniset_sudo {
|
|
|
|
local file=$1
|
|
|
|
shift
|
|
|
|
local tmpfile=$(mktemp)
|
|
|
|
# Create a temporary copy, work on it, and copy it back into place
|
2014-07-31 13:15:52 +02:00
|
|
|
sudo cp -fv "$file" "$tmpfile"
|
2014-07-28 14:41:45 +02:00
|
|
|
iniset "$tmpfile" "$@"
|
|
|
|
cat "$tmpfile" | sudo tee "$file" >/dev/null
|
|
|
|
}
|
|
|
|
|
2015-04-15 20:17:04 +05:30
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
# Functions for manipulating config files without section
|
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
function iniset_sudo_no_section {
|
|
|
|
local file=$1
|
|
|
|
shift
|
|
|
|
local tmpfile=$(mktemp)
|
|
|
|
# Create a temporary copy, work on it, and copy it back into place
|
|
|
|
sudo cp -fv "$file" "$tmpfile"
|
|
|
|
iniset_no_section "$tmpfile" "$@"
|
|
|
|
cat "$tmpfile" | sudo tee "$file" >/dev/null
|
|
|
|
}
|
|
|
|
|
|
|
|
# ini_has_option_no_section config-file option
|
|
|
|
function ini_has_option_no_section {
|
|
|
|
local xtrace=$(set +o | grep xtrace)
|
|
|
|
set +o xtrace
|
|
|
|
local file=$1
|
|
|
|
local option=$2
|
|
|
|
local line
|
|
|
|
line=$(sed -ne "/^$option[ \t]*=/ p;" "$file")
|
|
|
|
$xtrace
|
|
|
|
[ -n "$line" ]
|
|
|
|
}
|
|
|
|
|
|
|
|
# Set an option in an INI file
|
|
|
|
# iniset_no_section config-file option value
|
|
|
|
function iniset_no_section {
|
|
|
|
local xtrace=$(set +o | grep xtrace)
|
|
|
|
set +o xtrace
|
|
|
|
local file=$1
|
|
|
|
local option=$2
|
|
|
|
local value=$3
|
|
|
|
|
|
|
|
[[ -z $option ]] && return
|
|
|
|
|
|
|
|
if ! ini_has_option_no_section "$file" "$option"; then
|
|
|
|
# Add it
|
|
|
|
sed -i -e "1 i\
|
|
|
|
$option = $value
|
|
|
|
" "$file"
|
|
|
|
else
|
|
|
|
local sep=$(echo -ne "\x01")
|
|
|
|
# Replace it
|
|
|
|
sed -i -e "/$option/ c\
|
|
|
|
$option = $value
|
|
|
|
" "$file"
|
|
|
|
fi
|
|
|
|
$xtrace
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-07-28 17:02:54 +05:30
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
# OpenStack helpers
|
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
function mysql_exe {
|
|
|
|
local cmd="$1"
|
|
|
|
echo "MySQL cmd: $cmd."
|
|
|
|
mysql -u "root" -p"$DATABASE_PASSWORD" -e "$cmd"
|
|
|
|
}
|
|
|
|
|
|
|
|
function setup_database {
|
|
|
|
local service=$1
|
2014-08-09 08:23:03 +02:00
|
|
|
local db_user=$(service_to_db_user $service)
|
|
|
|
local db_password=$(service_to_db_password $service)
|
2014-07-28 17:02:54 +05:30
|
|
|
mysql_exe "CREATE DATABASE $service"
|
2014-08-09 08:23:03 +02:00
|
|
|
mysql_exe "GRANT ALL ON ${service}.* TO '$db_user'@'%' IDENTIFIED BY '$db_password';"
|
2014-11-19 15:35:59 +05:30
|
|
|
mysql_exe "GRANT ALL ON ${service}.* TO '$db_user'@'localhost' IDENTIFIED BY '$db_password';"
|
2014-07-28 17:02:54 +05:30
|
|
|
}
|
|
|
|
|
2014-08-09 08:23:03 +02:00
|
|
|
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
# Users for service-specific MySQL databases
|
|
|
|
|
|
|
|
function service_to_db_user {
|
2014-07-28 17:02:54 +05:30
|
|
|
local service_name=$1
|
|
|
|
echo "${service_name}User"
|
|
|
|
}
|
|
|
|
|
2014-08-09 08:23:03 +02:00
|
|
|
function service_to_db_password {
|
2014-07-28 17:02:54 +05:30
|
|
|
local service_name=$1
|
|
|
|
echo "${service_name}Pass"
|
|
|
|
}
|
|
|
|
|
2014-08-09 08:23:03 +02:00
|
|
|
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
# Service-specific users in keystone
|
|
|
|
|
|
|
|
function service_to_user_name {
|
|
|
|
local service_name=$1
|
|
|
|
echo "${service_name}"
|
|
|
|
}
|
|
|
|
|
|
|
|
function service_to_user_password {
|
|
|
|
local service_name=$1
|
|
|
|
echo "${service_name}_pass"
|
|
|
|
}
|
|
|
|
|
2014-06-17 10:29:22 +02:00
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
# Network configuration
|
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
# Fedora /etc/sysconfig/network-scripts/ifcfg-* configuration
|
|
|
|
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
|
|
|
|
function _ifnum_to_ifname_fedora {
|
2014-08-30 12:59:36 +02:00
|
|
|
local if_num=$1
|
|
|
|
local -a if_names=('p2p1' 'p7p1' 'p8p1' 'p9p1')
|
2014-06-17 10:29:22 +02:00
|
|
|
|
2014-08-30 12:59:36 +02:00
|
|
|
echo "${if_names[$if_num]}"
|
2014-06-17 10:29:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function _config_sysconfig_nat {
|
2014-08-30 12:59:36 +02:00
|
|
|
local if_num=$1
|
2014-06-17 10:29:22 +02:00
|
|
|
|
2014-08-30 12:59:36 +02:00
|
|
|
local if_name="$(_ifnum_to_ifname_fedora "$if_num")"
|
2014-06-17 10:29:22 +02:00
|
|
|
|
2014-08-30 12:59:36 +02:00
|
|
|
local if_file=/etc/sysconfig/network-scripts/ifcfg-$if_name
|
2014-06-17 10:29:22 +02:00
|
|
|
|
|
|
|
sed -e "
|
2014-08-30 12:59:36 +02:00
|
|
|
s,%IF_NAME%,$if_name,g;
|
|
|
|
" "$TEMPLATE_DIR/template-fedora-ifcfg-nat" | sudo tee "$if_file"
|
2014-06-17 10:29:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function _config_sysconfig_hostonly {
|
2014-08-30 12:59:36 +02:00
|
|
|
local if_num=$1
|
|
|
|
local ip_address=$2
|
2014-06-17 10:29:22 +02:00
|
|
|
|
2014-08-30 12:59:36 +02:00
|
|
|
local if_name="$(_ifnum_to_ifname_fedora "$if_num")"
|
2014-06-17 10:29:22 +02:00
|
|
|
|
2014-08-30 12:59:36 +02:00
|
|
|
local if_file=/etc/sysconfig/network-scripts/ifcfg-$if_name
|
2014-06-17 10:29:22 +02:00
|
|
|
|
|
|
|
sed -e "
|
2014-08-30 12:59:36 +02:00
|
|
|
s,%IF_NAME%,$if_name,g;
|
|
|
|
s,%IP_ADDRESS%,$ip_address,g;
|
|
|
|
" "$TEMPLATE_DIR/template-fedora-ifcfg-hostonly" | sudo tee "$if_file"
|
2014-06-17 10:29:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
# Ubuntu /etc/network/interfaces configuration
|
|
|
|
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
|
|
|
|
readonly UBUNTU_IF_FILE=/etc/network/interfaces
|
|
|
|
|
|
|
|
function _ifnum_to_ifname_ubuntu {
|
2014-08-30 12:59:36 +02:00
|
|
|
local if_num=$1
|
|
|
|
local -a if_names=('eth0' 'eth1' 'eth2' 'eth3')
|
2014-06-17 10:29:22 +02:00
|
|
|
|
2014-08-30 12:59:36 +02:00
|
|
|
echo "${if_names[$if_num]}"
|
2014-06-17 10:29:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function _config_interfaces_nat {
|
2014-08-30 12:59:36 +02:00
|
|
|
local if_num=$1
|
2014-06-17 10:29:22 +02:00
|
|
|
|
2014-08-30 12:59:36 +02:00
|
|
|
local if_name="$(_ifnum_to_ifname_ubuntu "$if_num")"
|
2014-06-17 10:29:22 +02:00
|
|
|
|
|
|
|
# Empty line before this entry
|
|
|
|
echo | sudo tee -a "$UBUNTU_IF_FILE"
|
|
|
|
|
|
|
|
sed -e "
|
2014-08-30 12:59:36 +02:00
|
|
|
s,%IF_NAME%,$if_name,g;
|
2014-06-17 10:29:22 +02:00
|
|
|
" "$TEMPLATE_DIR/template-ubuntu-interfaces-nat" | sudo tee -a "$UBUNTU_IF_FILE"
|
|
|
|
}
|
|
|
|
|
|
|
|
function _config_interfaces_hostonly {
|
2014-08-30 12:59:36 +02:00
|
|
|
local if_num=$1
|
|
|
|
local ip_address=$2
|
2014-06-17 10:29:22 +02:00
|
|
|
|
2014-08-30 12:59:36 +02:00
|
|
|
local if_name="$(_ifnum_to_ifname_ubuntu "$if_num")"
|
2014-06-17 10:29:22 +02:00
|
|
|
|
|
|
|
# Empty line before this entry
|
|
|
|
echo | sudo tee -a "$UBUNTU_IF_FILE"
|
|
|
|
|
|
|
|
sed -e "
|
2014-08-30 12:59:36 +02:00
|
|
|
s,%IF_NAME%,$if_name,g;
|
|
|
|
s,%IP_ADDRESS%,$ip_address,g;
|
2014-06-17 10:29:22 +02:00
|
|
|
" "$TEMPLATE_DIR/template-ubuntu-interfaces-hostonly" | sudo tee -a "$UBUNTU_IF_FILE"
|
|
|
|
}
|
|
|
|
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
function config_nat {
|
2014-08-30 12:59:36 +02:00
|
|
|
local if_num=$1
|
2014-06-17 10:29:22 +02:00
|
|
|
|
2014-09-08 10:03:37 +02:00
|
|
|
init_os_ident
|
2014-06-17 10:29:22 +02:00
|
|
|
if is_fedora; then
|
2014-08-30 12:59:36 +02:00
|
|
|
echo _config_sysconfig_nat "$if_num"
|
|
|
|
_config_sysconfig_nat "$if_num"
|
2014-06-17 10:29:22 +02:00
|
|
|
else
|
2014-08-30 12:59:36 +02:00
|
|
|
echo _config_interfaces_nat "$if_num"
|
|
|
|
_config_interfaces_nat "$if_num"
|
2014-06-17 10:29:22 +02:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function config_hostonly {
|
2014-08-30 12:59:36 +02:00
|
|
|
local if_num=$1
|
|
|
|
local ip_address=$2
|
2014-06-17 10:29:22 +02:00
|
|
|
|
2014-09-08 10:03:37 +02:00
|
|
|
init_os_ident
|
2014-06-17 10:29:22 +02:00
|
|
|
if is_fedora; then
|
2014-08-30 12:59:36 +02:00
|
|
|
echo _config_sysconfig_hostonly "$if_num" "$ip_address"
|
|
|
|
_config_sysconfig_hostonly "$if_num" "$ip_address"
|
2014-06-17 10:29:22 +02:00
|
|
|
else
|
2014-08-30 12:59:36 +02:00
|
|
|
echo _config_interfaces_hostonly "$if_num" "$ip_address"
|
|
|
|
_config_interfaces_hostonly "$if_num" "$ip_address"
|
2014-06-17 10:29:22 +02:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function get_ip_from_net_and_fourth {
|
2014-08-30 12:59:36 +02:00
|
|
|
local net_name=$1
|
|
|
|
local net="${!net_name}"
|
|
|
|
local fourth_octet=$2
|
2014-06-17 10:29:22 +02:00
|
|
|
|
2014-08-30 12:59:36 +02:00
|
|
|
echo "${net%.*}.$fourth_octet"
|
2014-06-17 10:29:22 +02:00
|
|
|
}
|
|
|
|
|
2014-08-19 08:54:56 +02:00
|
|
|
function hostname_to_ip {
|
|
|
|
local host_name=$1
|
|
|
|
getent hosts "$host_name"|awk '{print $1}'
|
|
|
|
}
|
|
|
|
|
2014-06-17 10:29:22 +02:00
|
|
|
function config_network {
|
2014-09-08 10:03:37 +02:00
|
|
|
init_os_ident
|
2014-06-17 10:29:22 +02:00
|
|
|
if is_ubuntu; then
|
|
|
|
# Configuration functions will append to this file
|
|
|
|
sudo cp -v "$TEMPLATE_DIR/template-ubuntu-interfaces-loopback" \
|
|
|
|
"$UBUNTU_IF_FILE"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Get FOURTH_OCTET and network interfaces (NET_IF_?) for this node
|
|
|
|
unset -v NET_IF_0 NET_IF_1 NET_IF_2 NET_IF_3
|
|
|
|
source "$CONFIG_DIR/config.$(hostname)"
|
|
|
|
|
|
|
|
# Get API_NET, DATA_NET, MGMT_NET
|
|
|
|
source "$CONFIG_DIR/openstack"
|
|
|
|
|
|
|
|
# Iterate over all NET_IF_? variables
|
2014-08-30 12:59:36 +02:00
|
|
|
local net_ifs=( "${!NET_IF_@}" )
|
|
|
|
local net_if=""
|
|
|
|
for net_if in "${net_ifs[@]}"; do
|
|
|
|
echo >&2 -n "${net_if} ${!net_if}"
|
|
|
|
local if_num=${net_if##*_}
|
|
|
|
if [ "${!net_if}" = "nat" ]; then
|
2014-06-17 10:29:22 +02:00
|
|
|
echo >&2
|
2014-08-30 12:59:36 +02:00
|
|
|
config_nat "$if_num"
|
2014-06-17 10:29:22 +02:00
|
|
|
else
|
2014-08-30 12:59:36 +02:00
|
|
|
# Host-only network: net_if is net name (e.g. API_NET)
|
2014-06-17 10:29:22 +02:00
|
|
|
# Use corresponding value (e.g. 192.168.100.1)
|
2014-08-30 12:59:36 +02:00
|
|
|
IP="$(get_ip_from_net_and_fourth "${!net_if}" "$FOURTH_OCTET")"
|
2014-06-17 10:29:22 +02:00
|
|
|
echo >&2 " $IP"
|
|
|
|
|
2014-08-30 12:59:36 +02:00
|
|
|
config_hostonly "$if_num" "$IP"
|
2014-06-17 10:29:22 +02:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2015-01-19 20:34:29 +01:00
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
# ssh wrapper functions
|
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
function no_chk_ssh {
|
|
|
|
echo >&2 "ssh $@"
|
|
|
|
# Options set to disable strict host key checking and related messages.
|
|
|
|
ssh \
|
|
|
|
-o "UserKnownHostsFile /dev/null" \
|
|
|
|
-o "StrictHostKeyChecking no" \
|
|
|
|
-o LogLevel=error \
|
|
|
|
"$@"
|
|
|
|
}
|
|
|
|
|
|
|
|
# ssh from one node VM to another node in the cluster
|
|
|
|
function node_ssh {
|
2015-02-24 17:53:40 +05:30
|
|
|
no_chk_ssh -i "$HOME/.ssh/osbash_key" "$@"
|
2015-01-19 20:34:29 +01:00
|
|
|
}
|
|
|
|
|
2014-06-17 10:29:22 +02:00
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
fix_path_env
|
|
|
|
source_deploy
|
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
# vim: set ai ts=4 sw=4 et ft=sh:
|