From be2f84e1af4393eb74e2a542602b38d9e14b8e6a Mon Sep 17 00:00:00 2001 From: Markos Chandras Date: Fri, 6 Oct 2017 10:29:28 +0100 Subject: xci: scripts: start-new-vm.sh: Do not destroy user's configuration file As we move towards making this script useful for developers, we shouldn't destroy the existing ssh configuration file but rather create a new one just for XCI. This also move the destruction of previous instances sooner, even before building the OS image so we can free resources as soon as possible. Finally, this also uses the hostname to ssh to the new VM instead of its IP to ensure that everything is setup up properly on the physical host. Change-Id: I185befd8943fdb8ebcdb635aefb4d4b03473258b Signed-off-by: Markos Chandras --- xci/scripts/vm/start-new-vm.sh | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) (limited to 'xci') diff --git a/xci/scripts/vm/start-new-vm.sh b/xci/scripts/vm/start-new-vm.sh index a1f4080e..5273a778 100755 --- a/xci/scripts/vm/start-new-vm.sh +++ b/xci/scripts/vm/start-new-vm.sh @@ -82,6 +82,10 @@ declare -r XCI_CACHE_DIR=${HOME}/.cache/opnfv_xci_deploy echo "Preparing new virtual machine '${VM_NAME}'..." +echo "Destroying previous '${VM_NAME}' instances..." +sudo virsh destroy ${VM_NAME} || true +sudo virsh undefine ${VM_NAME} || true + source /etc/os-release echo "Installing host (${ID,,}) dependencies..." # check we can run sudo @@ -172,10 +176,6 @@ fi sudo virsh net-list --autostart | grep -q ${NETWORK} || sudo virsh net-autostart ${NETWORK} sudo virsh net-list --inactive | grep -q ${NETWORK} && sudo virsh net-start ${NETWORK} -echo "Destroying previous instances if necessary..." -sudo virsh destroy ${VM_NAME} || true -sudo virsh undefine ${VM_NAME} || true - echo "Installing virtual machine '${VM_NAME}'..." sudo virt-install -n ${VM_NAME} --memory ${MEMORY} --vcpus ${NCPUS} --cpu ${CPU} \ --import --disk=${OS_IMAGE_FILE},cache=unsafe --network network=${NETWORK} \ @@ -201,7 +201,8 @@ chmod 600 ${BASE_PATH}/xci/scripts/vm/id_rsa_for_dib* ssh-keygen -R $_ip || true ssh-keygen -R ${VM_NAME} || true -declare -r vm_ssh="ssh -o StrictHostKeyChecking=no -i ${BASE_PATH}/xci/scripts/vm/id_rsa_for_dib -l devuser" +# Initial ssh command until we setup everything +vm_ssh="ssh -o StrictHostKeyChecking=no -i ${BASE_PATH}/xci/scripts/vm/id_rsa_for_dib -l devuser" _retries=30 _ssh_exit=0 @@ -221,12 +222,12 @@ done echo "Congratulations! Your shiny new '${VM_NAME}' virtual machine is fully operational! Enjoy!" -echo "Adding ${VM_NAME}_xci_vm entry to /etc/hosts" +echo "Adding ${VM_NAME} entry to /etc/hosts" sudo sed -i "/.*${VM_NAME}.*/d" /etc/hosts sudo bash -c "echo '${_ip} ${VM_NAME}' >> /etc/hosts" echo "Dropping a minimal .ssh/config file" -cat > $HOME/.ssh/config< $HOME/.ssh/xci-vm-config< /etc/resolv.conf"' -$vm_ssh $_ip 'sudo bash -c "echo nameserver 8.8.4.4 >> /etc/resolv.conf"' +$vm_ssh ${VM_NAME} 'sudo bash -c "echo nameserver 8.8.8.8 > /etc/resolv.conf"' +$vm_ssh ${VM_NAME} 'sudo bash -c "echo nameserver 8.8.4.4 >> /etc/resolv.conf"' cat > ${BASE_PATH}/vm_hosts.txt <