def _stop_server(self, req, id, body):
     """Stop an instance."""
     context = req.environ['nova.context']
     instance = self._get_instance(context, id)
     extensions.check_compute_policy(context, 'stop', instance)
     LOG.debug(_('stop instance'), instance=instance)
     try:
         self.compute_api.stop(context, instance)
     except (exception.InstanceNotReady, exception.InstanceIsLocked) as e:
         raise webob.exc.HTTPConflict(explanation=e.format_message())
     return webob.Response(status_int=202)
 def _stop_server(self, req, id, body):
     """Stop an instance."""
     context = req.environ['nova.context']
     instance = self._get_instance(context, id)
     extensions.check_compute_policy(context, 'stop', instance)
     LOG.debug(_('stop instance'), instance=instance)
     try:
         self.compute_api.stop(context, instance)
     except (exception.InstanceNotReady, exception.InstanceIsLocked) as e:
         raise webob.exc.HTTPConflict(explanation=e.format_message())
     return webob.Response(status_int=202)
    def _stop_server(self, req, id, body):
        """Stop an instance."""
        context = req.environ['nova.context']
        instance = self._get_instance(context, id)
        extensions.check_compute_policy(context, 'stop', instance)

        try:
            self.compute_api.stop(context, instance)
        except (exception.InstanceNotReady, exception.InstanceIsLocked) as e:
            raise webob.exc.HTTPConflict(explanation=e.format_message())
        except exception.InstanceInvalidState as state_error:
            common.raise_http_conflict_for_instance_invalid_state(state_error,
                'stop', id)
        return webob.Response(status_int=202)
    def _stop_server(self, req, id, body):
        """Stop an instance."""
        context = req.environ['nova.context']
        instance = self._get_instance(context, id)
        extensions.check_compute_policy(context, 'stop', instance)
        LOG.debug(_('stop instance'), instance=instance)
        clean_shutdown=True
        if self.ext_mgr.is_loaded('os-force-shutdown'):
            if body['os-stop'] and 'force-shutdown' in body['os-stop']:
                force_shutdown = body['os-stop']['force-shutdown']
                if not isinstance(force_shutdown, bool):
                    msg = _LE("Argument 'force_shutdown-type' for stop must be a Boolean")
                    LOG.error(msg)
                    raise exc.HTTPBadRequest(explanation=msg)

                clean_shutdown=not force_shutdown
        try:
            self.compute_api.stop(context, instance, clean_shutdown=clean_shutdown)
        except (exception.InstanceNotReady, exception.InstanceIsLocked,
                exception.InstanceInvalidState) as e:
            raise webob.exc.HTTPConflict(explanation=e.format_message())
        return webob.Response(status_int=202)