self.options = options
self.engine_rpcapi = engine_rpcapi.EngineAPI()
- def _remote_error(self, ex, force_exists=False):
- """
- Map rpc_common.RemoteError exceptions returned by the engine
- to webob exceptions which can be used to return
- properly formatted error responses.
- """
- if ex.exc_type in ('AttributeError', 'ValueError'):
- if force_exists:
- raise exc.HTTPBadRequest(explanation=str(ex))
- else:
- raise exc.HTTPNotFound(explanation=str(ex))
-
- raise exc.HTTPInternalServerError(explanation=str(ex))
-
def default(self, req, **args):
raise exc.HTTPNotFound()
try:
stack_list = self.engine_rpcapi.list_stacks(req.context)
except rpc_common.RemoteError as ex:
- return self._remote_error(ex, True)
+ return util.remote_error(ex, True)
summary_keys = (engine_api.STACK_ID,
engine_api.STACK_NAME,
data.user_params(),
data.args())
except rpc_common.RemoteError as ex:
- return self._remote_error(ex, True)
+ return util.remote_error(ex, True)
if 'Description' in result:
raise exc.HTTPBadRequest(explanation=result['Description'])
identity = self.engine_rpcapi.identify_stack(req.context,
stack_name)
except rpc_common.RemoteError as ex:
- return self._remote_error(ex)
+ return util.remote_error(ex)
raise exc.HTTPFound(location=util.make_url(req, identity))
stack_list = self.engine_rpcapi.show_stack(req.context,
identity)
except rpc_common.RemoteError as ex:
- return self._remote_error(ex)
+ return util.remote_error(ex)
if not stack_list['stacks']:
raise exc.HTTPInternalServerError()
templ = self.engine_rpcapi.get_template(req.context,
identity)
except rpc_common.RemoteError as ex:
- return self._remote_error(ex)
+ return util.remote_error(ex)
if templ is None:
raise exc.HTTPNotFound()
data.user_params(),
data.args())
except rpc_common.RemoteError as ex:
- return self._remote_error(ex)
+ return util.remote_error(ex)
if 'Description' in res:
raise exc.HTTPBadRequest(explanation=res['Description'])
cast=False)
except rpc_common.RemoteError as ex:
- return self._remote_error(ex)
+ return util.remote_error(ex)
if res is not None:
raise exc.HTTPBadRequest(explanation=res['Error'])
result = self.engine_rpcapi.validate_template(req.context,
data.template())
except rpc_common.RemoteError as ex:
- return self._remote_error(ex, True)
+ return util.remote_error(ex, True)
if 'Error' in result:
raise exc.HTTPBadRequest(explanation=result['Error'])
# License for the specific language governing permissions and limitations
# under the License.
+from webob import exc
from functools import wraps
from heat.engine import identifier
def make_link(req, identity, relationship='self'):
'''Return a link structure for the supplied identity dictionary.'''
return {'href': make_url(req, identity), 'rel': relationship}
+
+
+def remote_error(ex, force_exists=False):
+ """
+ Map rpc_common.RemoteError exceptions returned by the engine
+ to webob exceptions which can be used to return
+ properly formatted error responses.
+ """
+ if ex.exc_type in ('AttributeError', 'ValueError'):
+ if force_exists:
+ raise exc.HTTPBadRequest(explanation=str(ex))
+ else:
+ raise exc.HTTPNotFound(explanation=str(ex))
+
+ raise exc.HTTPInternalServerError(explanation=str(ex))