Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # Testcase:
- VM_IP="192.168.0.11"
- VM_USERNAME="cirros"
- VM_INTERFACE="eth0"
- # VM_PASSWORD="gocubsgo"
- checkConnection() {
- echo "Wait for ssh-server of instance to start"
- (( check_timeout = 120 ))
- while (( check_timeout > 0 )); do
- ping -c 1 $VM_IP &>/dev/null
- if [ $? -eq 0 ]; then
- ssh-keygen -f ~/.ssh/known_hosts -R $VM_IP &>/dev/null
- ssh -i ./mykey.pem $VM_USERNAME@$VM_IP -o ServerAliveInterval=5 -o ServerAliveCountMax=1 -o StrictHostKeyChecking=no "exit" &>/dev/null
- if [ $? -eq 0 ]; then
- echo "Instance's ssh-server is running."
- return 0
- fi
- fi
- (( check_timeout-- ))
- sleep 1
- done
- echo "Instance's ssh-server isn't running."
- return 1
- }
- # Preparation
- echo "Creating instance..."
- . ./auth-demo.sh
- INSTANCE_ID=$(./instance-create.sh cirros m1.nano 1 compute3 $VM_IP)
- CLUSTER_ID="$(./cluster-create.sh vm-network-isolation compute3)"
- ./cluster-add-instance.sh $CLUSTER_ID $INSTANCE_ID
- checkConnection
- # cut off network
- echo "Cut off network of guest os"
- ssh-keygen -f ~/.ssh/known_hosts -R $VM_IP &>/dev/null
- ssh -i ./mykey.pem $VM_USERNAME@$VM_IP -o ServerAliveInterval=5 -o ServerAliveCountMax=1 -o StrictHostKeyChecking=no \
- "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin;sudo ifconfig $VM_INTERFACE down"
- # wait for HASS to reboot instance
- if checkConnection ;then
- echo "Pass"
- PASS=0
- else
- echo "Fail"
- PASS=1
- fi
- # clean up
- ./instance-delete.sh $INSTANCE_ID && ./cluster-delete.sh $CLUSTER_ID
- exit $PASS
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement