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

This commit is contained in:
Zuul
2025-11-18 17:54:16 +00:00
committed by Gerrit Code Review
2 changed files with 96 additions and 8 deletions
@@ -51,3 +51,85 @@ show_query = {
'properties': {},
'additionalProperties': True
}
_snapshot_response = {
'type': 'object',
'properties': {
'createdAt': {'type': 'string', 'format': 'date-time'},
'displayDescription': {'type': ['string', 'null']},
'displayName': {'type': ['string', 'null']},
'id': {'type': 'string', 'format': 'uuid'},
'volumeId': {'type': 'string', 'format': 'uuid'},
'size': {'type': 'integer'},
'status': {
'type': 'string',
# https://github.com/openstack/cinder/blob/26.0.0/cinder/objects/fields.py#L120-L129
'enum': [
'error',
'available',
'creating',
'deleting',
'deleted',
# 'updating' is omitted since it is unused in Cinder
'error_deleting',
'unmanaging',
'backing-up',
'restoring',
],
},
},
'required': [
'createdAt',
'displayDescription',
'displayName',
'id',
'volumeId',
'size',
'status',
],
'additionalProperties': False,
}
show_response = {
'type': 'object',
'properties': {
'snapshot': _snapshot_response,
},
'required': ['snapshot'],
'additionalProperties': False,
}
delete_response = {'type': 'null'}
index_response = {
'type': 'object',
'properties': {
'snapshots': {
'type': 'array',
'items': _snapshot_response,
},
},
'required': ['snapshots'],
'additionalProperties': False,
}
detail_response = {
'type': 'object',
'properties': {
'snapshots': {
'type': 'array',
'items': _snapshot_response,
},
},
'required': ['snapshots'],
'additionalProperties': False,
}
create_response = {
'type': 'object',
'properties': {
'snapshot': _snapshot_response,
},
'required': ['snapshot'],
'additionalProperties': False,
}
+14 -8
View File
@@ -34,21 +34,22 @@ def _translate_snapshot_detail_view(context, vol):
return _translate_snapshot_summary_view(context, vol)
def _translate_snapshot_summary_view(context, vol):
def _translate_snapshot_summary_view(context, snapshot):
"""Maps keys for snapshots summary view."""
d = {}
d['id'] = vol['id']
d['volumeId'] = vol['volume_id']
d['status'] = vol['status']
d['id'] = snapshot['id']
d['volumeId'] = snapshot['volume_id']
d['status'] = snapshot['status']
# NOTE(gagupta): We map volume_size as the snapshot size
d['size'] = vol['volume_size']
d['createdAt'] = vol['created_at']
d['displayName'] = vol['display_name']
d['displayDescription'] = vol['display_description']
d['size'] = snapshot['volume_size']
d['createdAt'] = snapshot['created_at']
d['displayName'] = snapshot['display_name']
d['displayDescription'] = snapshot['display_description']
return d
@validation.validated
class SnapshotController(wsgi.Controller):
"""The Snapshots API controller for the OpenStack API."""
@@ -59,6 +60,7 @@ class SnapshotController(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 snapshot."""
context = req.environ['nova.context']
@@ -76,6 +78,7 @@ class SnapshotController(wsgi.Controller):
@wsgi.api_version("2.1", MAX_PROXY_API_SUPPORT_VERSION)
@wsgi.response(202)
@wsgi.expected_errors(404)
@validation.response_body_schema(schema.delete_response)
def delete(self, req, id):
"""Delete a snapshot."""
context = req.environ['nova.context']
@@ -91,6 +94,7 @@ class SnapshotController(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 snapshots."""
context = req.environ['nova.context']
@@ -102,6 +106,7 @@ class SnapshotController(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 snapshots."""
context = req.environ['nova.context']
@@ -122,6 +127,7 @@ class SnapshotController(wsgi.Controller):
@wsgi.api_version("2.1", MAX_PROXY_API_SUPPORT_VERSION)
@wsgi.expected_errors((400, 403))
@validation.schema(schema.create)
@validation.response_body_schema(schema.create_response)
def create(self, req, body):
"""Creates a new snapshot."""
context = req.environ['nova.context']