2013-10-23 19:59:29 +00:00
|
|
|
#!/usr/bin/python
|
2013-03-16 18:52:16 +00:00
|
|
|
|
2013-10-23 19:59:29 +00:00
|
|
|
from qubes.qubes import QubesVmCollection,QubesException
|
|
|
|
import sys
|
2013-03-16 18:52:16 +00:00
|
|
|
|
2013-10-23 19:59:29 +00:00
|
|
|
qc = QubesVmCollection()
|
|
|
|
qc.lock_db_for_reading()
|
|
|
|
qc.load()
|
|
|
|
qc.unlock_db()
|
2013-03-16 18:52:16 +00:00
|
|
|
|
2013-10-23 19:59:29 +00:00
|
|
|
if sys.argv[1] in ["suspend", "hibernate"]:
|
|
|
|
for vm in qc.values():
|
|
|
|
if vm.is_running():
|
|
|
|
try:
|
2016-03-15 22:13:48 +00:00
|
|
|
vm.run_service("qubes.SuspendPreAll", user="root")
|
2013-10-23 19:59:29 +00:00
|
|
|
vm.suspend()
|
|
|
|
except Exception as e:
|
|
|
|
print >>sys.stderr, "Failed to suspend VM %s: %s" % (vm.name, e.message)
|
2013-03-16 18:52:16 +00:00
|
|
|
|
2013-10-23 19:59:29 +00:00
|
|
|
elif sys.argv[1] in ["resume", "thaw"]:
|
|
|
|
for vm in qc.values():
|
|
|
|
if vm.get_power_state() in ["Paused", "Suspended"]:
|
|
|
|
try:
|
|
|
|
vm.resume()
|
2016-03-15 22:13:48 +00:00
|
|
|
vm.run_service("qubes.SuspendPostAll", user="root")
|
2013-10-23 19:59:29 +00:00
|
|
|
except Exception as e:
|
|
|
|
print >>sys.stderr, "Failed to resume VM %s: %s" % (vm.name, e.message)
|