Merge "api: Add response body schemas for volumes APIs"

This commit is contained in:
Zuul
2025年11月11日 20:10:29 +00:00
committed by Gerrit Code Review

View File

@@ -13,6 +13,7 @@
# under the License.
from nova.api.validation import parameter_types
from nova.api.validation import response_types
create = {
'type': 'object',
@@ -59,3 +60,140 @@ show_query = {
'properties': {},
'additionalProperties': True
}
_volume_response = {
'type': 'object',
'properties': {
'attachments': {
'type': 'array',
# either a list of attachments or a list with a single empty object
'oneOf': [
{
'items': {
'type': 'object',
'properties': {
'id': {'type': 'string', 'format': 'uuid'},
'device': {'type': 'string'},
'serverId': {'type': 'string', 'format': 'uuid'},
'volumeId': {'type': 'string', 'format': 'uuid'},
},
'required': ['id', 'serverId', 'volumeId'],
'additionalProperties': False,
},
},
{
'prefixItems': [
{
'type': 'object',
'properties': {},
'required': [],
'additionalProperties': False,
}
],
},
],
'additionalItems': False,
},
'availabilityZone': {'type': ['string', 'null']},
'createdAt': {'type': 'string', 'format': 'date-time'},
'displayDescription': {'type': ['string', 'null']},
'displayName': {'type': ['string', 'null']},
'id': {'type': 'string', 'format': 'uuid'},
'metadata': response_types.metadata,
'size': {'type': 'integer'},
'snapshotId': {
'oneOf': [
{'type': 'string', 'format': 'uuid'},
{'type': 'null'},
],
},
'status': {
'type': 'string',
# https://github.com/openstack/cinder/blob/26.0.0/cinder/objects/fields.py#L168-L190
'enum': [
'creating',
'available',
'deleting',
'error',
'error_deleting',
# 'error_managing' is mapped to 'error'
# 'managing' is mapped to 'creating'
'attaching',
'in-use',
'detaching',
'maintenance',
'restoring-backup',
'error_restoring',
'reserved',
'awaiting-transfer',
'backing-up',
'error_backing-up',
'error_extending',
'downloading',
'uploading',
'retyping',
'extending',
],
},
'volumeType': {'type': ['string', 'null']},
},
'required': [
'attachments',
'availabilityZone',
'createdAt',
'displayDescription',
'displayName',
'id',
'metadata',
'size',
'snapshotId',
'status',
'volumeType',
],
'additionalProperties': False,
}
show_response = {
'type': 'object',
'properties': {
'volume': _volume_response,
},
'required': ['volume'],
'additionalProperties': False,
}
delete_response = {'type': 'null'}
# NOTE(stephenfin): Yes, the index and detail responses are exactly the same
index_response = {
'type': 'object',
'properties': {
'volumes': {
'type': 'array',
'items': _volume_response,
},
},
'required': ['volumes'],
'additionalProperties': False,
}
detail_response = {
'type': 'object',
'properties': {
'volumes': {
'type': 'array',
'items': _volume_response,
},
},
'required': ['volumes'],
'additionalProperties': False,
}
create_response = {
'type': 'object',
'properties': {
'volume': _volume_response,
},
'required': ['volume'],
'additionalProperties': False,
}

View File

@@ -89,6 +89,7 @@ def _translate_volume_summary_view(context, vol):
return d
@validation.validated
class VolumeController(wsgi.Controller):
"""The Volumes API controller for the OpenStack API."""
@@ -99,6 +100,7 @@ class VolumeController(wsgi.Controller):
@wsgi.api_version("2.1", MAX_PROXY_API_SUPPORT_VERSION)
@wsgi.expected_errors(404)
@validation.query_schema(schema.show_query)
@validation.response_body_schema(schema.show_response)
def show(self, req, id):
"""Return data about the given volume."""
context = req.environ['nova.context']
@@ -116,6 +118,7 @@ class VolumeController(wsgi.Controller):
@wsgi.api_version("2.1", MAX_PROXY_API_SUPPORT_VERSION)
@wsgi.response(202)
@wsgi.expected_errors((400, 404))
@validation.response_body_schema(schema.delete_response)
def delete(self, req, id):
"""Delete a volume."""
context = req.environ['nova.context']
@@ -133,6 +136,7 @@ class VolumeController(wsgi.Controller):
@wsgi.api_version("2.1", MAX_PROXY_API_SUPPORT_VERSION)
@wsgi.expected_errors(())
@validation.query_schema(schema.index_query)
@validation.response_body_schema(schema.index_response)
def index(self, req):
"""Returns a summary list of volumes."""
context = req.environ['nova.context']
@@ -144,6 +148,7 @@ class VolumeController(wsgi.Controller):
@wsgi.api_version("2.1", MAX_PROXY_API_SUPPORT_VERSION)
@wsgi.expected_errors(())
@validation.query_schema(schema.detail_query)
@validation.response_body_schema(schema.detail_response)
def detail(self, req):
"""Returns a detailed list of volumes."""
context = req.environ['nova.context']
@@ -164,6 +169,7 @@ class VolumeController(wsgi.Controller):
@wsgi.api_version("2.1", MAX_PROXY_API_SUPPORT_VERSION)
@wsgi.expected_errors((400, 403, 404))
@validation.schema(schema.create)
@validation.response_body_schema(schema.create_response)
def create(self, req, body):
"""Creates a new volume."""
context = req.environ['nova.context']
Reference in New Issue
openstack/nova
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.

The note is not visible to the blocked user.