return (True, "Instance started successfully")
-def ShutdownInstance(instance):
+def InstanceShutdown(instance):
"""Shut an instance down.
@note: this functions uses polling with a hardcoded timeout.
running_instances = GetInstanceList([hv_name])
if instance.name not in running_instances:
- return True
+ return (True, "Instance already stopped")
hyper = hypervisor.GetHypervisor(hv_name)
try:
hyper.StopInstance(instance)
except errors.HypervisorError, err:
- logging.error("Failed to stop instance: %s" % err)
- return False
+ msg = "Failed to stop instance %s: %s" % (instance.name, err)
+ logging.error(msg)
+ return (False, msg)
# test every 10secs for 2min
try:
hyper.StopInstance(instance, force=True)
except errors.HypervisorError, err:
- logging.exception("Failed to stop instance: %s" % err)
- return False
+ msg = "Failed to force stop instance %s: %s" % (instance.name, err)
+ logging.error(msg)
+ return (False, msg)
time.sleep(1)
if instance.name in GetInstanceList([hv_name]):
- logging.error("Could not shutdown instance '%s' even by destroy",
- instance.name)
- return False
+ msg = ("Could not shutdown instance %s even by destroy" %
+ instance.name)
+ logging.error(msg)
+ return (False, msg)
_RemoveBlockDevLinks(instance.name, instance.disks)
- return True
+ return (True, "Instance has been shutdown successfully")
def InstanceReboot(instance, reboot_type, extra_args):
return (False, msg)
elif reboot_type == constants.INSTANCE_REBOOT_HARD:
try:
- ShutdownInstance(instance)
+ InstanceShutdown(instance)
StartInstance(instance, extra_args)
except errors.HypervisorError, err:
msg = "Failed to hard reboot instance %s: %s" % (instance.name, err)
if msg:
raise errors.OpExecError("Could not reboot instance: %s" % msg)
else:
- if not self.rpc.call_instance_shutdown(node_current, instance):
- raise errors.OpExecError("could not shutdown instance for full reboot")
+ result = self.rpc.call_instance_shutdown(node_current, instance)
+ msg = result.RemoteFailMsg()
+ if msg:
+ raise errors.OpExecError("Could not shutdown instance for"
+ " full reboot: %s" % msg)
_ShutdownInstanceDisks(self, instance)
_StartInstanceDisks(self, instance, ignore_secondaries)
result = self.rpc.call_instance_start(node_current, instance, extra_args)
node_current = instance.primary_node
self.cfg.MarkInstanceDown(instance.name)
result = self.rpc.call_instance_shutdown(node_current, instance)
- if result.failed or not result.data:
- self.proc.LogWarning("Could not shutdown instance")
+ msg = result.RemoteFailMsg()
+ if msg:
+ self.proc.LogWarning("Could not shutdown instance: %s" % msg)
_ShutdownInstanceDisks(self, instance)
instance.name, instance.primary_node)
result = self.rpc.call_instance_shutdown(instance.primary_node, instance)
- if result.failed or not result.data:
+ msg = result.RemoteFailMsg()
+ if msg:
if self.op.ignore_failures:
- feedback_fn("Warning: can't shutdown instance")
+ feedback_fn("Warning: can't shutdown instance: %s" % msg)
else:
- raise errors.OpExecError("Could not shutdown instance %s on node %s" %
- (instance.name, instance.primary_node))
+ raise errors.OpExecError("Could not shutdown instance %s on"
+ " node %s: %s" %
+ (instance.name, instance.primary_node, msg))
logging.info("Removing block devices for instance %s", instance.name)
instance.name, source_node)
result = self.rpc.call_instance_shutdown(source_node, instance)
- if result.failed or not result.data:
+ msg = result.RemoteFailMsg()
+ if msg:
if self.op.ignore_consistency:
self.proc.LogWarning("Could not shutdown instance %s on node %s."
- " Proceeding"
- " anyway. Please make sure node %s is down",
- instance.name, source_node, source_node)
+ " Proceeding anyway. Please make sure node"
+ " %s is down. Error details: %s",
+ instance.name, source_node, source_node, msg)
else:
- raise errors.OpExecError("Could not shutdown instance %s on node %s" %
- (instance.name, source_node))
+ raise errors.OpExecError("Could not shutdown instance %s on"
+ " node %s: %s" %
+ (instance.name, source_node, msg))
feedback_fn("* deactivating the instance's disks on source node")
if not _ShutdownInstanceDisks(self, instance, ignore_primary=True):
if self.op.shutdown:
# shutdown the instance, but not the disks
result = self.rpc.call_instance_shutdown(src_node, instance)
- result.Raise()
- if not result.data:
- raise errors.OpExecError("Could not shutdown instance %s on node %s" %
- (instance.name, src_node))
+ msg = result.RemoteFailMsg()
+ if msg:
+ raise errors.OpExecError("Could not shutdown instance %s on"
+ " node %s: %s" %
+ (instance.name, src_node, msg))
vgname = self.cfg.GetVGName()