Extracted HTTP response codes to constants
There are several places in the source code where HTTP response codes are used as numeric values. Status codes 202, 204, 300 and 412 under api/v3 are replaced with symbolic constants from six.moves.http_client thus improves code readability. More patches will be submitted to address other status codes. Partial-Bug: #1520159 Change-Id: I60d8d99827bfa1a6fc5b6dbb67d1d1fb3a3b95fe
This commit is contained in:
parent
2db1f6bdef
commit
9f874a9ca0
|
@ -14,6 +14,7 @@
|
|||
"""The consistencygroups V3 api."""
|
||||
|
||||
from oslo_log import log as logging
|
||||
from six.moves import http_client
|
||||
import webob
|
||||
from webob import exc
|
||||
|
||||
|
@ -82,7 +83,7 @@ class ConsistencyGroupsController(cg_v2.ConsistencyGroupsController):
|
|||
remove_volumes)
|
||||
self._update(context, id, name, description, add_volumes,
|
||||
remove_volumes, allow_empty)
|
||||
return webob.Response(status_int=202)
|
||||
return webob.Response(status_int=http_client.ACCEPTED)
|
||||
|
||||
|
||||
def create_resource():
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
|
||||
from oslo_log import log as logging
|
||||
import six
|
||||
from six.moves import http_client
|
||||
import webob
|
||||
from webob import exc
|
||||
|
||||
|
@ -90,7 +91,7 @@ class GroupSnapshotsController(wsgi.Controller):
|
|||
LOG.exception(msg)
|
||||
raise exc.HTTPBadRequest(explanation=msg)
|
||||
|
||||
return webob.Response(status_int=202)
|
||||
return webob.Response(status_int=http_client.ACCEPTED)
|
||||
|
||||
@wsgi.Controller.api_version(GROUP_SNAPSHOT_API_VERSION)
|
||||
def index(self, req):
|
||||
|
@ -130,7 +131,7 @@ class GroupSnapshotsController(wsgi.Controller):
|
|||
return {'group_snapshots': new_group_snapshots}
|
||||
|
||||
@wsgi.Controller.api_version(GROUP_SNAPSHOT_API_VERSION)
|
||||
@wsgi.response(202)
|
||||
@wsgi.response(http_client.ACCEPTED)
|
||||
def create(self, req, body):
|
||||
"""Create a new group_snapshot."""
|
||||
LOG.debug('Creating new group_snapshot %s', body)
|
||||
|
@ -208,7 +209,7 @@ class GroupSnapshotsController(wsgi.Controller):
|
|||
{'error_message': error.msg,
|
||||
'id': id})
|
||||
raise exc.HTTPBadRequest(explanation=error.msg)
|
||||
return webob.Response(status_int=202)
|
||||
return webob.Response(status_int=http_client.ACCEPTED)
|
||||
|
||||
|
||||
def create_resource():
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
|
||||
"""The group types specs controller"""
|
||||
|
||||
from six.moves import http_client
|
||||
import webob
|
||||
|
||||
from cinder.api import common
|
||||
|
@ -59,7 +60,7 @@ class GroupTypeSpecsController(wsgi.Controller):
|
|||
return self._get_group_specs(context, group_type_id)
|
||||
|
||||
@wsgi.Controller.api_version('3.11')
|
||||
@wsgi.response(202)
|
||||
@wsgi.response(http_client.ACCEPTED)
|
||||
def create(self, req, group_type_id, body=None):
|
||||
context = req.environ['cinder.context']
|
||||
self._check_policy(context)
|
||||
|
@ -140,7 +141,7 @@ class GroupTypeSpecsController(wsgi.Controller):
|
|||
notifier.info(context,
|
||||
'group_type_specs.delete',
|
||||
notifier_info)
|
||||
return webob.Response(status_int=202)
|
||||
return webob.Response(status_int=http_client.ACCEPTED)
|
||||
|
||||
def _check_key_names(self, keys):
|
||||
if not common.validate_key_names(keys):
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
from oslo_utils import strutils
|
||||
import six
|
||||
from six.moves import http_client
|
||||
import webob
|
||||
from webob import exc
|
||||
|
||||
|
@ -53,7 +54,7 @@ class GroupTypesController(wsgi.Controller):
|
|||
rpc.get_notifier('groupType').info(context, method, payload)
|
||||
|
||||
@wsgi.Controller.api_version('3.11')
|
||||
@wsgi.response(202)
|
||||
@wsgi.response(http_client.ACCEPTED)
|
||||
def create(self, req, body):
|
||||
"""Creates a new group type."""
|
||||
context = req.environ['cinder.context']
|
||||
|
@ -183,7 +184,7 @@ class GroupTypesController(wsgi.Controller):
|
|||
context, 'group_type.delete', err, id=id)
|
||||
raise webob.exc.HTTPNotFound(explanation=err.msg)
|
||||
|
||||
return webob.Response(status_int=202)
|
||||
return webob.Response(status_int=http_client.ACCEPTED)
|
||||
|
||||
@wsgi.Controller.api_version('3.11')
|
||||
def index(self, req):
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
from oslo_log import log as logging
|
||||
from oslo_utils import strutils
|
||||
from oslo_utils import uuidutils
|
||||
from six.moves import http_client
|
||||
import webob
|
||||
from webob import exc
|
||||
|
||||
|
@ -105,7 +106,7 @@ class GroupsController(wsgi.Controller):
|
|||
{'error_message': error.msg,
|
||||
'id': id})
|
||||
raise exc.HTTPBadRequest(explanation=error.msg)
|
||||
return webob.Response(status_int=202)
|
||||
return webob.Response(status_int=http_client.ACCEPTED)
|
||||
|
||||
@wsgi.Controller.api_version(GROUP_API_VERSION)
|
||||
@wsgi.action("delete")
|
||||
|
@ -146,7 +147,7 @@ class GroupsController(wsgi.Controller):
|
|||
except exception.InvalidGroup as error:
|
||||
raise exc.HTTPBadRequest(explanation=error.msg)
|
||||
|
||||
return webob.Response(status_int=202)
|
||||
return webob.Response(status_int=http_client.ACCEPTED)
|
||||
|
||||
@wsgi.Controller.api_version(GROUP_API_VERSION)
|
||||
def index(self, req):
|
||||
|
@ -188,7 +189,7 @@ class GroupsController(wsgi.Controller):
|
|||
return groups
|
||||
|
||||
@wsgi.Controller.api_version(GROUP_API_VERSION)
|
||||
@wsgi.response(202)
|
||||
@wsgi.response(http_client.ACCEPTED)
|
||||
def create(self, req, body):
|
||||
"""Create a new group."""
|
||||
LOG.debug('Creating new group %s', body)
|
||||
|
@ -235,7 +236,7 @@ class GroupsController(wsgi.Controller):
|
|||
|
||||
@wsgi.Controller.api_version(GROUP_CREATE_FROM_SRC_API_VERSION)
|
||||
@wsgi.action("create-from-src")
|
||||
@wsgi.response(202)
|
||||
@wsgi.response(http_client.ACCEPTED)
|
||||
def create_from_src(self, req, body):
|
||||
"""Create a new group from a source.
|
||||
|
||||
|
@ -361,7 +362,7 @@ class GroupsController(wsgi.Controller):
|
|||
except exception.InvalidGroup as error:
|
||||
raise exc.HTTPBadRequest(explanation=error.msg)
|
||||
|
||||
return webob.Response(status_int=202)
|
||||
return webob.Response(status_int=http_client.ACCEPTED)
|
||||
|
||||
|
||||
def create_resource():
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
"""The messages API."""
|
||||
|
||||
|
||||
from six.moves import http_client
|
||||
import webob
|
||||
|
||||
from cinder.api import common
|
||||
|
@ -73,7 +74,7 @@ class MessagesController(wsgi.Controller):
|
|||
check_policy(context, 'delete', message)
|
||||
self.message_api.delete(context, message)
|
||||
|
||||
return webob.Response(status_int=204)
|
||||
return webob.Response(status_int=http_client.NO_CONTENT)
|
||||
|
||||
@wsgi.Controller.api_version(MESSAGES_BASE_MICRO_VERSION)
|
||||
def index(self, req):
|
||||
|
|
|
@ -12,6 +12,8 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from six.moves import http_client
|
||||
|
||||
from cinder.api.contrib import snapshot_manage as snapshot_manage_v2
|
||||
from cinder.api.openstack import wsgi
|
||||
from cinder.api.v3 import resource_common_manage as common
|
||||
|
@ -23,7 +25,7 @@ class SnapshotManageController(common.ManageResource,
|
|||
super(SnapshotManageController, self).__init__(*args, **kwargs)
|
||||
self._set_resource_type('snapshot')
|
||||
|
||||
@wsgi.response(202)
|
||||
@wsgi.response(http_client.ACCEPTED)
|
||||
def create(self, req, body):
|
||||
self._ensure_min_version(req, "3.8")
|
||||
return super(SnapshotManageController, self).create(req, body)
|
||||
|
|
|
@ -12,6 +12,8 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from six.moves import http_client
|
||||
|
||||
from cinder.api.contrib import volume_manage as volume_manage_v2
|
||||
from cinder.api.openstack import wsgi
|
||||
from cinder.api.v3 import resource_common_manage as common
|
||||
|
@ -23,7 +25,7 @@ class VolumeManageController(common.ManageResource,
|
|||
super(VolumeManageController, self).__init__(*args, **kwargs)
|
||||
self._set_resource_type('volume')
|
||||
|
||||
@wsgi.response(202)
|
||||
@wsgi.response(http_client.ACCEPTED)
|
||||
def create(self, req, body):
|
||||
self._ensure_min_version(req, "3.8")
|
||||
return super(VolumeManageController, self).create(req, body)
|
||||
|
|
|
@ -19,6 +19,7 @@ import hashlib
|
|||
|
||||
from oslo_serialization import jsonutils
|
||||
import six
|
||||
from six.moves import http_client
|
||||
import webob
|
||||
|
||||
from cinder.api.openstack import wsgi
|
||||
|
@ -63,7 +64,7 @@ class Controller(volume_meta_v2.Controller):
|
|||
def update(self, req, volume_id, id, body):
|
||||
self._ensure_min_version(req, METADATA_MICRO_VERSION)
|
||||
if not self._validate_etag(req, volume_id):
|
||||
return webob.Response(status_int=412)
|
||||
return webob.Response(status_int=http_client.PRECONDITION_FAILED)
|
||||
return super(Controller, self).update(req, volume_id,
|
||||
id, body)
|
||||
|
||||
|
@ -71,7 +72,7 @@ class Controller(volume_meta_v2.Controller):
|
|||
def update_all(self, req, volume_id, body):
|
||||
self._ensure_min_version(req, METADATA_MICRO_VERSION)
|
||||
if not self._validate_etag(req, volume_id):
|
||||
return webob.Response(status_int=412)
|
||||
return webob.Response(status_int=http_client.PRECONDITION_FAILED)
|
||||
return super(Controller, self).update_all(req, volume_id,
|
||||
body)
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
|
||||
from oslo_log import log as logging
|
||||
from oslo_utils import uuidutils
|
||||
from six.moves import http_client
|
||||
import webob
|
||||
from webob import exc
|
||||
|
||||
|
@ -146,7 +147,7 @@ class VolumeController(volumes_v2.VolumeController):
|
|||
volumes = self.volume_api.get_volume_summary(context, filters=filters)
|
||||
return view_builder_v3.quick_summary(volumes[0], int(volumes[1]))
|
||||
|
||||
@wsgi.response(202)
|
||||
@wsgi.response(http_client.ACCEPTED)
|
||||
def create(self, req, body):
|
||||
"""Creates a new volume.
|
||||
|
||||
|
|
|
@ -17,6 +17,8 @@
|
|||
|
||||
import copy
|
||||
|
||||
from six.moves import http_client
|
||||
|
||||
from cinder.api import extensions
|
||||
from cinder.api import openstack
|
||||
from cinder.api.openstack import api_version_request
|
||||
|
@ -118,7 +120,7 @@ class VersionsController(wsgi.Controller):
|
|||
# /v1, /v2, or /v3 in the URL will lead to this unversioned
|
||||
# method, which should always return info about all
|
||||
# available versions.
|
||||
@wsgi.response(300)
|
||||
@wsgi.response(http_client.MULTIPLE_CHOICES)
|
||||
def all(self, req):
|
||||
"""Return all known versions."""
|
||||
builder = views_versions.get_view_builder(req)
|
||||
|
|
Loading…
Reference in New Issue