import re
import urlparse
import webob
-from webob.exc import (HTTPNotFound,
- HTTPConflict,
- HTTPBadRequest)
+from heat.api.v1 import exception
from heat.common import wsgi
from heat.common import config
from heat.common import context
'''
return {'%sResponse' % action: {'%sResult' % action: response}}
+ def _remote_error(self, ex):
+ '''
+ Map rpc_common.RemoteError exceptions returned by the engine
+ to HeatAPIException subclasses which can be used to return
+ properly formatted AWS error responses
+ '''
+ if ex.exc_type == 'AttributeError':
+ # Attribute error, bad user data, ex.value should tell us why
+ return exception.HeatInvalidParameterValueError(detail=ex.value)
+ else:
+ # Map everything else to internal server error for now
+ # FIXME : further investigation into engine errors required
+ return exception.HeatInternalFailureError(detail=ex.value)
+
def list(self, req):
"""
Returns the following information for all stacks:
'params': parms}})
except rpc_common.RemoteError as ex:
- return webob.exc.HTTPBadRequest(str(ex))
+ return self._remote_error(ex)
res = {'Stacks': []}
for s in stack_list['stacks']:
templ = self._get_template(req)
except socket.gaierror:
msg = _('Invalid Template URL')
- return webob.exc.HTTPBadRequest(explanation=msg)
+ return exception.HeatInvalidParameterValueError(detail=msg)
+
if templ is None:
msg = _("TemplateBody or TemplateUrl were not given.")
- return webob.exc.HTTPBadRequest(explanation=msg)
+ return exception.HeatMissingParameterError(detail=msg)
try:
stack = json.loads(templ)
except ValueError:
msg = _("The Template must be a JSON document.")
- return webob.exc.HTTPBadRequest(explanation=msg)
+ return exception.HeatInvalidParameterValueError(detail=msg)
try:
res = rpc.call(con, 'engine',
'template': stack,
'params': parms}})
except rpc_common.RemoteError as ex:
- return webob.exc.HTTPBadRequest(str(ex))
+ return self._remote_error(ex)
return self._format_response('CreateStack',
self._stackid_addprefix(res))
'args': {'stack_name': req.params['StackName'],
'params': parms}})
except rpc_common.RemoteError as ex:
- return webob.exc.HTTPBadRequest(str(ex))
+ return self._remote_error(ex)
if templ is None:
- return webob.exc.HTTPNotFound('stack not found')
+ msg = _('stack not not found')
+ return exception.HeatInvalidParameterValueError(detail=msg)
return self._format_response('GetTemplate', {'TemplateBody': templ})
templ = self._get_template(req)
except socket.gaierror:
msg = _('Invalid Template URL')
- return webob.exc.HTTPBadRequest(explanation=msg)
+ return exception.HeatInvalidParameterValueError(detail=msg)
if templ is None:
msg = _("TemplateBody or TemplateUrl were not given.")
- return webob.exc.HTTPBadRequest(explanation=msg)
+ return exception.HeatMissingParameterError(detail=msg)
try:
stack = json.loads(templ)
except ValueError:
msg = _("The Template must be a JSON document.")
- return webob.exc.HTTPBadRequest(explanation=msg)
+ return exception.HeatInvalidParameterValueError(detail=msg)
logger.info('validate_template')
try:
'args': {'template': stack,
'params': parms}})
except rpc_common.RemoteError as ex:
- return webob.exc.HTTPBadRequest(str(ex))
+ return self._remote_error(ex)
def delete(self, req):
"""
'params': parms}})
except rpc_common.RemoteError as ex:
- return webob.exc.HTTPBadRequest(str(ex))
+ return self._remote_error(ex)
if res is None:
return self._format_response('DeleteStack', '')
'args': {'stack_name': stack_name,
'params': parms}})
except rpc_common.RemoteError as ex:
- return webob.exc.HTTPBadRequest(str(ex))
+ return self._remote_error(ex)
events = 'Error' not in event_res and event_res['events'] or []
'args': args})
except rpc_common.RemoteError as ex:
- return webob.exc.HTTPBadRequest(str(ex))
+ return self._remote_error(ex)
return self._format_response('DescribeStackResource',
{'StackResourceDetail': resource_details})
physical_resource_id = req.params.get('PhysicalResourceId')
if stack_name and physical_resource_id:
msg = 'Use `StackName` or `PhysicalResourceId` but not both'
- return webob.exc.HTTPBadRequest(msg)
+ return exception.HeatInvalidParameterCombinationError(detail=msg)
args = {
'stack_name': stack_name,
'args': args})
except rpc_common.RemoteError as ex:
- return webob.exc.HTTPBadRequest(str(ex))
+ return self._remote_error(ex)
return self._format_response('DescribeStackResources',
{'StackResources': resources})
'args': {'stack_name': req.params.get('StackName')}
})
except rpc_common.RemoteError as ex:
- return webob.exc.HTTPBadRequest(str(ex))
+ return self._remote_error(ex)
return self._format_response('ListStackResources',
{'StackResourceSummaries': resources})