Commit 5ae35aa2 by Guba Sándor

operations: Added ShutdownOperation precondition.

SaveAsTemplateOperation optimistic shutdown.
parent aea984d1
......@@ -202,8 +202,12 @@ class SaveAsTemplateOperation(InstanceOperation):
def _operation(self, activity, name, user, system, timeout=300,
with_shutdown=True, **kwargs):
if with_shutdown:
ShutdownOperation(self.instance).call(parent_activity=activity,
user=user)
try:
ShutdownOperation(self.instance).call(parent_activity=activity,
user=user)
except Instance.WrongStateError:
pass
# prepare parameters
params = {
'access_method': self.instance.access_method,
......@@ -260,6 +264,11 @@ class ShutdownOperation(InstanceOperation):
name = _("shutdown")
description = _("Shutdown virtual machine with ACPI signal.")
def check_precond(self):
super(ShutdownOperation, self).check_precond()
if self.instance.status not in ['RUNNING']:
raise self.instance.WrongStateError(self.instance)
def on_abort(self, activity, error):
if isinstance(error, TimeLimitExceeded):
activity.resultant_state = None
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment