Start an instance and connect

Written by admin on August 12, 2015 Categories: OpenStack Tags: , , , , ,
function nssh {
        arg=$@
        srv=${@: -1}
        nova delete $srv && sleep 5
        id=$(nova boot $arg | grep '|\s*id\s*|\s' | awk '{ print $4 }');
        echo "ACK from Nova, id: $id"
        while true; do
                ip=$(nova show $id | grep 'Ext-Net network' | grep '[0-9]*.[0-9]*.[0-9]*.[0-9]*' |awk '{ print $5 '});
                if [ "-$ip-" != "--" ]; then
                        echo "IP found, ip: $ip"
                        break;
                else
                        sleep 3;
                fi;
        done;
        while true; do
                op=$(nmap -p22 -PN -PS22 $ip | grep '22/tcp\s*open\s*ssh');
                if [ "-$op-" != "--" ]; then
                        echo "SSH available, connecting..."
                        ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no $ip
                        break
                else
                        sleep 1;
                fi;
        done;
 };

 

 

No Comments on Start an instance and connect

Leave a Reply

Your email address will not be published. Required fields are marked *