Skip to content

Instantly share code, notes, and snippets.

@ties
Created May 14, 2014 09:06
Show Gist options
  • Save ties/c23b7520a1d71945bcc5 to your computer and use it in GitHub Desktop.
Save ties/c23b7520a1d71945bcc5 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
"""
One of my machines runs multiple KVM vm's.
When the host needs to reboot i suspend the vm's first using this quick and dirty script.
After the reboot there is some time skew in the vm's (they continue at the time of the
suspend). You either need to use one of these solutions;
* reboot the vm's. They will pickup the correct time...
* manually stop ntp (service stop ntp) and let ntpd fix the time with a large step (ntpd -gq)
* setup ntp to skew the clock faster
* setup KVM to provide a different clocksource <https://access.redhat.com/site/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Virtualization_Administration_Guide/sect-Virtualization-Tips_and_tricks-Libvirt_Managed_Timers.html>
Since I don't reboot often I have not setup the clocksource yet...
"""
import libvirt
conn = libvirt.open(None)
for id in conn.listDomainsID():
domain = conn.lookupByID(id)
#domain.shutdown()
domain.managedSave(0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment