Delete only the demo hostonly networks
Change-Id: I81b1c73d782e75e89ce76c51e0b6e9246409d80e Closes-Bug: #1384976
This commit is contained in:
parent
8841a977e3
commit
9737a945a6
|
@ -1,4 +1,4 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# Copyright 2014 Mirantis, Inc.
|
# Copyright 2014 Mirantis, Inc.
|
||||||
#
|
#
|
||||||
|
@ -15,7 +15,7 @@
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
#
|
#
|
||||||
# This script check availble memory on host PC for quality provision VMs via VirtualBox
|
# This script check available memory on host PC for quality provision VMs via VirtualBox
|
||||||
#
|
#
|
||||||
|
|
||||||
source ./config.sh
|
source ./config.sh
|
||||||
|
|
|
@ -25,11 +25,14 @@ source ./config.sh
|
||||||
source ./functions/vm.sh
|
source ./functions/vm.sh
|
||||||
source ./functions/network.sh
|
source ./functions/network.sh
|
||||||
|
|
||||||
# Delete all host-only interfaces
|
# Delete host-only interfaces
|
||||||
delete_all_hostonly_interfaces
|
if [[ "$rm_network" == "0" ]]; then
|
||||||
|
delete_fuel_ifaces
|
||||||
|
else
|
||||||
|
delete_all_hostonly_interfaces
|
||||||
|
fi
|
||||||
|
|
||||||
# Create the required host-only interfaces
|
# Create the required host-only interfaces
|
||||||
# Change {0..2} to {0..4} below if you are going to create 5 interfaces instead of 3
|
for ip in $fuel_master_ips; do
|
||||||
for idx in $(eval echo {0..2}); do
|
create_hostonly_interfaces $ip
|
||||||
create_hostonly_interface "${host_nic_name[$idx]}" ${host_nic_ip[$idx]} ${host_nic_mask[$idx]}
|
|
||||||
done
|
done
|
||||||
|
|
|
@ -22,10 +22,15 @@
|
||||||
# Include the handy functions to operate VMs and track ISO installation progress
|
# Include the handy functions to operate VMs and track ISO installation progress
|
||||||
source ./config.sh
|
source ./config.sh
|
||||||
source ./functions/vm.sh
|
source ./functions/vm.sh
|
||||||
|
source ./functions/network.sh
|
||||||
source ./functions/product.sh
|
source ./functions/product.sh
|
||||||
|
|
||||||
# Create master node for the product
|
# Create master node for the product
|
||||||
|
# Get variables "host_nic_name" for the master node
|
||||||
|
get_fuel_name_ifaces
|
||||||
|
|
||||||
name="${vm_name_prefix}master"
|
name="${vm_name_prefix}master"
|
||||||
|
|
||||||
create_vm $name "${host_nic_name[0]}" $vm_master_cpu_cores $vm_master_memory_mb $vm_master_disk_mb
|
create_vm $name "${host_nic_name[0]}" $vm_master_cpu_cores $vm_master_memory_mb $vm_master_disk_mb
|
||||||
echo
|
echo
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# Copyright 2013 Mirantis, Inc.
|
# Copyright 2013 Mirantis, Inc.
|
||||||
#
|
#
|
||||||
|
@ -22,6 +22,10 @@
|
||||||
# Include the handy functions to operate VMs
|
# Include the handy functions to operate VMs
|
||||||
source ./config.sh
|
source ./config.sh
|
||||||
source ./functions/vm.sh
|
source ./functions/vm.sh
|
||||||
|
source ./functions/network.sh
|
||||||
|
|
||||||
|
# Get variables "host_nic_name" for the slave nodes
|
||||||
|
get_fuel_name_ifaces
|
||||||
|
|
||||||
# Create and start slave nodes
|
# Create and start slave nodes
|
||||||
for idx in $(eval echo {1..$cluster_size}); do
|
for idx in $(eval echo {1..$cluster_size}); do
|
||||||
|
|
32
config.sh
32
config.sh
|
@ -22,22 +22,28 @@ iso_path=`ls -1t iso/*.iso 2>/dev/null | head -1`
|
||||||
# Every Mirantis OpenStack machine name will start from this prefix
|
# Every Mirantis OpenStack machine name will start from this prefix
|
||||||
vm_name_prefix=fuel-
|
vm_name_prefix=fuel-
|
||||||
|
|
||||||
# Host interfaces to bridge VMs interfaces with
|
# By default, all available network interfaces vboxnet won't be removed,
|
||||||
# VirtualBox has different virtual NIC naming convention and index base
|
# if their IP addresses don't match with fuel_master_ips (10.20.0.1 172.16.0.1
|
||||||
# between Windows and Linux/MacOS
|
# 172.16.1.1)
|
||||||
idx=0
|
# If you want to remove all existing vbox interfaces, then use rm_network=1
|
||||||
|
# 0 - don't remove all vbox networks. Remove only fuel networks if they exist
|
||||||
|
# 1 - remove all vbox networks
|
||||||
|
rm_network=0
|
||||||
|
|
||||||
# Please add the IPs accordingly if you going to create non-default NICs number
|
# Please add the IPs accordingly if you going to create non-default NICs number
|
||||||
# 10.20.0.1/24 - Mirantis OpenStack Admin network
|
# 10.20.0.1/24 - Mirantis OpenStack Admin network
|
||||||
# 172.16.0.1/24 - OpenStack Public/External/Floating network
|
# 172.16.0.1/24 - OpenStack Public/External/Floating network
|
||||||
# 172.16.1.1/24 - OpenStack Fixed/Internal/Private network
|
# 172.16.1.1/24 - OpenStack Fixed/Internal/Private network
|
||||||
# 192.168.0.1/24 - OpenStack Management network
|
# 192.168.0.1/24 - OpenStack Management network
|
||||||
# 192.168.1.1/24 - OpenStack Storage network (for Ceph, Swift etc)
|
# 192.168.1.1/24 - OpenStack Storage network (for Ceph, Swift etc)
|
||||||
for ip in 10.20.0.1 172.16.0.1 172.16.1.1 ; do
|
fuel_master_ips="10.20.0.1 172.16.0.1 172.16.1.1"
|
||||||
# VirtualBox for Windows has different virtual NICs naming and indexing.
|
|
||||||
# Define the type of operating system and the number of processor cores for the fuel master node.
|
# Network mask for fuel interfaces
|
||||||
|
mask="255.255.255.0"
|
||||||
|
|
||||||
|
# Determining the type of operating system and adding CPU core to the master node
|
||||||
case "$(uname)" in
|
case "$(uname)" in
|
||||||
Linux)
|
Linux)
|
||||||
host_nic_name[$idx]=vboxnet$idx
|
|
||||||
os_type="linux"
|
os_type="linux"
|
||||||
if [ "$(nproc)" -gt "1" ]; then
|
if [ "$(nproc)" -gt "1" ]; then
|
||||||
vm_master_cpu_cores=2
|
vm_master_cpu_cores=2
|
||||||
|
@ -46,7 +52,6 @@ for ip in 10.20.0.1 172.16.0.1 172.16.1.1 ; do
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
Darwin)
|
Darwin)
|
||||||
host_nic_name[$idx]=vboxnet$idx
|
|
||||||
os_type="darwin"
|
os_type="darwin"
|
||||||
mac_nproc=`sysctl -a | grep machdep.cpu.thread_count | sed 's/^machdep.cpu.thread_count\:[ \t]*//'`
|
mac_nproc=`sysctl -a | grep machdep.cpu.thread_count | sed 's/^machdep.cpu.thread_count\:[ \t]*//'`
|
||||||
if [ "$mac_nproc" -gt "1" ]; then
|
if [ "$mac_nproc" -gt "1" ]; then
|
||||||
|
@ -56,11 +61,6 @@ for ip in 10.20.0.1 172.16.0.1 172.16.1.1 ; do
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
CYGWIN*)
|
CYGWIN*)
|
||||||
if [ $idx -eq 0 ]; then
|
|
||||||
host_nic_name[$idx]='VirtualBox Host-Only Ethernet Adapter'
|
|
||||||
else
|
|
||||||
host_nic_name[$idx]='VirtualBox Host-Only Ethernet Adapter #'$((idx+1))
|
|
||||||
fi
|
|
||||||
os_type="cygwin"
|
os_type="cygwin"
|
||||||
if [ "$(nproc)" -gt "1" ]; then
|
if [ "$(nproc)" -gt "1" ]; then
|
||||||
vm_master_cpu_cores=2
|
vm_master_cpu_cores=2
|
||||||
|
@ -73,10 +73,6 @@ for ip in 10.20.0.1 172.16.0.1 172.16.1.1 ; do
|
||||||
exit 1
|
exit 1
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
host_nic_ip[$idx]=$ip
|
|
||||||
host_nic_mask[$idx]=255.255.255.0
|
|
||||||
idx=$((idx+1))
|
|
||||||
done
|
|
||||||
|
|
||||||
# Master node settings
|
# Master node settings
|
||||||
vm_master_memory_mb=1536
|
vm_master_memory_mb=1536
|
||||||
|
|
|
@ -20,11 +20,33 @@ get_hostonly_interfaces() {
|
||||||
echo -e `VBoxManage list hostonlyifs | grep '^Name' | sed 's/^Name\:[ \t]*//' | uniq | tr "\\n" ","`
|
echo -e `VBoxManage list hostonlyifs | grep '^Name' | sed 's/^Name\:[ \t]*//' | uniq | tr "\\n" ","`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get_fuel_ifaces() {
|
||||||
|
local fuel_iface
|
||||||
|
local fuel_ifaces=""
|
||||||
|
for ip in $fuel_master_ips; do
|
||||||
|
fuel_iface=`VBoxManage list hostonlyifs | grep -B5 $ip | grep '^Name' | sed 's/^Name\:[ \t]*//' | uniq | tr "\\n" ","`
|
||||||
|
fuel_ifaces+="$fuel_iface"
|
||||||
|
done
|
||||||
|
echo $fuel_ifaces
|
||||||
|
}
|
||||||
|
|
||||||
|
get_fuel_name_ifaces() {
|
||||||
|
local fuel_ifaces=$(get_fuel_ifaces)
|
||||||
|
IFS=","
|
||||||
|
set -- $fuel_ifaces
|
||||||
|
j=0
|
||||||
|
for i in $fuel_ifaces; do
|
||||||
|
host_nic_name[$j]=$i
|
||||||
|
j=$((j+1));
|
||||||
|
done
|
||||||
|
unset IFS
|
||||||
|
}
|
||||||
|
|
||||||
is_hostonly_interface_present() {
|
is_hostonly_interface_present() {
|
||||||
name=$1
|
name=$1
|
||||||
# String comparison with IF works different in Cygwin, probably due to encoding.
|
# String comparison with IF works different in Cygwin, probably due to encoding.
|
||||||
# So, reduced Case is used. since it works the same way.
|
# So, reduced Case is used. since it works the same way.
|
||||||
# Default divider character change is mandatory for Cygwin.
|
# Default divider character change is mandatory for Cygwin.
|
||||||
case "$(uname)" in
|
case "$(uname)" in
|
||||||
CYGWIN*)
|
CYGWIN*)
|
||||||
OIFS=$IFS
|
OIFS=$IFS
|
||||||
|
@ -34,7 +56,7 @@ is_hostonly_interface_present() {
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
# Call VBoxManage directly instead of function, due to changed IFS
|
# Call VBoxManage directly instead of function, due to changed IFS
|
||||||
list=(`VBoxManage list hostonlyifs | grep '^Name' | sed 's/^Name\:[ \t]*//' | uniq | tr "\\n" ","`)
|
local found_iface=(`VBoxManage list hostonlyifs | grep -E "Name: + $name\$" | awk '/Name/ { $1 = ""; print substr($0, 2) }'`)
|
||||||
# Change default divider back
|
# Change default divider back
|
||||||
case "$(uname)" in
|
case "$(uname)" in
|
||||||
CYGWIN*)
|
CYGWIN*)
|
||||||
|
@ -44,7 +66,7 @@ is_hostonly_interface_present() {
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
# Check that the list of interfaces contains the given interface
|
# Check that the list of interfaces contains the given interface
|
||||||
if [[ $list = *$name* ]]; then
|
if [[ "$found_iface" == "$name" ]]; then
|
||||||
return 0
|
return 0
|
||||||
else
|
else
|
||||||
return 1
|
return 1
|
||||||
|
@ -97,26 +119,18 @@ check_if_iface_settings_applied() {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
create_hostonly_interface() {
|
create_hostonly_interfaces() {
|
||||||
name=$1
|
# Creating host-only interface
|
||||||
ip=$2
|
local ip=$1
|
||||||
mask=$3
|
echo "Creating host-only interface"
|
||||||
echo "Creating host-only interface (name ip netmask): $name $ip $mask"
|
local id=`VBoxManage hostonlyif create | sed "s/'/_/g" | cut -d "_" -f2 | sed "s/^_//" | sed "s/_$//"`
|
||||||
|
|
||||||
# Exit if the interface already exists (deleting it here is not safe, as VirtualBox creates hostonly adapters sequentially)
|
|
||||||
if is_hostonly_interface_present "$name"; then
|
|
||||||
echo "Fatal error. Interface $name cannot be created because it already exists. Exiting"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
VBoxManage hostonlyif create
|
|
||||||
|
|
||||||
# If it does not exist after creation, let's abort
|
# If it does not exist after creation, let's abort
|
||||||
if ! is_hostonly_interface_present "$name"; then
|
if ! is_hostonly_interface_present "$id"; then
|
||||||
echo "Fatal error. Interface $name does not exist after creation. Exiting"
|
echo "Fatal error. Interface $id does not exist after creation. Exiting"
|
||||||
exit 1
|
exit 1
|
||||||
|
else
|
||||||
|
echo "Interface" $id "was successfully created"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Disable DHCP
|
# Disable DHCP
|
||||||
echo "Disabling DHCP server on interface: $name..."
|
echo "Disabling DHCP server on interface: $name..."
|
||||||
# These magic 1 second sleeps around DHCP config are required under Windows/Cygwin
|
# These magic 1 second sleeps around DHCP config are required under Windows/Cygwin
|
||||||
|
@ -124,14 +138,14 @@ create_hostonly_interface() {
|
||||||
sleep 1s
|
sleep 1s
|
||||||
VBoxManage dhcpserver remove --ifname "$name" 2>/dev/null
|
VBoxManage dhcpserver remove --ifname "$name" 2>/dev/null
|
||||||
sleep 1s
|
sleep 1s
|
||||||
set -x
|
|
||||||
# Set up IP address and network mask
|
# Set up IP address and network mask
|
||||||
echo "Configuring IP address $ip and network mask $mask on interface: $name..."
|
echo "Configuring IP address $ip and network mask $mask on interface: $name..."
|
||||||
VBoxManage hostonlyif ipconfig "$name" --ip $ip --netmask $mask
|
set -x
|
||||||
|
VBoxManage hostonlyif ipconfig "$id" --ip $ip --netmask $mask
|
||||||
set +x
|
set +x
|
||||||
# Check what we have created actually.
|
# Check what we have created actually.
|
||||||
# Sometimes VBox occasionally fails to apply settings to the last IFace under Windows
|
# Sometimes VBox occasionally fails to apply settings to the last IFace under Windows
|
||||||
if !(check_if_iface_settings_applied "$name" $ip $mask); then
|
if !(check_if_iface_settings_applied "$id" $ip $mask); then
|
||||||
echo "Looks like VirtualBox failed to apply settings for interface $name"
|
echo "Looks like VirtualBox failed to apply settings for interface $name"
|
||||||
echo "Sometimes such error happens under Windows."
|
echo "Sometimes such error happens under Windows."
|
||||||
echo "Please run launch.sh one more time."
|
echo "Please run launch.sh one more time."
|
||||||
|
@ -141,12 +155,42 @@ create_hostonly_interface() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Checking that the interface has been removed
|
||||||
|
check_removed_iface() {
|
||||||
|
local iface=$1
|
||||||
|
if is_hostonly_interface_present "$iface"; then
|
||||||
|
echo "Host-only interface \"$iface\" was not removed. Aborting..."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
delete_fuel_ifaces() {
|
||||||
|
# Only the interfaces that have IP addresses from the 'fuel_master_ips'
|
||||||
|
# variable in the config.sh scripts will be removed
|
||||||
|
local fuel_ifaces=$(get_fuel_ifaces)
|
||||||
|
if [ ! -z "$fuel_ifaces" ]; then
|
||||||
|
check_running_vms "$fuel_ifaces"
|
||||||
|
OIFS=$IFS
|
||||||
|
IFS=","
|
||||||
|
for interface in $fuel_ifaces; do
|
||||||
|
IFS=$OIFS
|
||||||
|
echo "Deleting host-only interface: $interface..."
|
||||||
|
VBoxManage hostonlyif remove "$interface"
|
||||||
|
check_removed_iface "$interface"
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
delete_all_hostonly_interfaces() {
|
delete_all_hostonly_interfaces() {
|
||||||
|
# All the hostonly interfaces will be removed
|
||||||
|
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=(`VBoxManage list hostonlyifs | grep '^Name' | sed 's/^Name\:[ \t]*//' | uniq | tr "\\n" ","`);IFS=$OIFS
|
||||||
# Delete every single hostonly interface in the system
|
# Delete every single hostonly interface in the system
|
||||||
for interface in "${list[@]}"; do
|
for interface in "${list[@]}"; do
|
||||||
echo "Deleting host-only interface: $interface..."
|
echo "Deleting host-only interface: $interface..."
|
||||||
VBoxManage hostonlyif remove "$interface"
|
VBoxManage hostonlyif remove "$interface"
|
||||||
|
check_removed_iface "$interface"
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -53,6 +53,24 @@ is_vm_present() {
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
check_running_vms() {
|
||||||
|
OIFS=$IFS
|
||||||
|
IFS=","
|
||||||
|
local hostonly_interfaces=$1
|
||||||
|
local list_running_vms=`VBoxManage list runningvms | awk '{print $1}' | sed 's/"//g' | uniq | tr "\\n" ","`
|
||||||
|
for i in $list_running_vms; do
|
||||||
|
for j in $hostonly_interfaces; do
|
||||||
|
running_vm=`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..."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
done
|
||||||
|
IFS=$OIFS
|
||||||
|
}
|
||||||
|
|
||||||
create_vm() {
|
create_vm() {
|
||||||
name=$1
|
name=$1
|
||||||
nic=$2
|
nic=$2
|
||||||
|
|
10
launch.sh
10
launch.sh
|
@ -1,4 +1,4 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# Copyright 2013 Mirantis, Inc.
|
# Copyright 2013 Mirantis, Inc.
|
||||||
#
|
#
|
||||||
|
@ -14,7 +14,7 @@
|
||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
# add VirtualBox directory to PATH
|
# Add VirtualBox directory to PATH
|
||||||
case "$(uname)" in
|
case "$(uname)" in
|
||||||
CYGWIN*)
|
CYGWIN*)
|
||||||
vbox_path_registry=`cat /proc/registry/HKEY_LOCAL_MACHINE/SOFTWARE/Oracle/VirtualBox/InstallDir`
|
vbox_path_registry=`cat /proc/registry/HKEY_LOCAL_MACHINE/SOFTWARE/Oracle/VirtualBox/InstallDir`
|
||||||
|
@ -25,17 +25,16 @@ case "$(uname)" in
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
|
||||||
# Prepare the host system
|
# Prepare the host system
|
||||||
./actions/prepare-environment.sh || exit 1
|
./actions/prepare-environment.sh || exit 1
|
||||||
|
|
||||||
# Check available memory on the host system
|
# Check available memory on the host system
|
||||||
./actions/check-available-memory.sh || exit 1
|
./actions/check-available-memory.sh || exit 1
|
||||||
|
|
||||||
# clean previous installation if exists
|
# Сlean previous installation if exists
|
||||||
./actions/clean-previous-installation.sh || exit 1
|
./actions/clean-previous-installation.sh || exit 1
|
||||||
|
|
||||||
# create host-only interfaces
|
# Сreate host-only interfaces
|
||||||
./actions/create-interfaces.sh || exit 1
|
./actions/create-interfaces.sh || exit 1
|
||||||
|
|
||||||
# Create and launch master node
|
# Create and launch master node
|
||||||
|
@ -43,4 +42,3 @@ esac
|
||||||
|
|
||||||
# Create and launch slave nodes
|
# Create and launch slave nodes
|
||||||
./actions/slave-nodes-create-and-boot.sh || exit 1
|
./actions/slave-nodes-create-and-boot.sh || exit 1
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue