Advertisement
Guest User

Untitled

a guest
Apr 9th, 2019
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. #!/bin/bash
  2. # Testcase:
  3. VM_IP="192.168.0.11"
  4. VM_USERNAME="cirros"
  5. VM_INTERFACE="eth0"
  6. # VM_PASSWORD="gocubsgo"
  7.  
  8. checkConnection() {
  9. echo "Wait for ssh-server of instance to start"
  10. (( check_timeout = 120 ))
  11. while (( check_timeout > 0 )); do
  12. ping -c 1 $VM_IP &>/dev/null
  13. if [ $? -eq 0 ]; then
  14. ssh-keygen -f ~/.ssh/known_hosts -R $VM_IP &>/dev/null
  15. ssh -i ./mykey.pem $VM_USERNAME@$VM_IP -o ServerAliveInterval=5 -o ServerAliveCountMax=1 -o StrictHostKeyChecking=no "exit" &>/dev/null
  16. if [ $? -eq 0 ]; then
  17. echo "Instance's ssh-server is running."
  18. return 0
  19. fi
  20. fi
  21. (( check_timeout-- ))
  22. sleep 1
  23. done
  24. echo "Instance's ssh-server isn't running."
  25. return 1
  26. }
  27.  
  28. # Preparation
  29. echo "Creating instance..."
  30. . ./auth-demo.sh
  31. INSTANCE_ID=$(./instance-create.sh cirros m1.nano 1 compute3 $VM_IP)
  32. CLUSTER_ID="$(./cluster-create.sh vm-network-isolation compute3)"
  33. ./cluster-add-instance.sh $CLUSTER_ID $INSTANCE_ID
  34. checkConnection
  35.  
  36. # cut off network
  37. echo "Cut off network of guest os"
  38. ssh-keygen -f ~/.ssh/known_hosts -R $VM_IP &>/dev/null
  39. ssh -i ./mykey.pem $VM_USERNAME@$VM_IP -o ServerAliveInterval=5 -o ServerAliveCountMax=1 -o StrictHostKeyChecking=no \
  40. "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin;sudo ifconfig $VM_INTERFACE down"
  41.  
  42. # wait for HASS to reboot instance
  43. if checkConnection ;then
  44. echo "Pass"
  45. PASS=0
  46. else
  47. echo "Fail"
  48. PASS=1
  49. fi
  50.  
  51. # clean up
  52. ./instance-delete.sh $INSTANCE_ID && ./cluster-delete.sh $CLUSTER_ID
  53. exit $PASS
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement