Skip to content

Commit c5ebda4

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "api: Add response body schemas for snapshots APIs"
2 parents 0c33871 + 626a4fd commit c5ebda4

2 files changed

Lines changed: 96 additions & 8 deletions

File tree

nova/api/openstack/compute/schemas/snapshots.py

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,85 @@
5151
'properties': {},
5252
'additionalProperties': True
5353
}
54+
55+
_snapshot_response = {
56+
'type': 'object',
57+
'properties': {
58+
'createdAt': {'type': 'string', 'format': 'date-time'},
59+
'displayDescription': {'type': ['string', 'null']},
60+
'displayName': {'type': ['string', 'null']},
61+
'id': {'type': 'string', 'format': 'uuid'},
62+
'volumeId': {'type': 'string', 'format': 'uuid'},
63+
'size': {'type': 'integer'},
64+
'status': {
65+
'type': 'string',
66+
# https://github.com/openstack/cinder/blob/26.0.0/cinder/objects/fields.py#L120-L129
67+
'enum': [
68+
'error',
69+
'available',
70+
'creating',
71+
'deleting',
72+
'deleted',
73+
# 'updating' is omitted since it is unused in Cinder
74+
'error_deleting',
75+
'unmanaging',
76+
'backing-up',
77+
'restoring',
78+
],
79+
},
80+
},
81+
'required': [
82+
'createdAt',
83+
'displayDescription',
84+
'displayName',
85+
'id',
86+
'volumeId',
87+
'size',
88+
'status',
89+
],
90+
'additionalProperties': False,
91+
}
92+
93+
show_response = {
94+
'type': 'object',
95+
'properties': {
96+
'snapshot': _snapshot_response,
97+
},
98+
'required': ['snapshot'],
99+
'additionalProperties': False,
100+
}
101+
102+
delete_response = {'type': 'null'}
103+
104+
index_response = {
105+
'type': 'object',
106+
'properties': {
107+
'snapshots': {
108+
'type': 'array',
109+
'items': _snapshot_response,
110+
},
111+
},
112+
'required': ['snapshots'],
113+
'additionalProperties': False,
114+
}
115+
116+
detail_response = {
117+
'type': 'object',
118+
'properties': {
119+
'snapshots': {
120+
'type': 'array',
121+
'items': _snapshot_response,
122+
},
123+
},
124+
'required': ['snapshots'],
125+
'additionalProperties': False,
126+
}
127+
128+
create_response = {
129+
'type': 'object',
130+
'properties': {
131+
'snapshot': _snapshot_response,
132+
},
133+
'required': ['snapshot'],
134+
'additionalProperties': False,
135+
}

nova/api/openstack/compute/snapshots.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,22 @@ def _translate_snapshot_detail_view(context, vol):
3434
return _translate_snapshot_summary_view(context, vol)
3535

3636

37-
def _translate_snapshot_summary_view(context, vol):
37+
def _translate_snapshot_summary_view(context, snapshot):
3838
"""Maps keys for snapshots summary view."""
3939
d = {}
4040

41-
d['id'] = vol['id']
42-
d['volumeId'] = vol['volume_id']
43-
d['status'] = vol['status']
41+
d['id'] = snapshot['id']
42+
d['volumeId'] = snapshot['volume_id']
43+
d['status'] = snapshot['status']
4444
# NOTE(gagupta): We map volume_size as the snapshot size
45-
d['size'] = vol['volume_size']
46-
d['createdAt'] = vol['created_at']
47-
d['displayName'] = vol['display_name']
48-
d['displayDescription'] = vol['display_description']
45+
d['size'] = snapshot['volume_size']
46+
d['createdAt'] = snapshot['created_at']
47+
d['displayName'] = snapshot['display_name']
48+
d['displayDescription'] = snapshot['display_description']
4949
return d
5050

5151

52+
@validation.validated
5253
class SnapshotController(wsgi.Controller):
5354
"""The Snapshots API controller for the OpenStack API."""
5455

@@ -59,6 +60,7 @@ def __init__(self):
5960
@wsgi.api_version("2.1", MAX_PROXY_API_SUPPORT_VERSION)
6061
@wsgi.expected_errors(404)
6162
@validation.query_schema(schema.show_query)
63+
@validation.response_body_schema(schema.show_response)
6264
def show(self, req, id):
6365
"""Return data about the given snapshot."""
6466
context = req.environ['nova.context']
@@ -76,6 +78,7 @@ def show(self, req, id):
7678
@wsgi.api_version("2.1", MAX_PROXY_API_SUPPORT_VERSION)
7779
@wsgi.response(202)
7880
@wsgi.expected_errors(404)
81+
@validation.response_body_schema(schema.delete_response)
7982
def delete(self, req, id):
8083
"""Delete a snapshot."""
8184
context = req.environ['nova.context']
@@ -91,6 +94,7 @@ def delete(self, req, id):
9194
@wsgi.api_version("2.1", MAX_PROXY_API_SUPPORT_VERSION)
9295
@wsgi.expected_errors(())
9396
@validation.query_schema(schema.index_query)
97+
@validation.response_body_schema(schema.index_response)
9498
def index(self, req):
9599
"""Returns a summary list of snapshots."""
96100
context = req.environ['nova.context']
@@ -102,6 +106,7 @@ def index(self, req):
102106
@wsgi.api_version("2.1", MAX_PROXY_API_SUPPORT_VERSION)
103107
@wsgi.expected_errors(())
104108
@validation.query_schema(schema.detail_query)
109+
@validation.response_body_schema(schema.detail_response)
105110
def detail(self, req):
106111
"""Returns a detailed list of snapshots."""
107112
context = req.environ['nova.context']
@@ -122,6 +127,7 @@ def _items(self, req, entity_maker):
122127
@wsgi.api_version("2.1", MAX_PROXY_API_SUPPORT_VERSION)
123128
@wsgi.expected_errors((400, 403))
124129
@validation.schema(schema.create)
130+
@validation.response_body_schema(schema.create_response)
125131
def create(self, req, body):
126132
"""Creates a new snapshot."""
127133
context = req.environ['nova.context']

0 commit comments

Comments
 (0)