Added support to deploy product on remote machine via ssh
It is useful in case if there is 2 machines: the main that has limited resources and used only for development and the second, that has enough resources to use it for deployment. enable feature VRDP for virtual machine Change-Id: Ib34a188311cc04250d29e685bf5b9f12ac2aeb05 Closes-Bug: #1491925
This commit is contained in:
parent
50a6a0a2ca
commit
ca5a2adfcf
|
@ -22,3 +22,12 @@ If there are any errors, the script will report them and abort.
|
|||
If you want to change settings (number of OpenStack nodes, CPU, RAM, HDD), please refer to "config.sh".
|
||||
|
||||
To shutdown VMs and clean environment just run "./clean.sh"
|
||||
|
||||
To deploy on a remote machine just set environment variable REMOTE_HOST with ssh connection string.
|
||||
The variable REMOTE_PORT allows to specify custom port for ssh.
|
||||
|
||||
```bash
|
||||
REMOTE_HOST=user@user.mos.mirantis.net ./launch_8GB.sh
|
||||
# or
|
||||
REMOTE_HOST=user@user.mos.mirantis.net REMOTE_PORT=23 ./launch_8GB.sh
|
||||
```
|
||||
|
|
|
@ -26,11 +26,12 @@
|
|||
source ./config.sh
|
||||
source ./functions/vm.sh
|
||||
source ./functions/network.sh
|
||||
source ./functions/shell.sh
|
||||
|
||||
# Check for procps package
|
||||
if [ "$(uname -s | cut -c1-6)" = "CYGWIN" ]; then
|
||||
if [ "$(execute uname -s | cut -c1-6)" = "CYGWIN" ]; then
|
||||
echo -n "Checking for 'free'... "
|
||||
type free >/dev/null 2>&1
|
||||
execute type free >/dev/null 2>&1
|
||||
if [ $? -eq 1 ]; then
|
||||
echo "\"free\" is not available in the path, but it's required. Please install the \"procps\" package. Aborting."
|
||||
exit 1
|
||||
|
@ -41,7 +42,7 @@ fi
|
|||
|
||||
# Check for expect
|
||||
echo -n "Checking for 'expect'... "
|
||||
type expect >/dev/null 2>&1
|
||||
execute type expect >/dev/null 2>&1
|
||||
if [ $? -eq 1 ]; then
|
||||
echo "\"expect\" is not available in the path, but it's required. Please install Tcl \"expect\" package. Aborting."
|
||||
exit 1
|
||||
|
@ -53,7 +54,7 @@ fi
|
|||
echo "If you run this script under Cygwin, you may have to add path to VirtualBox directory to your PATH. "
|
||||
echo "Usually it is enough to run \"export PATH=\$PATH:\"/cygdrive/c/Program Files/Oracle/VirtualBox\" "
|
||||
echo -n "Checking for \"VBoxManage\"... "
|
||||
type VBoxManage >/dev/null 2>&1
|
||||
execute type VBoxManage >/dev/null 2>&1
|
||||
if [ $? -eq 1 ]; then
|
||||
echo "\"VBoxManage\" is not available in the path, but it's required. Likely, VirtualBox is not installed. Aborting."
|
||||
exit 1
|
||||
|
@ -63,7 +64,7 @@ fi
|
|||
|
||||
# Check for VirtualBox Extension Pack
|
||||
echo -n "Checking for VirtualBox Extension Pack... "
|
||||
extpacks=`VBoxManage list extpacks | grep 'Usable' | grep 'true' | wc -l`
|
||||
extpacks=`execute VBoxManage list extpacks | grep 'Usable' | grep 'true' | wc -l`
|
||||
if [ "$extpacks" -le 0 ]; then
|
||||
echo >&2 "VirtualBox Extension Pack is not installed. Please, download and install it from the official VirtualBox web site at https://www.virtualbox.org/wiki/Downloads"; exit 1;
|
||||
fi
|
||||
|
@ -78,9 +79,12 @@ fi
|
|||
echo "OK"
|
||||
echo "Going to use Mirantis OpenStack ISO file $iso_path"
|
||||
|
||||
# Copy ISO to host
|
||||
copy_if_required $iso_path
|
||||
|
||||
# Check if SSH is installed. Cygwin does not install SSH by default.
|
||||
echo -n "Checking if SSH client installed... "
|
||||
type ssh >/dev/null 2>&1
|
||||
execute type ssh >/dev/null 2>&1
|
||||
if [ $? -eq 1 ]; then
|
||||
echo "SSH client is not installed. Please install the \"openssh\" package if you run this script under Cygwin. Aborting."
|
||||
exit 1
|
||||
|
@ -89,9 +93,9 @@ else
|
|||
fi
|
||||
|
||||
echo -n "Checking if ipconfig or ifconfig installed... "
|
||||
case "$(uname)" in
|
||||
case "$(execute uname)" in
|
||||
Linux | Darwin)
|
||||
if [ ! -x /sbin/ifconfig ] ; then
|
||||
if ! execute test -x /sbin/ifconfig ; then
|
||||
echo "No ifconfig available at /sbin/ifconfig path! This path is hard-coded into VBoxNetAdpCtl utility."
|
||||
echo "Please install ifconfig or create symlink to proper interface configuration utility. Aborting."
|
||||
exit 1
|
||||
|
@ -100,14 +104,14 @@ case "$(uname)" in
|
|||
CYGWIN*)
|
||||
# Cygwin does not use ifconfig at all and even has no link to it.
|
||||
# It uses built-in Windows ipconfig utility instead.
|
||||
type ipconfig >/dev/null 2>&1
|
||||
execute type ipconfig >/dev/null 2>&1
|
||||
if [ $? -eq 1 ]; then
|
||||
echo "No ipconfig available in Cygwin environment. Please check you can run ipconfig from Cygwin command prompt. Aborting."
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
echo "$(uname) is not supported operating system."
|
||||
echo "$(execute uname) is not supported operating system."
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
|
11
config.sh
11
config.sh
|
@ -15,6 +15,7 @@
|
|||
# under the License.
|
||||
|
||||
source ./functions/memory.sh
|
||||
source ./functions/shell.sh
|
||||
|
||||
# Get the first available ISO from the directory 'iso'
|
||||
iso_path=`ls -1t iso/*.iso 2>/dev/null | head -1`
|
||||
|
@ -42,10 +43,10 @@ fuel_master_ips="10.20.0.1 172.16.0.254 172.16.1.1"
|
|||
mask="255.255.255.0"
|
||||
|
||||
# Determining the type of operating system and adding CPU core to the master node
|
||||
case "$(uname)" in
|
||||
case "$(execute uname)" in
|
||||
Linux)
|
||||
os_type="linux"
|
||||
if [ "$(nproc)" -gt "1" ]; then
|
||||
if [ "$(execute nproc)" -gt "1" ]; then
|
||||
vm_master_cpu_cores=2
|
||||
else
|
||||
vm_master_cpu_cores=1
|
||||
|
@ -53,7 +54,7 @@ mask="255.255.255.0"
|
|||
;;
|
||||
Darwin)
|
||||
os_type="darwin"
|
||||
mac_nproc=`sysctl -a | grep machdep.cpu.thread_count | sed 's/^machdep.cpu.thread_count\:[ \t]*//'`
|
||||
mac_nproc=`execute sysctl -a | grep machdep.cpu.thread_count | sed 's/^machdep.cpu.thread_count\:[ \t]*//'`
|
||||
if [ "$mac_nproc" -gt "1" ]; then
|
||||
vm_master_cpu_cores=2
|
||||
else
|
||||
|
@ -62,14 +63,14 @@ mask="255.255.255.0"
|
|||
;;
|
||||
CYGWIN*)
|
||||
os_type="cygwin"
|
||||
if [ "$(nproc)" -gt "1" ]; then
|
||||
if [ "$(execute nproc)" -gt "1" ]; then
|
||||
vm_master_cpu_cores=2
|
||||
else
|
||||
vm_master_cpu_cores=1
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
echo "$(uname) is not supported operating system."
|
||||
echo "$(execute uname) is not supported operating system."
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
|
|
@ -16,14 +16,16 @@
|
|||
|
||||
# This file contains the functions to get available memory on host PC
|
||||
|
||||
source ./functions/shell.sh
|
||||
|
||||
get_available_memory() {
|
||||
local total_memory
|
||||
case $(uname) in
|
||||
case $(execute uname) in
|
||||
Linux | CYGWIN*)
|
||||
total_memory=$(LANG=C free | grep Mem | awk '{print $2}')
|
||||
total_memory=$(execute LANG=C free | grep Mem | awk '{print $2}')
|
||||
;;
|
||||
Darwin)
|
||||
total_memory=$(sysctl -n hw.memsize)
|
||||
total_memory=$(execute sysctl -n hw.memsize)
|
||||
total_memory=$(( $total_memory / 1024 ))
|
||||
;;
|
||||
*)
|
||||
|
|
|
@ -16,8 +16,10 @@
|
|||
|
||||
# This file contains the functions to manage host-only interfaces in the system
|
||||
|
||||
source ./functions/shell.sh
|
||||
|
||||
get_hostonly_interfaces() {
|
||||
echo -e `VBoxManage list hostonlyifs | grep '^Name' | sed 's/^Name\:[ \t]*//' | uniq | tr "\\n" ","`
|
||||
echo -e `execute VBoxManage list hostonlyifs | grep '^Name' | sed 's/^Name\:[ \t]*//' | uniq | tr "\\n" ","`
|
||||
}
|
||||
|
||||
get_fuel_ifaces() {
|
||||
|
@ -30,7 +32,7 @@ get_fuel_ifaces() {
|
|||
fuel_networks+="$fuel_network "
|
||||
done
|
||||
for ip in $fuel_networks; do
|
||||
fuel_iface=`VBoxManage list hostonlyifs | grep -B5 $ip | grep '^Name' | sed 's/^Name\:[ \t]*//' | uniq | tr "\\n" ","`
|
||||
fuel_iface=`execute VBoxManage list hostonlyifs | grep -B5 $ip | grep '^Name' | sed 's/^Name\:[ \t]*//' | uniq | tr "\\n" ","`
|
||||
fuel_ifaces+="$fuel_iface"
|
||||
done
|
||||
echo $fuel_ifaces
|
||||
|
@ -53,7 +55,7 @@ is_hostonly_interface_present() {
|
|||
# String comparison with IF works different in Cygwin, probably due to encoding.
|
||||
# So, reduced Case is used. since it works the same way.
|
||||
# Default divider character change is mandatory for Cygwin.
|
||||
case "$(uname)" in
|
||||
case "$(execute uname)" in
|
||||
CYGWIN*)
|
||||
OIFS=$IFS
|
||||
IFS=","
|
||||
|
@ -62,9 +64,9 @@ is_hostonly_interface_present() {
|
|||
;;
|
||||
esac
|
||||
# Call VBoxManage directly instead of function, due to changed IFS
|
||||
local found_iface=(`VBoxManage list hostonlyifs | grep -E "Name: + $name\$" | awk '/Name/ { $1 = ""; print substr($0, 2) }'`)
|
||||
local found_iface=(`execute VBoxManage list hostonlyifs | grep -E "Name: + $name\$" | awk '/Name/ { $1 = ""; print substr($0, 2) }'`)
|
||||
# Change default divider back
|
||||
case "$(uname)" in
|
||||
case "$(execute uname)" in
|
||||
CYGWIN*)
|
||||
IFS=$OIFS
|
||||
;;
|
||||
|
@ -85,7 +87,7 @@ check_if_iface_settings_applied() {
|
|||
mask=$3
|
||||
echo "Verifying interface $name has IP $ip and mask $mask properly set."
|
||||
# Please leave 12 spaces in place - these are placed intentionally
|
||||
case "$(uname)" in
|
||||
case "$(execute uname)" in
|
||||
CYGWIN*)
|
||||
OIFS=$IFS
|
||||
IFS=","
|
||||
|
@ -93,17 +95,17 @@ check_if_iface_settings_applied() {
|
|||
*)
|
||||
;;
|
||||
esac
|
||||
local new_name=(`VBoxManage list hostonlyifs | egrep -A9 "Name: $name\$" | awk '/Name/ { $1 = ""; print substr($0, 2) }'`)
|
||||
case "$(uname)" in
|
||||
local new_name=(`execute VBoxManage list hostonlyifs | egrep -A9 "Name: $name\$" | awk '/Name/ { $1 = ""; print substr($0, 2) }'`)
|
||||
case "$(execute uname)" in
|
||||
CYGWIN*)
|
||||
IFS=$OIFS
|
||||
;;
|
||||
*)
|
||||
;;
|
||||
esac
|
||||
local new_ip=(`VBoxManage list hostonlyifs | egrep -A9 "Name: $name\$" | awk '/IPAddress:/ {print $2}'`)
|
||||
local new_mask=(`VBoxManage list hostonlyifs | egrep -A9 "Name: $name\$" | awk '/NetworkMask:/ {print $2}'`)
|
||||
local new_dhcp=(`VBoxManage list hostonlyifs | egrep -A9 "Name: $name\$" | awk '/DHCP:/ {print $2}'`)
|
||||
local new_ip=(`execute VBoxManage list hostonlyifs | egrep -A9 "Name: $name\$" | awk '/IPAddress:/ {print $2}'`)
|
||||
local new_mask=(`execute VBoxManage list hostonlyifs | egrep -A9 "Name: $name\$" | awk '/NetworkMask:/ {print $2}'`)
|
||||
local new_dhcp=(`execute VBoxManage list hostonlyifs | egrep -A9 "Name: $name\$" | awk '/DHCP:/ {print $2}'`)
|
||||
# First verify if we checking correct interface
|
||||
if [[ "$name" != "$new_name" ]]; then
|
||||
echo "Checking $name but found settings for $new_name"
|
||||
|
@ -129,7 +131,7 @@ create_hostonly_interfaces() {
|
|||
# Creating host-only interface
|
||||
local ip=$1
|
||||
echo "Creating host-only interface"
|
||||
local id=`VBoxManage hostonlyif create | sed "s/'/_/g" | cut -d "_" -f2 | sed "s/^_//" | sed "s/_$//"`
|
||||
local id=`execute VBoxManage hostonlyif create | sed "s/'/_/g" | cut -d "_" -f2 | sed "s/^_//" | sed "s/_$//"`
|
||||
# If it does not exist after creation, let's abort
|
||||
if ! is_hostonly_interface_present "$id"; then
|
||||
echo "Fatal error. Interface $id does not exist after creation. Exiting"
|
||||
|
@ -142,12 +144,12 @@ create_hostonly_interfaces() {
|
|||
# These magic 1 second sleeps around DHCP config are required under Windows/Cygwin
|
||||
# due to VBoxSvc COM server accepts next request before previous one is actually finished.
|
||||
sleep 1s
|
||||
VBoxManage dhcpserver remove --ifname "$name" 2>/dev/null
|
||||
execute VBoxManage dhcpserver remove --ifname "$name" 2>/dev/null
|
||||
sleep 1s
|
||||
# Set up IP address and network mask
|
||||
echo "Configuring IP address $ip and network mask $mask on interface: $name..."
|
||||
set -x
|
||||
VBoxManage hostonlyif ipconfig "$id" --ip $ip --netmask $mask
|
||||
execute VBoxManage hostonlyif ipconfig "$id" --ip $ip --netmask $mask
|
||||
set +x
|
||||
# Check what we have created actually.
|
||||
# Sometimes VBox occasionally fails to apply settings to the last IFace under Windows
|
||||
|
@ -181,7 +183,7 @@ delete_fuel_ifaces() {
|
|||
for interface in $fuel_ifaces; do
|
||||
IFS=$OIFS
|
||||
echo "Deleting host-only interface: $interface..."
|
||||
VBoxManage hostonlyif remove "$interface"
|
||||
execute VBoxManage hostonlyif remove "$interface"
|
||||
check_removed_iface "$interface"
|
||||
done
|
||||
fi
|
||||
|
@ -192,11 +194,11 @@ delete_all_hostonly_interfaces() {
|
|||
local all_hostonly_interfaces=$(get_hostonly_interfaces)
|
||||
# Checking that the running virtual machines don't use removable host-only interfaces
|
||||
check_running_vms "$all_hostonly_interfaces"
|
||||
OIFS=$IFS;IFS=",";list=(`VBoxManage list hostonlyifs | grep '^Name' | sed 's/^Name\:[ \t]*//' | uniq | tr "\\n" ","`);IFS=$OIFS
|
||||
OIFS=$IFS;IFS=",";list=(`execute VBoxManage list hostonlyifs | grep '^Name' | sed 's/^Name\:[ \t]*//' | uniq | tr "\\n" ","`);IFS=$OIFS
|
||||
# Delete every single hostonly interface in the system
|
||||
for interface in "${list[@]}"; do
|
||||
echo "Deleting host-only interface: $interface..."
|
||||
VBoxManage hostonlyif remove "$interface"
|
||||
execute VBoxManage hostonlyif remove "$interface"
|
||||
check_removed_iface "$interface"
|
||||
done
|
||||
}
|
||||
|
|
|
@ -18,6 +18,8 @@
|
|||
# and Fuel became operational, and also enabling outbound network/internet access for this VM through the
|
||||
# host system
|
||||
|
||||
source ./functions/shell.sh
|
||||
|
||||
ssh_options='-oConnectTimeout=5 -oStrictHostKeyChecking=no -oCheckHostIP=no -oUserKnownHostsFile=/dev/null -oRSAAuthentication=no -oPubkeyAuthentication=no'
|
||||
|
||||
wait_for_fuel_menu() {
|
||||
|
@ -49,7 +51,7 @@ skip_fuel_menu() {
|
|||
# Log in into the VM, see if Fuel Setup is running or puppet already started
|
||||
# Looks a bit ugly, but 'end of expect' has to be in the very beginning of the line
|
||||
result=$(
|
||||
expect << ENDOFEXPECT
|
||||
execute expect << ENDOFEXPECT
|
||||
spawn ssh $ssh_options $username@$ip
|
||||
expect "connect to host" exit
|
||||
expect "*?assword:*"
|
||||
|
@ -61,7 +63,7 @@ ENDOFEXPECT
|
|||
)
|
||||
if [[ "$result" =~ "returns 0" ]]; then
|
||||
echo "Skipping Fuel Setup..."
|
||||
expect << ENDOFEXPECT
|
||||
execute expect << ENDOFEXPECT
|
||||
spawn ssh $ssh_options $username@$ip
|
||||
expect "connect to host" exit
|
||||
expect "*?assword:*"
|
||||
|
@ -85,7 +87,7 @@ is_product_vm_operational() {
|
|||
# Log in into the VM, see if Puppet has completed its run
|
||||
# Looks a bit ugly, but 'end of expect' has to be in the very beginning of the line
|
||||
result=$(
|
||||
expect << ENDOFEXPECT
|
||||
execute expect << ENDOFEXPECT
|
||||
spawn ssh $ssh_options $username@$ip
|
||||
expect "connect to host" exit
|
||||
expect "*?assword:*"
|
||||
|
@ -168,22 +170,22 @@ enable_outbound_network_for_product_vm() {
|
|||
# Check for internet access on the host system
|
||||
echo -n "Checking for internet connectivity on the host system... "
|
||||
check_hosts=`echo google.com wikipedia.com | tr ' ' '\n'`
|
||||
case $(uname) in
|
||||
case $(execute uname) in
|
||||
Linux | Darwin)
|
||||
for i in ${check_hosts} ; do
|
||||
ping_host=`ping -c 2 ${i} | grep %`
|
||||
ping_host=`execute ping -c 2 ${i} | grep %`
|
||||
ping_host_result+=$ping_host
|
||||
done
|
||||
;;
|
||||
CYGWIN*)
|
||||
if [ ! -z "`type ping | grep system32`" ]; then
|
||||
if [ ! -z "`execute type ping | grep system32`" ]; then
|
||||
for i in ${check_hosts} ; do
|
||||
ping_host=`ping -n 5 ${i} | grep %`
|
||||
ping_host=`execute ping -n 5 ${i} | grep %`
|
||||
ping_host_result+=$ping_host
|
||||
done
|
||||
elif [ ! -z "`type ping | grep bin`" ]; then
|
||||
elif [ ! -z "`execute type ping | grep bin`" ]; then
|
||||
for i in ${check_hosts} ; do
|
||||
ping_host=`ping ${i} count 5 | grep %`
|
||||
ping_host=`execute ping ${i} count 5 | grep %`
|
||||
ping_host_result+=$ping_host
|
||||
done
|
||||
else
|
||||
|
@ -204,13 +206,13 @@ enable_outbound_network_for_product_vm() {
|
|||
|
||||
# Check host nameserver configuration
|
||||
echo -n "Checking local DNS configuration... "
|
||||
if [ -f /etc/resolv.conf ]; then
|
||||
nameserver="$(grep '^nameserver' /etc/resolv.conf | grep -v 'nameserver\s\s*127.' | head -3)"
|
||||
if execute test -f /etc/resolv.conf ; then
|
||||
nameserver="$(execute grep '^nameserver' /etc/resolv.conf | grep -v 'nameserver\s\s*127.' | head -3)"
|
||||
fi
|
||||
if [ -z "$nameserver" -a -x /usr/bin/nmcli ]; then
|
||||
if [ -z "$nameserver" -a execute test -x /usr/bin/nmcli ]; then
|
||||
# Get DNS from network manager
|
||||
if [ -n "`LANG=C nmcli nm | grep \"running\s\+connected\"`" ]; then
|
||||
nameserver="$(nmcli dev list | grep 'IP[46].DNS' | sed -e 's/IP[46]\.DNS\[[0-9]\+\]:\s\+/nameserver /'| grep -v 'nameserver\s\s*127.' | head -3)"
|
||||
if [ -n "`execute LANG=C nmcli nm | grep \"running\s\+connected\"`" ]; then
|
||||
nameserver="$(execute nmcli dev list | grep 'IP[46].DNS' | sed -e 's/IP[46]\.DNS\[[0-9]\+\]:\s\+/nameserver /'| grep -v 'nameserver\s\s*127.' | head -3)"
|
||||
fi
|
||||
fi
|
||||
if [ -z "$nameserver" ]; then
|
||||
|
@ -231,7 +233,7 @@ enable_outbound_network_for_product_vm() {
|
|||
# Log in into the VM, configure and bring up the NAT interface, set default gateway, check internet connectivity
|
||||
# Looks a bit ugly, but 'end of expect' has to be in the very beginning of the line
|
||||
result=$(
|
||||
expect << ENDOFEXPECT
|
||||
execute expect << ENDOFEXPECT
|
||||
spawn ssh $ssh_options $username@$ip
|
||||
expect "connect to host" exit
|
||||
expect "*?assword:*"
|
||||
|
@ -285,7 +287,7 @@ ENDOFEXPECT
|
|||
echo -e "\nWaiting until the network services are restarted..."
|
||||
sleep 5s
|
||||
result_inet=$(
|
||||
expect << ENDOFEXPECT
|
||||
execute expect << ENDOFEXPECT
|
||||
spawn ssh $ssh_options $username@$ip
|
||||
expect "connect to host" exit
|
||||
expect "*?assword:*"
|
||||
|
|
|
@ -0,0 +1,66 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Copyright 2015 Mirantis, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
# This file contains the functions, those encapsulate executing of command.
|
||||
# Each command might be executed on the local machine or on the remote machine
|
||||
# depending on environment settings
|
||||
|
||||
shell_ssh_options=""
|
||||
shell_scp_options=""
|
||||
|
||||
if [ -n "$REMOTE_PORT" ]; then
|
||||
shell_ssh_options="-p $REMOTE_PORT $shell_ssh_options"
|
||||
shell_scp_options="-P $REMOTE_PORT $shell_scp_options"
|
||||
fi
|
||||
|
||||
|
||||
function execute() {
|
||||
# use shell substitution pattern ${parameter/pattern/string}, to escape spaces in arguments.
|
||||
if [ -n "$REMOTE_HOST" ]; then
|
||||
eval "ssh $shell_ssh_options $REMOTE_HOST \"${@//\ /\\ }\""
|
||||
else
|
||||
eval "${@//\ /\\ }"
|
||||
fi
|
||||
}
|
||||
|
||||
# copy file to remote machine if needed
|
||||
# be careful, do nothing in case if file with same name exists on target machine
|
||||
function copy_if_required() {
|
||||
local source_path=$1
|
||||
if [ -n "$REMOTE_HOST" ]; then
|
||||
if ! execute test -f $source_path; then
|
||||
# the scripts always find iso in original path
|
||||
# reconstruct same path on remote machine
|
||||
local source_dir=$(dirname $source_path)
|
||||
echo "Copying $source_path to $REMOTE_HOST:$source_path..."
|
||||
execute mkdir -p $source_dir && copy $source_path $source_path || exit 1
|
||||
else
|
||||
echo "Skip copying the file $source_path, it already exists on $REMOTE_HOST."
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
function copy() {
|
||||
local src=$1
|
||||
local dst=$2
|
||||
|
||||
if [ -n "$REMOTE_HOST" ]; then
|
||||
eval "scp $shell_scp_options $src $REMOTE_HOST:$dst"
|
||||
else
|
||||
cp $src $dst
|
||||
fi
|
||||
}
|
|
@ -16,16 +16,18 @@
|
|||
|
||||
# This file contains the functions to manage VMs in through VirtualBox CLI
|
||||
|
||||
source ./functions/shell.sh
|
||||
|
||||
get_vm_base_path() {
|
||||
echo `VBoxManage list systemproperties | grep '^Default machine folder' | sed 's/^Default machine folder\:[ \t]*//'`
|
||||
echo `execute VBoxManage list systemproperties | grep '^Default machine folder' | sed 's/^Default machine folder\:[ \t]*//'`
|
||||
}
|
||||
|
||||
get_vms_running() {
|
||||
echo `VBoxManage list runningvms | sed 's/[ \t]*{.*}//' | sed 's/^"//' | sed 's/"$//'`
|
||||
echo `execute VBoxManage list runningvms | sed 's/[ \t]*{.*}//' | sed 's/^"//' | sed 's/"$//'`
|
||||
}
|
||||
|
||||
get_vms_present() {
|
||||
echo `VBoxManage list vms | sed 's/[ \t]*{.*}//' | sed 's/^"//' | sed 's/"$//'`
|
||||
echo `execute VBoxManage list vms | sed 's/[ \t]*{.*}//' | sed 's/^"//' | sed 's/"$//'`
|
||||
}
|
||||
|
||||
is_vm_running() {
|
||||
|
@ -57,14 +59,14 @@ check_running_vms() {
|
|||
OIFS=$IFS
|
||||
IFS=","
|
||||
local hostonly_interfaces=$1
|
||||
local list_running_vms=$(VBoxManage list runningvms | sed 's/\" {/\",{/g')
|
||||
local list_running_vms=$(execute VBoxManage list runningvms | sed 's/\" {/\",{/g')
|
||||
for vm_name in $list_running_vms; do
|
||||
vm_name=$(echo $vm_name | grep "\"" | sed 's/"//g')
|
||||
vm_names+="$vm_name,"
|
||||
done
|
||||
for i in $vm_names; do
|
||||
for j in $hostonly_interfaces; do
|
||||
running_vm=`VBoxManage showvminfo $i | grep "$j"`
|
||||
running_vm=`execute VBoxManage showvminfo $i | grep "$j"`
|
||||
if [[ $? -eq 0 ]]; then
|
||||
echo "The \"$i\" VM uses host-only interface \"$j\" and it cannot be removed...."
|
||||
echo "You should turn off the \"$i\" virtual machine, run the script again and then the host-only interface will be deleted. Aborting..."
|
||||
|
@ -86,26 +88,29 @@ create_vm() {
|
|||
# There is a chance that some files are left from previous VM instance
|
||||
vm_base_path=$(get_vm_base_path)
|
||||
vm_path="$vm_base_path/$name/"
|
||||
rm -rf "$vm_path"
|
||||
execute rm -rf "$vm_path"
|
||||
|
||||
# Create virtual machine with the right name and type (assuming CentOS)
|
||||
VBoxManage createvm --name $name --ostype $os --register
|
||||
execute VBoxManage createvm --name $name --ostype $os --register
|
||||
|
||||
# Set the real-time clock (RTC) operate in UTC time
|
||||
# Set memory and CPU parameters
|
||||
# Set video memory to 16MB, so VirtualBox does not complain about "non-optimal" settings in the UI
|
||||
VBoxManage modifyvm $name --rtcuseutc on --memory $memory_mb --cpus $cpu_cores --vram 16
|
||||
execute VBoxManage modifyvm $name --rtcuseutc on --memory $memory_mb --cpus $cpu_cores --vram 16
|
||||
|
||||
# Configure main network interface for management/PXE network
|
||||
add_hostonly_adapter_to_vm $name 1 "$nic"
|
||||
VBoxManage modifyvm $name --boot1 disk --boot2 dvd --boot3 net --boot4 none
|
||||
execute VBoxManage modifyvm $name --boot1 disk --boot2 dvd --boot3 net --boot4 none
|
||||
|
||||
# Configure storage controllers
|
||||
VBoxManage storagectl $name --name 'IDE' --add ide --hostiocache on
|
||||
VBoxManage storagectl $name --name 'SATA' --add sata --hostiocache on
|
||||
execute VBoxManage storagectl $name --name 'IDE' --add ide --hostiocache on
|
||||
execute VBoxManage storagectl $name --name 'SATA' --add sata --hostiocache on
|
||||
|
||||
# Create and attach the main hard drive
|
||||
add_disk_to_vm $name 0 $disk_mb
|
||||
|
||||
# Enable RDP
|
||||
execute VBoxManage modifyvm $name --vrde on
|
||||
}
|
||||
|
||||
add_hostonly_adapter_to_vm() {
|
||||
|
@ -115,9 +120,9 @@ add_hostonly_adapter_to_vm() {
|
|||
echo "Adding hostonly adapter to $name and bridging with host NIC $nic..."
|
||||
|
||||
# Add Intel PRO/1000 MT Desktop (82540EM) card to VM. The card is 1Gbps.
|
||||
VBoxManage modifyvm $name --nic${id} hostonly --hostonlyadapter${id} "$nic" --nictype${id} 82540EM \
|
||||
execute VBoxManage modifyvm $name --nic${id} hostonly --hostonlyadapter${id} "$nic" --nictype${id} 82540EM \
|
||||
--cableconnected${id} on --macaddress${id} auto
|
||||
VBoxManage modifyvm $name --nicpromisc${id} allow-all
|
||||
execute VBoxManage modifyvm $name --nicpromisc${id} allow-all
|
||||
}
|
||||
|
||||
add_nat_adapter_to_vm() {
|
||||
|
@ -127,10 +132,10 @@ add_nat_adapter_to_vm() {
|
|||
echo "Adding NAT adapter to $name for outbound network access through the host system..."
|
||||
|
||||
# Add Intel PRO/1000 MT Desktop (82540EM) card to VM. The card is 1Gbps.
|
||||
VBoxManage modifyvm $name --nic${id} nat --nictype${id} 82540EM \
|
||||
execute VBoxManage modifyvm $name --nic${id} nat --nictype${id} 82540EM \
|
||||
--cableconnected${id} on --macaddress${id} auto --natnet${id} "${nat_network}"
|
||||
VBoxManage modifyvm $name --nicpromisc${id} allow-all
|
||||
VBoxManage controlvm $name setlinkstate${id} on
|
||||
execute VBoxManage modifyvm $name --nicpromisc${id} allow-all
|
||||
execute VBoxManage controlvm $name setlinkstate${id} on
|
||||
}
|
||||
|
||||
add_disk_to_vm() {
|
||||
|
@ -143,12 +148,12 @@ add_disk_to_vm() {
|
|||
vm_disk_path="$(get_vm_base_path)/$vm_name/"
|
||||
disk_name="${vm_name}_${port}"
|
||||
disk_filename="${disk_name}.vdi"
|
||||
VBoxManage createhd --filename "$vm_disk_path/$disk_filename" --size $disk_mb --format VDI
|
||||
VBoxManage storageattach $vm_name --storagectl 'SATA' --port $port --device 0 --type hdd --medium "$vm_disk_path/$disk_filename"
|
||||
execute VBoxManage createhd --filename "$vm_disk_path/$disk_filename" --size $disk_mb --format VDI
|
||||
execute VBoxManage storageattach $vm_name --storagectl 'SATA' --port $port --device 0 --type hdd --medium "$vm_disk_path/$disk_filename"
|
||||
|
||||
# Add serial numbers of disks to slave nodes
|
||||
echo "Adding serial numbers of disks to $vm_name..."
|
||||
VBoxManage setextradata $vm_name "VBoxInternal/Devices/ahci/0/Config/Port$port/SerialNumber" "VBOX-MIRANTIS-VHD$port"
|
||||
execute VBoxManage setextradata $vm_name "VBoxInternal/Devices/ahci/0/Config/Port$port/SerialNumber" "VBOX-MIRANTIS-VHD$port"
|
||||
|
||||
}
|
||||
|
||||
|
@ -161,7 +166,7 @@ delete_vm() {
|
|||
count=0
|
||||
while is_vm_running $name; do
|
||||
echo "Stopping Virtual Machine $name..."
|
||||
VBoxManage controlvm $name poweroff
|
||||
execute VBoxManage controlvm $name poweroff
|
||||
if [[ "$count" != 5 ]]; then
|
||||
count=$((count+1))
|
||||
sleep 5
|
||||
|
@ -174,10 +179,10 @@ delete_vm() {
|
|||
echo "Deleting existing virtual machine $name..."
|
||||
while is_vm_present $name
|
||||
do
|
||||
VBoxManage unregistervm $name --delete
|
||||
execute VBoxManage unregistervm $name --delete
|
||||
done
|
||||
# Virtualbox does not fully delete VM file structure, so we need to delete the corresponding directory with files as well
|
||||
rm -rf "$vm_path"
|
||||
execute rm -rf "$vm_path"
|
||||
}
|
||||
|
||||
delete_vms_multiple() {
|
||||
|
@ -198,9 +203,9 @@ start_vm() {
|
|||
|
||||
# Just start it
|
||||
if [[ $headless == 1 ]]; then
|
||||
VBoxManage startvm $name --type headless
|
||||
execute VBoxManage startvm $name --type headless
|
||||
else
|
||||
VBoxManage startvm $name
|
||||
execute VBoxManage startvm $name
|
||||
fi
|
||||
}
|
||||
|
||||
|
@ -209,13 +214,12 @@ mount_iso_to_vm() {
|
|||
iso_path=$2
|
||||
|
||||
# Mount ISO to the VM
|
||||
VBoxManage storageattach $name --storagectl "IDE" --port 0 --device 0 --type dvddrive --medium "$iso_path"
|
||||
execute VBoxManage storageattach $name --storagectl "IDE" --port 0 --device 0 --type dvddrive --medium "$iso_path"
|
||||
}
|
||||
|
||||
enable_network_boot_for_vm() {
|
||||
name=$1
|
||||
|
||||
# Set the right boot priority
|
||||
VBoxManage modifyvm $name --boot1 net --boot2 disk --boot3 none --boot4 none --nicbootprio1 1
|
||||
execute VBoxManage modifyvm $name --boot1 net --boot2 disk --boot3 none --boot4 none --nicbootprio1 1
|
||||
}
|
||||
|
||||
|
|
|
@ -14,11 +14,13 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
source ./functions/shell.sh
|
||||
|
||||
# Add VirtualBox directory to PATH
|
||||
case "$(uname)" in
|
||||
case "$(execute uname)" in
|
||||
CYGWIN*)
|
||||
vbox_path_registry=`cat /proc/registry/HKEY_LOCAL_MACHINE/SOFTWARE/Oracle/VirtualBox/InstallDir`
|
||||
vbox_path=`cygpath "$vbox_path_registry"| sed -e 's%/$%%'`
|
||||
vbox_path_registry=`execute cat /proc/registry/HKEY_LOCAL_MACHINE/SOFTWARE/Oracle/VirtualBox/InstallDir`
|
||||
vbox_path=`execute cygpath "$vbox_path_registry"| sed -e 's%/$%%'`
|
||||
export PATH=$PATH:$vbox_path
|
||||
;;
|
||||
*)
|
||||
|
|
Loading…
Reference in New Issue