Created
August 1, 2017 09:34
-
-
Save orpiske/b4d44bac6eb03cfdaaa63b1d90596b4c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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