Merge "api: Add response body schemas for servers APIs (2/6)"

This commit is contained in:
Zuul
2026-02-24 23:45:11 +00:00
committed by Gerrit Code Review
4 changed files with 78 additions and 8 deletions
-1
View File
@@ -38,7 +38,6 @@ CONF = nova.conf.CONF
LOG = logging.getLogger(__name__)
QUOTAS = quota.QUOTAS
POWER_ON = 'POWER_ON'
POWER_OFF = 'POWER_OFF'
+68 -2
View File
@@ -731,6 +731,72 @@ show_query = {
'additionalProperties': True,
}
_server_status = {
'type': 'string',
'enum': [
'ACTIVE',
'BUILD',
'DELETED',
'ERROR',
'HARD_REBOOT',
'MIGRATING',
'PASSWORD',
'PAUSED',
'REBOOT',
'REBUILD',
'RESCUE',
'RESIZE',
'REVERT_RESIZE',
'SHELVED',
'SHELVED_OFFLOADED',
'SHUTOFF',
'SOFT_DELETED',
'SUSPENDED',
'VERIFY_RESIZE',
],
}
index_response = {
'type': 'object',
'properties': {
'servers': {
'type': 'array',
'items': {
'type': 'object',
'properties': {
'id': {'type': 'string', 'format': 'uuid'},
'links': response_types.links,
'name': {'type': 'string'},
},
'required': ['id', 'links', 'name'],
'additionalProperties': False,
},
},
'servers_links': response_types.collection_links,
},
'required': ['servers'],
'additionalProperties': False,
}
# v2.69 add an alternative representation for instances from down cells. name
# is gone, status is in.
index_response_v269 = copy.deepcopy(index_response)
index_response_v269['properties']['servers']['items'] = {
'oneOf': [
index_response_v269['properties']['servers']['items'],
{
'type': 'object',
'properties': {
'id': {'type': 'string', 'format': 'uuid'},
'links': response_types.links,
'status': {'type': 'string', 'const': 'UNKNOWN'},
},
'required': ['id', 'links', 'status'],
'additionalProperties': False,
},
],
}
_server_cell_down_response = {
'type': 'object',
'properties': {
@@ -929,7 +995,7 @@ _server_response = {
'additionalProperties': False,
},
},
'status': {'type': 'string'},
'status': _server_status,
'tenant_id': parameter_types.project_id,
'updated': {'type': 'string', 'format': 'date-time'},
'user_id': parameter_types.user_id,
@@ -1296,7 +1362,7 @@ rebuild_response = {
},
'name': {'type': ['string', 'null']},
'progress': {'type': ['null', 'number']},
'status': {'type': 'string'},
'status': _server_status,
'tenant_id': parameter_types.project_id,
'updated': {'type': 'string', 'format': 'date-time'},
'user_id': parameter_types.user_id,
+6 -4
View File
@@ -113,11 +113,13 @@ class ServersController(wsgi.Controller):
self.compute_api = compute.API()
@wsgi.expected_errors((400, 403))
@validation.query_schema(schema.query_params_v275, '2.75')
@validation.query_schema(schema.query_params_v273, '2.73', '2.74')
@validation.query_schema(schema.query_params_v266, '2.66', '2.72')
@validation.query_schema(schema.query_params_v226, '2.26', '2.65')
@validation.query_schema(schema.query_params_v21, '2.1', '2.25')
@validation.query_schema(schema.query_params_v226, '2.26', '2.65')
@validation.query_schema(schema.query_params_v266, '2.66', '2.72')
@validation.query_schema(schema.query_params_v273, '2.73', '2.74')
@validation.query_schema(schema.query_params_v275, '2.75')
@validation.response_body_schema(schema.index_response, '2.1', '2.68')
@validation.response_body_schema(schema.index_response_v269, '2.69')
def index(self, req):
"""Returns a list of server names and ids for a given user."""
context = req.environ['nova.context']
@@ -454,7 +454,10 @@ class ServersControllerTest(_ServersControllerTest):
ctxt = context.RequestContext('fake', fakes.FAKE_PROJECT_ID)
return fake_instance.fake_instance_obj(
ctxt, expected_attrs=expected_attrs,
project_id=self.request.environ['nova.context'].project_id)
project_id=self.request.environ['nova.context'].project_id,
task_state=None,
vm_state=vm_states.ACTIVE,
)
self.mock_get.side_effect = fake_get
self.controller.show(self.request, FAKE_UUID)