e0c875a367
Host suspend notification may be useful not only to driver domains. For example Whonix needs to resync time after suspend. Thanks @adrelanos for help. Fixes QubesOS/qubes-issues#1663
28 lines
864 B
Python
Executable File
28 lines
864 B
Python
Executable File
#!/usr/bin/python
|
|
|
|
from qubes.qubes import QubesVmCollection,QubesException
|
|
import sys
|
|
|
|
qc = QubesVmCollection()
|
|
qc.lock_db_for_reading()
|
|
qc.load()
|
|
qc.unlock_db()
|
|
|
|
if sys.argv[1] in ["suspend", "hibernate"]:
|
|
for vm in qc.values():
|
|
if vm.is_running():
|
|
try:
|
|
vm.run_service("qubes.SuspendPreAll", user="root")
|
|
vm.suspend()
|
|
except Exception as e:
|
|
print >>sys.stderr, "Failed to suspend VM %s: %s" % (vm.name, e.message)
|
|
|
|
elif sys.argv[1] in ["resume", "thaw"]:
|
|
for vm in qc.values():
|
|
if vm.get_power_state() in ["Paused", "Suspended"]:
|
|
try:
|
|
vm.resume()
|
|
vm.run_service("qubes.SuspendPostAll", user="root")
|
|
except Exception as e:
|
|
print >>sys.stderr, "Failed to resume VM %s: %s" % (vm.name, e.message)
|