Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
rpm -q libguestfs-tools || yum install -y libguestfs-tools
for vm in $(virsh list --all | tail -n +3 | awk ' { print $2 } ') ; do
virsh start $vm
done
### FIXME: Adjust the wait time according to the number of VMs and how powerful
### your server is.
echo "Waiting for the vms to power up"
sleep 3m
mkdir -p ~/install-files/ ;
### FIXME: iterates over all RHEL 6 hosts (in my case, all RHEL 6 hosts contain the r6
### string as part of their name. Replace or remove this accordingly
for vm in $(virsh list --all | tail -n +3 | grep running | grep r6 | awk ' { print $2 } ') ; do
echo "Reading last leases from $vm"
virt-cat $vm /var/lib/dhclient/dhclient-eth1.leases | tail -17 | grep "fixed-address" | sed 's/;//' | awk '{ print $2 }' > /root/install-files/$vm.ip.source
## Print the new IP
IP_NEW="$(cat /root/install-files/$vm.ip.source)"
echo "New IP address is ${IP_NEW}"
done
### FIXME: iterates over all RHEL 6 hosts (in my case, all RHEL 7 hosts contain the r7
### string as part of their name. Replace or remove this accordingly
for vm in $(virsh list --all | tail -n +3 | grep running | grep r7 | awk ' { print $2 } ') ; do
echo "Reading last leases from $vm"
leases_file=$(virt-ls $vm /var/lib/NetworkManager/ | grep lease)
virt-cat $vm /var/lib/NetworkManager/$leases_file | tail -17 | grep "fixed-address" | sed 's/;//' | awk '{ print $2 }' > /root/install-files/$vm.ip.source
## Print the new IP
IP_NEW="$(cat /root/install-files/$vm.ip.source)"
echo "New IP address is ${IP_NEW}"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment