Add and use raise_feature_not_supported()

In HTTPNotImplemented cases, each API passes its original message.
The meaning of these messages are almost the same but messages are
inconsistent.
This patch adds common raise_feature_not_supported() and replaces
these messages with the method for consistent message.

Partially implements blueprint v2-on-v3-api

Change-Id: I23da9bf153cb92944c0f4e76d70ce72a4ff6b16f
This commit is contained in:
Ken'ichi Ohmichi 2015-03-09 00:40:29 +00:00
parent 5a1a1b7b71
commit 735c45070e
14 changed files with 46 additions and 71 deletions

View File

@ -536,11 +536,16 @@ def get_instance(compute_api, context, instance_id, expected_attrs=None):
raise exc.HTTPNotFound(explanation=e.format_message())
def raise_feature_not_supported(msg=None):
if msg is None:
msg = _("The requested functionality is not supported.")
raise webob.exc.HTTPNotImplemented(explanation=msg)
def check_cells_enabled(function):
@functools.wraps(function)
def inner(*args, **kwargs):
if not CONF.cells.enable:
msg = _("Cells is not enabled.")
raise webob.exc.HTTPNotImplemented(explanation=msg)
raise_feature_not_supported()
return function(*args, **kwargs)
return inner

View File

@ -56,7 +56,7 @@ class AdminPasswordController(wsgi.Controller):
e, 'changePassword', id)
except NotImplementedError:
msg = _("Unable to set password on instance")
raise exc.HTTPNotImplemented(explanation=msg)
common.raise_feature_not_supported(msg=msg)
class AdminPassword(extensions.V3APIExtensionBase):

View File

@ -128,8 +128,7 @@ class InterfaceAttachmentController(wsgi.Controller):
exception.NetworkNotFound) as e:
raise exc.HTTPNotFound(explanation=e.format_message())
except NotImplementedError:
msg = _("The requested functionality is not supported.")
raise webob.exc.HTTPNotImplemented(explanation=msg)
common.raise_feature_not_supported()
except exception.InterfaceAttachFailed as e:
raise webob.exc.HTTPInternalServerError(
explanation=e.format_message())
@ -156,8 +155,7 @@ class InterfaceAttachmentController(wsgi.Controller):
except exception.InstanceIsLocked as e:
raise exc.HTTPConflict(explanation=e.format_message())
except NotImplementedError:
msg = _("The requested functionality is not supported.")
raise webob.exc.HTTPNotImplemented(explanation=msg)
common.raise_feature_not_supported()
except exception.InstanceInvalidState as state_error:
common.raise_http_conflict_for_instance_invalid_state(state_error,
'detach_interface', server_id)
@ -175,8 +173,7 @@ class InterfaceAttachmentController(wsgi.Controller):
except exception.NotFound as e:
raise exc.HTTPNotFound(explanation=e.format_message())
except NotImplementedError:
msg = _("Network driver does not support this function.")
raise webob.exc.HTTPNotImplemented(explanation=msg)
common.raise_feature_not_supported()
ports = data.get('ports', [])
results = [entity_maker(port) for port in ports]

View File

@ -20,6 +20,7 @@ from oslo_config import cfg
from oslo_utils import importutils
import webob
from nova.api.openstack import common
from nova.api.openstack import extensions
from nova.api.openstack import wsgi
from nova.i18n import _
@ -59,8 +60,7 @@ CONF.import_opt('compute_driver', 'nova.virt.driver')
def _check_ironic_client_enabled():
"""Check whether Ironic is installed or not."""
if ironic_client is None:
msg = _("Ironic client unavailable, cannot access Ironic.")
raise webob.exc.HTTPNotImplemented(explanation=msg)
common.raise_feature_not_supported()
def _get_ironic_client():

View File

@ -14,6 +14,7 @@
import webob.exc
from nova.api.openstack import common
from nova.api.openstack import extensions
from nova.api.openstack import wsgi
import nova.cert.rpcapi
@ -47,7 +48,10 @@ class CertificatesController(wsgi.Controller):
authorize(context, action='show')
if id != 'root':
msg = _("Only root certificate can be retrieved.")
raise webob.exc.HTTPNotImplemented(explanation=msg)
# TODO(oomichi): This seems a HTTPBadRequest case because of the
# above message. This will be changed with a microversion in the
# future.
common.raise_feature_not_supported(msg=msg)
try:
cert = self.cert_rpcapi.fetch_ca(context,
project_id=context.project_id)

View File

@ -25,7 +25,6 @@ from nova.api.openstack import wsgi
from nova.api import validation
from nova import compute
from nova import exception
from nova.i18n import _
ALIAS = "os-console-output"
authorize = extensions.os_compute_authorizer(ALIAS)
@ -61,8 +60,7 @@ class ConsoleOutputController(wsgi.Controller):
except exception.InstanceNotReady as e:
raise webob.exc.HTTPConflict(explanation=e.format_message())
except NotImplementedError:
msg = _("Unable to get console log, functionality not implemented")
raise webob.exc.HTTPNotImplemented(explanation=msg)
common.raise_feature_not_supported()
# XML output is not correctly escaped, so remove invalid characters
# NOTE(cyeoh): We don't support XML output with V2.1, but for

View File

@ -17,6 +17,7 @@ import urllib
from oslo_utils import netutils
import webob
from nova.api.openstack import common
from nova.api.openstack.compute.schemas.v3 import floating_ip_dns
from nova.api.openstack import extensions
from nova.api.openstack import wsgi
@ -95,8 +96,7 @@ class FloatingIPDNSDomainController(wsgi.Controller):
try:
domains = self.network_api.get_dns_domains(context)
except NotImplementedError:
msg = _("Unable to create dns domain")
raise webob.exc.HTTPNotImplemented(explanation=msg)
common.raise_feature_not_supported()
domainlist = [_create_domain_entry(domain['domain'],
domain.get('scope'),
@ -135,8 +135,7 @@ class FloatingIPDNSDomainController(wsgi.Controller):
try:
create_dns_domain(context, fqdomain, area)
except NotImplementedError:
msg = _("Unable to create dns domain")
raise webob.exc.HTTPNotImplemented(explanation=msg)
common.raise_feature_not_supported()
return _translate_domain_entry_view({'domain': fqdomain,
'scope': scope,
@ -154,8 +153,7 @@ class FloatingIPDNSDomainController(wsgi.Controller):
try:
self.network_api.delete_dns_domain(context, domain)
except NotImplementedError:
msg = _("Unable to delete dns domain")
raise webob.exc.HTTPNotImplemented(explanation=msg)
common.raise_feature_not_supported()
except exception.NotFound as e:
raise webob.exc.HTTPNotFound(explanation=e.format_message())
@ -189,8 +187,7 @@ class FloatingIPDNSEntryController(wsgi.Controller):
id,
domain)
except NotImplementedError:
msg = _("Unable to get dns domain")
raise webob.exc.HTTPNotImplemented(explanation=msg)
common.raise_feature_not_supported()
if not entries:
explanation = _("DNS entries not found.")
@ -229,8 +226,7 @@ class FloatingIPDNSEntryController(wsgi.Controller):
self.network_api.modify_dns_entry(context, name,
address, domain)
except NotImplementedError:
msg = _("Unable to update dns domain")
raise webob.exc.HTTPNotImplemented(explanation=msg)
common.raise_feature_not_supported()
return _translate_dns_entry_view({'ip': address,
'name': name,
@ -249,8 +245,7 @@ class FloatingIPDNSEntryController(wsgi.Controller):
try:
self.network_api.delete_dns_entry(context, name, domain)
except NotImplementedError:
msg = _("Unable to delete dns domain")
raise webob.exc.HTTPNotImplemented(explanation=msg)
common.raise_feature_not_supported()
except exception.NotFound as e:
raise webob.exc.HTTPNotFound(explanation=e.format_message())

View File

@ -19,13 +19,13 @@ from oslo_log import log as logging
import six
import webob.exc
from nova.api.openstack import common
from nova.api.openstack.compute.schemas.v3 import hosts
from nova.api.openstack import extensions
from nova.api.openstack import wsgi
from nova.api import validation
from nova import compute
from nova import exception
from nova.i18n import _
from nova.i18n import _LI
from nova import objects
@ -138,8 +138,7 @@ class HostController(wsgi.Controller):
try:
result = self.api.set_host_maintenance(context, host_name, mode)
except NotImplementedError:
msg = _("Virt driver does not implement host maintenance mode.")
raise webob.exc.HTTPNotImplemented(explanation=msg)
common.raise_feature_not_supported()
except exception.HostNotFound as e:
raise webob.exc.HTTPNotFound(explanation=e.format_message())
except exception.ComputeServiceUnavailable as e:
@ -161,8 +160,7 @@ class HostController(wsgi.Controller):
result = self.api.set_host_enabled(context, host_name=host_name,
enabled=enabled)
except NotImplementedError:
msg = _("Virt driver does not implement host disabled status.")
raise webob.exc.HTTPNotImplemented(explanation=msg)
common.raise_feature_not_supported()
except exception.HostNotFound as e:
raise webob.exc.HTTPNotFound(explanation=e.format_message())
except exception.ComputeServiceUnavailable as e:
@ -179,8 +177,7 @@ class HostController(wsgi.Controller):
result = self.api.host_power_action(context, host_name=host_name,
action=action)
except NotImplementedError:
msg = _("Virt driver does not implement host power management.")
raise webob.exc.HTTPNotImplemented(explanation=msg)
common.raise_feature_not_supported()
except exception.HostNotFound as e:
raise webob.exc.HTTPNotFound(explanation=e.format_message())
except exception.ComputeServiceUnavailable as e:

View File

@ -17,6 +17,7 @@
import webob.exc
from nova.api.openstack import common
from nova.api.openstack import extensions
from nova.api.openstack import wsgi
from nova import compute
@ -129,8 +130,7 @@ class HypervisorsController(wsgi.Controller):
host = hyp.host
uptime = self.host_api.get_host_uptime(context, host)
except NotImplementedError:
msg = _("Virt driver does not implement uptime function.")
raise webob.exc.HTTPNotImplemented(explanation=msg)
common.raise_feature_not_supported()
service = self.host_api.service_get_by_compute_host(context, host)
return dict(hypervisor=self._view_hypervisor(hyp, service, False,

View File

@ -17,6 +17,7 @@
import netaddr
from webob import exc
from nova.api.openstack import common
from nova.api.openstack.compute.schemas.v3 import networks as schema
from nova.api.openstack import extensions
from nova.api.openstack import wsgi
@ -102,9 +103,7 @@ class NetworkController(wsgi.Controller):
msg = _("Network not found")
raise exc.HTTPNotFound(explanation=msg)
except NotImplementedError:
msg = _('Disassociate network is not implemented by the '
'configured Network API')
raise exc.HTTPNotImplemented(explanation=msg)
common.raise_feature_not_supported()
@extensions.expected_errors(404)
def show(self, req, id):
@ -170,8 +169,7 @@ class NetworkController(wsgi.Controller):
self.network_api.add_network_to_project(
context, project_id, network_id)
except NotImplementedError:
msg = (_("VLAN support must be enabled"))
raise exc.HTTPNotImplemented(explanation=msg)
common.raise_feature_not_supported()
except (exception.NoMoreNetworks,
exception.NetworkNotFoundForUUID) as e:
raise exc.HTTPBadRequest(explanation=e.format_message())

View File

@ -12,6 +12,7 @@
from webob import exc
from nova.api.openstack import common
from nova.api.openstack.compute.schemas.v3 import networks_associate
from nova.api.openstack import extensions
from nova.api.openstack import wsgi
@ -43,9 +44,7 @@ class NetworkAssociateActionController(wsgi.Controller):
msg = _("Network not found")
raise exc.HTTPNotFound(explanation=msg)
except NotImplementedError:
msg = _('Disassociate host is not implemented by the configured '
'Network API')
raise exc.HTTPNotImplemented(explanation=msg)
common.raise_feature_not_supported()
@wsgi.action("disassociate_project")
@wsgi.response(202)
@ -59,9 +58,7 @@ class NetworkAssociateActionController(wsgi.Controller):
msg = _("Network not found")
raise exc.HTTPNotFound(explanation=msg)
except NotImplementedError:
msg = _('Disassociate project is not implemented by the '
'configured Network API')
raise exc.HTTPNotImplemented(explanation=msg)
common.raise_feature_not_supported()
@wsgi.action("associate_host")
@wsgi.response(202)
@ -78,9 +75,7 @@ class NetworkAssociateActionController(wsgi.Controller):
msg = _("Network not found")
raise exc.HTTPNotFound(explanation=msg)
except NotImplementedError:
msg = _('Associate host is not implemented by the configured '
'Network API')
raise exc.HTTPNotImplemented(explanation=msg)
common.raise_feature_not_supported()
class NetworksAssociate(extensions.V3APIExtensionBase):

View File

@ -20,7 +20,6 @@ from nova.api.openstack import extensions
from nova.api.openstack import wsgi
from nova import compute
from nova import exception
from nova.i18n import _
ALIAS = "os-pause-server"
@ -50,8 +49,7 @@ class PauseServerController(wsgi.Controller):
except exception.InstanceNotFound as e:
raise exc.HTTPNotFound(explanation=e.format_message())
except NotImplementedError:
msg = _("Virt driver does not implement pause function.")
raise exc.HTTPNotImplemented(explanation=msg)
common.raise_feature_not_supported()
@wsgi.response(202)
@extensions.expected_errors((404, 409, 501))
@ -71,8 +69,7 @@ class PauseServerController(wsgi.Controller):
except exception.InstanceNotFound as e:
raise exc.HTTPNotFound(explanation=e.format_message())
except NotImplementedError:
msg = _("Virt driver does not implement pause function.")
raise exc.HTTPNotImplemented(explanation=msg)
common.raise_feature_not_supported()
class PauseServer(extensions.V3APIExtensionBase):

View File

@ -21,7 +21,6 @@ from nova.api.openstack import wsgi
from nova.api import validation
from nova import compute
from nova import exception
from nova.i18n import _
ALIAS = "os-remote-consoles"
@ -56,8 +55,7 @@ class RemoteConsolesController(wsgi.Controller):
except exception.InstanceNotReady as e:
raise webob.exc.HTTPConflict(explanation=e.format_message())
except NotImplementedError:
msg = _("Unable to get vnc console, functionality not implemented")
raise webob.exc.HTTPNotImplemented(explanation=msg)
common.raise_feature_not_supported()
return {'console': {'type': console_type, 'url': output['url']}}
@ -84,9 +82,7 @@ class RemoteConsolesController(wsgi.Controller):
except exception.InstanceNotReady as e:
raise webob.exc.HTTPConflict(explanation=e.format_message())
except NotImplementedError:
msg = _("Unable to get spice console, "
"functionality not implemented")
raise webob.exc.HTTPNotImplemented(explanation=msg)
common.raise_feature_not_supported()
return {'console': {'type': console_type, 'url': output['url']}}
@ -115,8 +111,7 @@ class RemoteConsolesController(wsgi.Controller):
except exception.InstanceNotReady as e:
raise webob.exc.HTTPConflict(explanation=e.format_message())
except NotImplementedError:
msg = _("Unable to get rdp console, functionality not implemented")
raise webob.exc.HTTPNotImplemented(explanation=msg)
common.raise_feature_not_supported()
return {'console': {'type': console_type, 'url': output['url']}}
@ -145,9 +140,7 @@ class RemoteConsolesController(wsgi.Controller):
exception.SocketPortRangeExhaustedException) as e:
raise webob.exc.HTTPBadRequest(explanation=e.format_message())
except NotImplementedError:
msg = _("Unable to get serial console, "
"functionality not implemented")
raise webob.exc.HTTPNotImplemented(explanation=msg)
common.raise_feature_not_supported()
return {'console': {'type': console_type, 'url': output['url']}}

View File

@ -13,14 +13,11 @@
# License for the specific language governing permissions and limitations
# under the License.
import webob.exc
from nova.api.openstack import common
from nova.api.openstack import extensions
from nova.api.openstack import wsgi
from nova import compute
from nova import exception
from nova.i18n import _
ALIAS = "os-server-diagnostics"
@ -49,8 +46,7 @@ class ServerDiagnosticsController(wsgi.Controller):
common.raise_http_conflict_for_instance_invalid_state(state_error,
'get_diagnostics', server_id)
except NotImplementedError:
msg = _("Unable to get diagnostics, functionality not implemented")
raise webob.exc.HTTPNotImplemented(explanation=msg)
common.raise_feature_not_supported()
class ServerDiagnostics(extensions.V3APIExtensionBase):