+##check to make sure nodes are powered off
+##this function does nothing if virtual
+##params: none
+##usage: check_baremetal_nodes()
+check_baremetal_nodes() {
+ if [ $virtual ]; then
+ echo "${blue}Skipping Baremetal node power status check as deployment is virtual ${reset}"
+ else
+ echo "${blue}Checking Baremetal nodes power state... ${reset}"
+ if [ ! -z "$base_config" ]; then
+ # Install ipmitool
+ # Major version is pinned to force some consistency for Arno
+ if ! yum list installed | grep -i ipmitool; then
+ echo "${blue}Installing ipmitool...${reset}"
+ if ! yum -y install ipmitool-1*; then
+ echo "${red}Failed to install ipmitool!${reset}"
+ exit 1
+ fi
+ fi
+
+ ###find all the bmc IPs and number of nodes
+ node_counter=0
+ output=`grep bmc_ip $base_config | grep -Eo '[0-9]+.[0-9]+.[0-9]+.[0-9]+'`
+ for line in ${output} ; do
+ bmc_ip[$node_counter]=$line
+ ((node_counter++))
+ done
+
+ max_nodes=$((node_counter-1))
+
+ ###find bmc_users per node
+ node_counter=0
+ output=`grep bmc_user $base_config | sed 's/\s*bmc_user:\s*//'`
+ for line in ${output} ; do
+ bmc_user[$node_counter]=$line
+ ((node_counter++))
+ done
+
+ ###find bmc_pass per node
+ node_counter=0
+ output=`grep bmc_pass $base_config | sed 's/\s*bmc_pass:\s*//'`
+ for line in ${output} ; do
+ bmc_pass[$node_counter]=$line
+ ((node_counter++))
+ done
+
+ for mynode in `seq 0 $max_nodes`; do
+ echo "${blue}Node: ${bmc_ip[$mynode]} ${bmc_user[$mynode]} ${bmc_pass[$mynode]} ${reset}"
+ ipmi_output=`ipmitool -I lanplus -P ${bmc_pass[$mynode]} -U ${bmc_user[$mynode]} -H ${bmc_ip[$mynode]} chassis status \
+ | grep "System Power" | cut -d ':' -f2 | tr -d [:blank:]`
+ if [ "$ipmi_output" == "on" ]; then
+ echo "${red}Error: Node is powered on: ${bmc_ip[$mynode]} ${reset}"
+ echo "${red}Please run clean.sh before running deploy! ${reset}"
+ exit 1
+ elif [ "$ipmi_output" == "off" ]; then
+ echo "${blue}Node: ${bmc_ip[$mynode]} is powered off${reset}"
+ else
+ echo "${red}Warning: Unable to detect node power state: ${bmc_ip[$mynode]} ${reset}"
+ fi
+ done
+ else
+ echo "${red}base_config was not provided for a baremetal install! Exiting${reset}"
+ exit 1
+ fi
+ fi
+}
+
+##resizes vagrant disk (cannot shrink)
+##params: size in GB
+##usage: resize_vagrant_disk 100
+resize_vagrant_disk() {
+ if [[ "$1" < 40 ]]; then
+ echo "${blue}Warn: Requested disk size cannot be less than 40, using 40 as new size${reset}"
+ new_size_gb=40
+ else
+ new_size_gb=$1
+ fi
+
+ if ! vagrant box list | grep opnfv; then
+ vagrant box remove -f opnfv/centos-7.0
+ if ! vagrant box add opnfv/centos-7.0 --provider virtualbox; then
+ echo "${red}Unable to reclone vagrant box! Exiting...${reset}"
+ exit 1
+ fi
+ fi
+
+ pushd $vagrant_box_dir
+
+ # Close medium to make sure we can modify it
+ vboxmanage closemedium disk $vagrant_box_vmdk
+
+ cur_size=$(vboxmanage showhdinfo $vagrant_box_vmdk | grep -i capacity | grep -Eo [0-9]+)
+ cur_size_gb=$((cur_size / 1024))
+
+ if [ "$cur_size_gb" -eq "$new_size_gb" ]; then
+ echo "${blue}Info: Disk size already ${cur_size_gb} ${reset}"
+ popd
+ return
+ elif [[ "$new_size_gb" < "$cur_size_gb" ]] ; then
+ echo "${blue}Info: Requested disk is less than ${cur_size_gb} ${reset}"
+ echo "${blue}Re-adding vagrant box${reset}"
+ if vagrant box list | grep opnfv; then
+ popd
+ vagrant box remove -f opnfv/centos-7.0
+ if ! vagrant box add opnfv/centos-7.0 --provider virtualbox; then
+ echo "${red}Unable to reclone vagrant box! Exiting...${reset}"
+ exit 1
+ fi
+ pushd $vagrant_box_dir
+ fi
+ fi
+
+ new_size=$((new_size_gb * 1024))
+ if ! vboxmanage clonehd $vagrant_box_vmdk tmp-disk.vdi --format vdi; then
+ echo "${red}Error: Unable to clone ${vagrant_box_vmdk}${reset}"
+ popd
+ return 1
+ fi
+
+ if ! vboxmanage modifyhd tmp-disk.vdi --resize $new_size; then
+ echo "${red}Error: Unable modify tmp-disk.vdi to ${new_size}${reset}"
+ popd
+ return 1
+ fi
+
+ if ! vboxmanage clonehd tmp-disk.vdi resized-disk.vmdk --format vmdk; then
+ echo "${red}Error: Unable clone tmp-disk.vdi to vmdk${reset}"
+ popd
+ return 1
+ fi
+
+ vboxmanage closemedium disk tmp-disk.vdi --delete
+ rm -f tmp-disk.vdi $vagrant_box_vmdk
+ cp -f resized-disk.vmdk $vagrant_box_vmdk
+ vboxmanage closemedium disk resized-disk.vmdk --delete
+ popd
+}
+