f4d74c2ef1
To help people get started running this puppet, let's provide a set of DIB elements and libvirt templates to help set up a mock development environment. Change-Id: Ife8e253ba0429bedb924fde5a12f5be9e23dc163
38 lines
993 B
Bash
38 lines
993 B
Bash
#!/bin/bash
|
|
|
|
ssh_cmd() {
|
|
local vm_ip=$1
|
|
shift
|
|
ssh devuser@${vm_ip} -o StrictHostKeyChecking=no "$*"
|
|
}
|
|
|
|
sshvm() {
|
|
local vm_name=$1
|
|
shift
|
|
local vm_mac=$(virsh dumpxml $vm_name | grep -m 1 'mac address' | cut -d "'" -f 2)
|
|
local vm_ip=$(arp -n | grep -m 1 $vm_mac | cut -d ' ' -f 1)
|
|
local tries=2
|
|
while [ $tries -ge 0 ] ; do
|
|
if [ -n "$vm_ip" ] ; then
|
|
local error=$(ssh_cmd $vm_ip true 2>&1) # Check for connection refused and try again
|
|
if [[ ! $error =~ .*Connection\ refused.* ]] ; then
|
|
echo "SSHing to $vm_ip"
|
|
ssh_cmd $vm_ip "$*"
|
|
break
|
|
else
|
|
echo "SSH is not ready yet. Trying again in 5 seconds."
|
|
sleep 5
|
|
fi
|
|
else
|
|
if [ $tries -eq 0 ] ; then
|
|
echo "Could not reach VM."
|
|
else
|
|
echo "VM is not ready yet. Trying $tries more time(s) in 15 seconds."
|
|
sleep 15
|
|
fi
|
|
vm_ip=$(arp -n | grep $vm_mac | cut -d ' ' -f 1)
|
|
tries=$(echo "${tries}-1" | bc)
|
|
fi
|
|
done
|
|
}
|