API: Handle InstanceUnknownCell exceptions

There are some methods in Nova compute api and cell api would call the
decorator `check_instance_cell`, and that decorator may raise
InstanceUnknownCell, there isn't any exception handler in REST api layer.

This patch adds handlers for those methods.

Closes-bug: #1484776
Change-Id: I753a81f093ec5fdf000841949e52fca6f2662aa8
This commit is contained in:
Eli Qiao 2015-08-14 11:56:00 +08:00
parent 1db33ca6c2
commit cbcf5932be
16 changed files with 72 additions and 6 deletions

View File

@ -48,6 +48,8 @@ class AdminActionsController(wsgi.Controller):
try:
instance = common.get_instance(self.compute_api, context, id)
self.compute_api.reset_network(context, instance)
except exception.InstanceUnknownCell as e:
raise exc.HTTPNotFound(explanation=e.format_message())
except exception.InstanceIsLocked as e:
raise exc.HTTPConflict(explanation=e.format_message())
@ -61,6 +63,8 @@ class AdminActionsController(wsgi.Controller):
try:
instance = common.get_instance(self.compute_api, context, id)
self.compute_api.inject_network_info(context, instance)
except exception.InstanceUnknownCell as e:
raise exc.HTTPNotFound(explanation=e.format_message())
except exception.InstanceIsLocked as e:
raise exc.HTTPConflict(explanation=e.format_message())

View File

@ -49,6 +49,8 @@ class AdminPasswordController(wsgi.Controller):
instance = common.get_instance(self.compute_api, context, id)
try:
self.compute_api.set_admin_password(context, instance, password)
except exception.InstanceUnknownCell as e:
raise exc.HTTPNotFound(explanation=e.format_message())
except exception.InstancePasswordSetFailed as e:
raise exc.HTTPConflict(explanation=e.format_message())
except exception.InstanceInvalidState as e:

View File

@ -66,6 +66,8 @@ class CreateBackupController(wsgi.Controller):
try:
image = self.compute_api.backup(context, instance, image_name,
backup_type, rotation, extra_properties=props)
except exception.InstanceUnknownCell as e:
raise webob.exc.HTTPNotFound(explanation=e.format_message())
except exception.InstanceInvalidState as state_error:
common.raise_http_conflict_for_instance_invalid_state(state_error,
'createBackup', id)

View File

@ -42,6 +42,8 @@ class DeferredDeleteController(wsgi.Controller):
instance = common.get_instance(self.compute_api, context, id)
try:
self.compute_api.restore(context, instance)
except exception.InstanceUnknownCell as error:
raise webob.exc.HTTPNotFound(explanation=error.format_message())
except exception.QuotaError as error:
raise webob.exc.HTTPForbidden(explanation=error.format_message())
except exception.InstanceInvalidState as state_error:

View File

@ -86,6 +86,8 @@ class EvacuateController(wsgi.Controller):
try:
self.compute_api.evacuate(context, instance, host,
on_shared_storage, password)
except exception.InstanceUnknownCell as e:
raise exc.HTTPNotFound(explanation=e.format_message())
except exception.InstanceInvalidState as state_error:
common.raise_http_conflict_for_instance_invalid_state(state_error,
'evacuate', id)

View File

@ -242,6 +242,8 @@ class FloatingIPActionController(wsgi.Controller):
except exception.NoFloatingIpInterface:
msg = _('l3driver call to add floating ip failed')
raise webob.exc.HTTPBadRequest(explanation=msg)
except exception.InstanceUnknownCell as e:
raise webob.exc.HTTPNotFound(explanation=e.format_message())
except exception.FloatingIpNotFoundForAddress:
msg = _('floating ip not found')
raise webob.exc.HTTPNotFound(explanation=msg)

View File

@ -80,6 +80,8 @@ class MigrateServerController(wsgi.Controller):
instance = common.get_instance(self.compute_api, context, id)
self.compute_api.live_migrate(context, instance, block_migration,
disk_over_commit, host)
except exception.InstanceUnknownCell as e:
raise exc.HTTPNotFound(explanation=e.format_message())
except (exception.NoValidHost,
exception.ComputeServiceUnavailable,
exception.InvalidHypervisorType,

View File

@ -48,6 +48,8 @@ class MultinicController(wsgi.Controller):
network_id = body['addFixedIp']['networkId']
try:
self.compute_api.add_fixed_ip(context, instance, network_id)
except exception.InstanceUnknownCell as e:
raise exc.HTTPNotFound(explanation=e.format_message())
except exception.NoMoreFixedIps as e:
raise exc.HTTPBadRequest(explanation=e.format_message())
@ -65,6 +67,8 @@ class MultinicController(wsgi.Controller):
try:
self.compute_api.remove_fixed_ip(context, instance, address)
except exception.InstanceUnknownCell as e:
raise exc.HTTPNotFound(explanation=e.format_message())
except exception.FixedIpNotFoundForSpecificInstance as e:
raise exc.HTTPBadRequest(explanation=e.format_message())

View File

@ -46,7 +46,8 @@ class PauseServerController(wsgi.Controller):
except exception.InstanceInvalidState as state_error:
common.raise_http_conflict_for_instance_invalid_state(state_error,
'pause', id)
except exception.InstanceNotFound as e:
except (exception.InstanceUnknownCell,
exception.InstanceNotFound) as e:
raise exc.HTTPNotFound(explanation=e.format_message())
except NotImplementedError:
common.raise_feature_not_supported()
@ -66,7 +67,8 @@ class PauseServerController(wsgi.Controller):
except exception.InstanceInvalidState as state_error:
common.raise_http_conflict_for_instance_invalid_state(state_error,
'unpause', id)
except exception.InstanceNotFound as e:
except (exception.InstanceUnknownCell,
exception.InstanceNotFound) as e:
raise exc.HTTPNotFound(explanation=e.format_message())
except NotImplementedError:
common.raise_feature_not_supported()

View File

@ -56,7 +56,8 @@ class RemoteConsolesController(wsgi.Controller):
console_type)
except exception.ConsoleTypeUnavailable as e:
raise webob.exc.HTTPBadRequest(explanation=e.format_message())
except exception.InstanceNotFound as e:
except (exception.InstanceUnknownCell,
exception.InstanceNotFound) as e:
raise webob.exc.HTTPNotFound(explanation=e.format_message())
except exception.InstanceNotReady as e:
raise webob.exc.HTTPConflict(explanation=e.format_message())
@ -84,7 +85,8 @@ class RemoteConsolesController(wsgi.Controller):
console_type)
except exception.ConsoleTypeUnavailable as e:
raise webob.exc.HTTPBadRequest(explanation=e.format_message())
except exception.InstanceNotFound as e:
except (exception.InstanceUnknownCell,
exception.InstanceNotFound) as e:
raise webob.exc.HTTPNotFound(explanation=e.format_message())
except exception.InstanceNotReady as e:
raise webob.exc.HTTPConflict(explanation=e.format_message())
@ -114,7 +116,8 @@ class RemoteConsolesController(wsgi.Controller):
console_type)
except exception.ConsoleTypeUnavailable as e:
raise webob.exc.HTTPBadRequest(explanation=e.format_message())
except exception.InstanceNotFound as e:
except (exception.InstanceUnknownCell,
exception.InstanceNotFound) as e:
raise webob.exc.HTTPNotFound(explanation=e.format_message())
except exception.InstanceNotReady as e:
raise webob.exc.HTTPConflict(explanation=e.format_message())
@ -139,7 +142,8 @@ class RemoteConsolesController(wsgi.Controller):
output = self.compute_api.get_serial_console(context,
instance,
console_type)
except exception.InstanceNotFound as e:
except (exception.InstanceUnknownCell,
exception.InstanceNotFound) as e:
raise webob.exc.HTTPNotFound(explanation=e.format_message())
except exception.InstanceNotReady as e:
raise webob.exc.HTTPConflict(explanation=e.format_message())

View File

@ -65,6 +65,8 @@ class RescueController(wsgi.Controller):
self.compute_api.rescue(context, instance,
rescue_password=password,
rescue_image_ref=rescue_image_ref)
except exception.InstanceUnknownCell as e:
raise exc.HTTPNotFound(explanation=e.format_message())
except exception.InstanceIsLocked as e:
raise exc.HTTPConflict(explanation=e.format_message())
except exception.InstanceInvalidState as state_error:
@ -91,6 +93,8 @@ class RescueController(wsgi.Controller):
instance = common.get_instance(self.compute_api, context, id)
try:
self.compute_api.unrescue(context, instance)
except exception.InstanceUnknownCell as e:
raise exc.HTTPNotFound(explanation=e.format_message())
except exception.InstanceIsLocked as e:
raise exc.HTTPConflict(explanation=e.format_message())
except exception.InstanceInvalidState as state_error:

View File

@ -112,6 +112,9 @@ class ServerMetadataController(wsgi.Controller):
metadata,
delete)
except exception.InstanceUnknownCell as e:
raise exc.HTTPNotFound(explanation=e.format_message())
except exception.QuotaError as error:
raise exc.HTTPForbidden(explanation=error.format_message())
@ -151,6 +154,9 @@ class ServerMetadataController(wsgi.Controller):
try:
self.compute_api.delete_instance_metadata(context, server, id)
except exception.InstanceUnknownCell as e:
raise exc.HTTPNotFound(explanation=e.format_message())
except exception.InstanceIsLocked as e:
raise exc.HTTPConflict(explanation=e.format_message())

View File

@ -792,6 +792,8 @@ class ServersController(wsgi.Controller):
instance = self._get_server(context, req, id)
try:
self.compute_api.confirm_resize(context, instance)
except exception.InstanceUnknownCell as e:
raise exc.HTTPNotFound(explanation=e.format_message())
except exception.MigrationNotFound:
msg = _("Instance has not been resized.")
raise exc.HTTPBadRequest(explanation=msg)
@ -810,6 +812,8 @@ class ServersController(wsgi.Controller):
instance = self._get_server(context, req, id)
try:
self.compute_api.revert_resize(context, instance)
except exception.InstanceUnknownCell as e:
raise exc.HTTPNotFound(explanation=e.format_message())
except exception.MigrationNotFound:
msg = _("Instance has not been resized.")
raise exc.HTTPBadRequest(explanation=msg)
@ -849,6 +853,8 @@ class ServersController(wsgi.Controller):
try:
self.compute_api.resize(context, instance, flavor_id, **kwargs)
except exception.InstanceUnknownCell as e:
raise exc.HTTPNotFound(explanation=e.format_message())
except exception.QuotaError as error:
raise exc.HTTPForbidden(
explanation=error.format_message(),
@ -891,6 +897,8 @@ class ServersController(wsgi.Controller):
except exception.InstanceNotFound:
msg = _("Instance could not be found")
raise exc.HTTPNotFound(explanation=msg)
except exception.InstanceUnknownCell as e:
raise exc.HTTPNotFound(explanation=e.format_message())
except exception.InstanceIsLocked as e:
raise exc.HTTPConflict(explanation=e.format_message())
except exception.InstanceInvalidState as state_error:
@ -995,6 +1003,8 @@ class ServersController(wsgi.Controller):
except exception.InstanceNotFound:
msg = _("Instance could not be found")
raise exc.HTTPNotFound(explanation=msg)
except exception.InstanceUnknownCell as e:
raise exc.HTTPNotFound(explanation=e.format_message())
except exception.ImageNotFound:
msg = _("Cannot find image for rebuild")
raise exc.HTTPBadRequest(explanation=msg)
@ -1055,6 +1065,8 @@ class ServersController(wsgi.Controller):
instance,
image_name,
extra_properties=metadata)
except exception.InstanceUnknownCell as e:
raise exc.HTTPNotFound(explanation=e.format_message())
except exception.InstanceInvalidState as state_error:
common.raise_http_conflict_for_instance_invalid_state(state_error,
'createImage', id)
@ -1107,6 +1119,8 @@ class ServersController(wsgi.Controller):
self.compute_api.start(context, instance)
except (exception.InstanceNotReady, exception.InstanceIsLocked) as e:
raise webob.exc.HTTPConflict(explanation=e.format_message())
except exception.InstanceUnknownCell as e:
raise exc.HTTPNotFound(explanation=e.format_message())
except exception.InstanceInvalidState as state_error:
common.raise_http_conflict_for_instance_invalid_state(state_error,
'start', id)
@ -1124,6 +1138,8 @@ class ServersController(wsgi.Controller):
self.compute_api.stop(context, instance)
except (exception.InstanceNotReady, exception.InstanceIsLocked) as e:
raise webob.exc.HTTPConflict(explanation=e.format_message())
except exception.InstanceUnknownCell as e:
raise exc.HTTPNotFound(explanation=e.format_message())
except exception.InstanceInvalidState as state_error:
common.raise_http_conflict_for_instance_invalid_state(state_error,
'stop', id)

View File

@ -43,6 +43,8 @@ class ShelveController(wsgi.Controller):
instance = common.get_instance(self.compute_api, context, id)
try:
self.compute_api.shelve(context, instance)
except exception.InstanceUnknownCell as e:
raise exc.HTTPNotFound(explanation=e.format_message())
except exception.InstanceIsLocked as e:
raise exc.HTTPConflict(explanation=e.format_message())
except exception.InstanceInvalidState as state_error:
@ -60,6 +62,8 @@ class ShelveController(wsgi.Controller):
instance = common.get_instance(self.compute_api, context, id)
try:
self.compute_api.shelve_offload(context, instance)
except exception.InstanceUnknownCell as e:
raise exc.HTTPNotFound(explanation=e.format_message())
except exception.InstanceIsLocked as e:
raise exc.HTTPConflict(explanation=e.format_message())
except exception.InstanceInvalidState as state_error:
@ -77,6 +81,8 @@ class ShelveController(wsgi.Controller):
instance = common.get_instance(self.compute_api, context, id)
try:
self.compute_api.unshelve(context, instance)
except exception.InstanceUnknownCell as e:
raise exc.HTTPNotFound(explanation=e.format_message())
except exception.InstanceIsLocked as e:
raise exc.HTTPConflict(explanation=e.format_message())
except exception.InstanceInvalidState as state_error:

View File

@ -41,6 +41,8 @@ class SuspendServerController(wsgi.Controller):
try:
server = common.get_instance(self.compute_api, context, id)
self.compute_api.suspend(context, server)
except exception.InstanceUnknownCell as e:
raise exc.HTTPNotFound(explanation=e.format_message())
except exception.InstanceIsLocked as e:
raise exc.HTTPConflict(explanation=e.format_message())
except exception.InstanceInvalidState as state_error:
@ -57,6 +59,8 @@ class SuspendServerController(wsgi.Controller):
try:
server = common.get_instance(self.compute_api, context, id)
self.compute_api.resume(context, server)
except exception.InstanceUnknownCell as e:
raise exc.HTTPNotFound(explanation=e.format_message())
except exception.InstanceIsLocked as e:
raise exc.HTTPConflict(explanation=e.format_message())
except exception.InstanceInvalidState as state_error:

View File

@ -281,6 +281,8 @@ class VolumeAttachmentController(wsgi.Controller):
try:
device = self.compute_api.attach_volume(context, instance,
volume_id, device)
except exception.InstanceUnknownCell as e:
raise exc.HTTPNotFound(explanation=e.format_message())
except exception.VolumeNotFound as e:
raise exc.HTTPNotFound(explanation=e.format_message())
except exception.InstanceIsLocked as e:
@ -399,6 +401,8 @@ class VolumeAttachmentController(wsgi.Controller):
pass
except exception.InvalidVolume as e:
raise exc.HTTPBadRequest(explanation=e.format_message())
except exception.InstanceUnknownCell as e:
raise exc.HTTPNotFound(explanation=e.format_message())
except exception.InstanceIsLocked as e:
raise exc.HTTPConflict(explanation=e.format_message())