core: add methods to trigger ACPI S3 of VM
Those methods should be called during dom0 suspend/resume.
This commit is contained in:
parent
084b5575a9
commit
149971ae2e
@ -562,7 +562,10 @@ class QubesVm(object):
|
|||||||
elif dominfo['crashed']:
|
elif dominfo['crashed']:
|
||||||
return "Crashed"
|
return "Crashed"
|
||||||
elif dominfo['shutdown']:
|
elif dominfo['shutdown']:
|
||||||
return "Halting"
|
if dominfo['shutdown_reason'] == 2:
|
||||||
|
return "Suspended"
|
||||||
|
else:
|
||||||
|
return "Halting"
|
||||||
elif dominfo['dying']:
|
elif dominfo['dying']:
|
||||||
return "Dying"
|
return "Dying"
|
||||||
else:
|
else:
|
||||||
@ -1532,6 +1535,39 @@ class QubesVm(object):
|
|||||||
|
|
||||||
subprocess.call (['/usr/sbin/xl', 'destroy', str(xid) if xid is not None else self.name])
|
subprocess.call (['/usr/sbin/xl', 'destroy', str(xid) if xid is not None else self.name])
|
||||||
|
|
||||||
|
def suspend(self):
|
||||||
|
if dry_run:
|
||||||
|
return
|
||||||
|
|
||||||
|
if not self.is_running() and not self.is_paused():
|
||||||
|
raise QubesException ("VM already stopped!")
|
||||||
|
|
||||||
|
xs_path = '/local/domain/%d/control/shutdown' % self.get_xid()
|
||||||
|
xs.write('', xs_path, 'suspend')
|
||||||
|
tries = 0
|
||||||
|
while self.get_power_state() != "Suspended":
|
||||||
|
tries += 1
|
||||||
|
if tries > 15:
|
||||||
|
# fallback to pause
|
||||||
|
print >>sys.stderr, "Failed to suspend domain %s, falling back to pause method" % self.name
|
||||||
|
self.pause()
|
||||||
|
break
|
||||||
|
time.sleep(0.2)
|
||||||
|
|
||||||
|
def resume(self):
|
||||||
|
if dry_run:
|
||||||
|
return
|
||||||
|
|
||||||
|
xc_info = self.get_xc_dominfo()
|
||||||
|
if not xc_info:
|
||||||
|
raise QubesException ("VM isn't started (cannot get xc_dominfo)!")
|
||||||
|
|
||||||
|
if xc_info['shutdown_reason'] == 2:
|
||||||
|
# suspended
|
||||||
|
xc.domain_resume(xc_info['domid'], 1)
|
||||||
|
else:
|
||||||
|
self.unpause()
|
||||||
|
|
||||||
def pause(self):
|
def pause(self):
|
||||||
if dry_run:
|
if dry_run:
|
||||||
return
|
return
|
||||||
|
@ -63,6 +63,9 @@ class QubesDom0NetVm(QubesNetVm):
|
|||||||
def start(self, **kwargs):
|
def start(self, **kwargs):
|
||||||
raise QubesException ("Cannot start Dom0 fake domain!")
|
raise QubesException ("Cannot start Dom0 fake domain!")
|
||||||
|
|
||||||
|
def suspend(self):
|
||||||
|
return
|
||||||
|
|
||||||
def get_xl_dominfo(self):
|
def get_xl_dominfo(self):
|
||||||
if dry_run:
|
if dry_run:
|
||||||
return
|
return
|
||||||
|
@ -269,6 +269,15 @@ class QubesHVm(QubesVm):
|
|||||||
|
|
||||||
self.wait_for_session(notify_function=kwargs.get('notify_function', None))
|
self.wait_for_session(notify_function=kwargs.get('notify_function', None))
|
||||||
|
|
||||||
|
def suspend(self):
|
||||||
|
if dry_run:
|
||||||
|
return
|
||||||
|
|
||||||
|
if not self.is_running() and not self.is_paused():
|
||||||
|
raise QubesException ("VM not running!")
|
||||||
|
|
||||||
|
self.pause()
|
||||||
|
|
||||||
def pause(self):
|
def pause(self):
|
||||||
if dry_run:
|
if dry_run:
|
||||||
return
|
return
|
||||||
|
Loading…
Reference in New Issue
Block a user