From b4576bae0620bb7e62475b3455c8b2fee6de3813 Mon Sep 17 00:00:00 2001 From: Stephen Finucane Date: 2024年11月15日 15:16:20 +0000 Subject: [PATCH] api: Add response body schemas for volumes APIs Change-Id: Ia40b1dcc637bca7b8fc48b486dab5cb4195aae67 Signed-off-by: Stephen Finucane --- nova/api/openstack/compute/schemas/volumes.py | 138 ++++++++++++++++++ nova/api/openstack/compute/volumes.py | 6 + 2 files changed, 144 insertions(+) diff --git a/nova/api/openstack/compute/schemas/volumes.py b/nova/api/openstack/compute/schemas/volumes.py index b14417aa2b34..2e82e5051b6c 100644 --- a/nova/api/openstack/compute/schemas/volumes.py +++ b/nova/api/openstack/compute/schemas/volumes.py @@ -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, +} diff --git a/nova/api/openstack/compute/volumes.py b/nova/api/openstack/compute/volumes.py index dabca6d13940..25078a2ab7dd 100644 --- a/nova/api/openstack/compute/volumes.py +++ b/nova/api/openstack/compute/volumes.py @@ -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']

AltStyle によって変換されたページ (->オリジナル) /