instack-undercloud/scripts/instack-virt-setup

91 lines
2.8 KiB
Bash
Executable File

#!/bin/bash
set -ex
if [ ! -d "/usr/share/instack-undercloud" ]; then
DEVTEST_VARIABLES=/usr/libexec/openstack-tripleo/devtest_variables.sh
export RCFILE=$(dirname $0)/../deploy-virt-overcloudrc
export ANSWERSFILE=$(dirname $0)/../instack.answers.sample
export ELEMENTS_PATH="$(realpath $(dirname $0)/../elements):/usr/share/tripleo-image-elements:/usr/share/diskimage-builder/elements"
fi
# We use $NODE_COUNT here instead of the $NODE_CNT from devtest_variables.sh so
# that it can still be overrideable *after* sourcing devtest_variables.sh
export NODE_COUNT=${NODE_COUNT:-4}
export NODE_CNT=$NODE_COUNT
# TODO(bnemec): This should use set-os-type from tripleo-incubator, but that's
# currently broken for rhel7.
if $(grep -Eqs 'Red Hat Enterprise Linux Server release 7' /etc/redhat-release); then
DEFAULT_DIST=rhel7
export FS_TYPE=${FS_TYPE:-xfs}
else
DEFAULT_DIST=fedora
fi
export NODE_DIST=${NODE_DIST:-$DEFAULT_DIST}
export NODE_ARCH=${NODE_ARCH:-x86_64}
export NODE_MEM=${NODE_MEM:-4096}
export NODE_CPU=${NODE_CPU:-1}
source $DEVTEST_VARIABLES
export TE_DATAFILE=instackenv.json
tripleo devtest_testenv.sh $TE_DATAFILE
sudo virsh undefine --remove-all-storage seed
MACS=$(for i in $(seq 0 3); do echo -n $(tripleo get-vm-mac baremetal_$i)" "; done)
cp $RCFILE /tmp/deploy-virt-overcloudrc
sed -i "s/MACS=\"\"/MACS=\"$MACS\"/" /tmp/deploy-virt-overcloudrc
export UNDERCLOUD_VM_NAME=${UNDERCLOUD_VM_NAME:-"instack"}
export UNDERCLOUD_OS=${UNDERCLOUD_OS:-"fedora-20"}
export UNDERCLOUD_INSTALL=${UNDERCLOUD_INSTALL:-1}
if [ "$UNDERCLOUD_INSTALL" = "1" ]; then
cp $ANSWERSFILE /tmp/instack.answers
disk-image-create \
--image-size 30 \
-a amd64 \
$NODE_DIST instack-vm \
-o $UNDERCLOUD_VM_NAME
sudo cp $UNDERCLOUD_VM_NAME.qcow2 /var/lib/libvirt/images/$UNDERCLOUD_VM_NAME.qcow2
else
sudo qemu-img create -f qcow2 /var/lib/libvirt/images/$UNDERCLOUD_VM_NAME.qcow2 30G
fi
tripleo configure-vm \
--name $UNDERCLOUD_VM_NAME \
--image /var/lib/libvirt/images/$UNDERCLOUD_VM_NAME.qcow2 \
--seed \
--libvirt-nic-driver virtio \
--arch x86_64 \
--memory $((1024 * $NODE_MEM)) \
--cpus $NODE_CPU
virsh start $UNDERCLOUD_VM_NAME
timeout_seconds=180
elapsed_seconds=0
while true; do
IP=$(cat /var/lib/libvirt/dnsmasq/default.leases | grep $(tripleo get-vm-mac $UNDERCLOUD_VM_NAME) | awk '{print $3;}')
if [ -n "$IP" ]; then
echo "$UNDERCLOUD_VM_NAME vm IP address is $IP"
echo "You can connect by running:"
echo "ssh root@$IP"
echo "And then su to the stack user:"
echo "su - stack"
break
fi
sleep 3
(( elapsed_seconds += 3 ))
if [ $elapsed_seconds -ge $timeout_seconds ]; then
echo "$UNDERCLOUD_VM_NAME never got an IP address from the libvirt default network."
fi
done