api: Add response body schemas for server external events API

We also fix some issues in the api-ref, since it'll be another while
before we can replace that.

Change-Id: If661e3af796475637c0e76b3dfbfd5b7a7f38c24
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
This commit is contained in:
Stephen Finucane
2024-11-13 18:03:48 +00:00
parent 1c03429337
commit 8ed52a058a
3 changed files with 100 additions and 20 deletions

View File

@@ -2089,11 +2089,11 @@ code:
description: | description: |
The HTTP response code for the event. The following codes are currently used: The HTTP response code for the event. The following codes are currently used:
* 200 - successfully submitted event * 200 - successfully submitted event
* 400 - the request is missing required parameter * 400 - the request is missing required parameter
* 404 - the instance specified by ``server_uuid`` was not found * 404 - the instance specified by ``server_uuid`` was not found
* 422 - no host was found for the server specified by ``server_uuid``, * 422 - no host was found for the server specified by ``server_uuid``,
so there is no route to this server. so there is no route to this server.
in: body in: body
required: true required: true
type: string type: string
@@ -2737,6 +2737,7 @@ event_name:
- ``volume-extended`` (since microversion ``2.51``) - ``volume-extended`` (since microversion ``2.51``)
- ``power-update`` (since microversion ``2.76``) - ``power-update`` (since microversion ``2.76``)
- ``accelerator-request-bound`` (since microversion ``2.82``) - ``accelerator-request-bound`` (since microversion ``2.82``)
- ``volume-reimaged`` (since microversion ``2.93``)
in: body in: body
required: true required: true

View File

@@ -19,31 +19,33 @@ create = {
'type': 'object', 'type': 'object',
'properties': { 'properties': {
'events': { 'events': {
'type': 'array', 'minItems': 1, 'type': 'array',
'minItems': 1,
'items': { 'items': {
'type': 'object', 'type': 'object',
'properties': { 'properties': {
'server_uuid': {
'type': 'string', 'format': 'uuid'
},
'name': { 'name': {
'type': 'string', 'type': 'string',
'enum': [ 'enum': [
'network-changed', 'network-changed',
'network-vif-plugged', 'network-vif-plugged',
'network-vif-unplugged', 'network-vif-unplugged',
'network-vif-deleted' 'network-vif-deleted',
], ],
}, },
'server_uuid': {
'type': 'string', 'format': 'uuid'
},
'status': { 'status': {
'type': 'string', 'type': 'string',
'enum': external_event_obj.EVENT_STATUSES, 'enum': external_event_obj.EVENT_STATUSES,
}, },
'tag': { 'tag': {
'type': 'string', 'maxLength': 255, 'type': 'string',
'maxLength': 255,
}, },
}, },
'required': ['server_uuid', 'name'], 'required': ['name', 'server_uuid'],
'additionalProperties': False, 'additionalProperties': False,
}, },
}, },
@@ -67,3 +69,74 @@ name['enum'].append('accelerator-request-bound')
create_v293 = copy.deepcopy(create_v282) create_v293 = copy.deepcopy(create_v282)
name = create_v293['properties']['events']['items']['properties']['name'] name = create_v293['properties']['events']['items']['properties']['name']
name['enum'].append('volume-reimaged') name['enum'].append('volume-reimaged')
create_response = {
'type': 'object',
'properties': {
'events': {
'type': 'array',
'items': {
'type': 'object',
'properties': {
'code': {
'type': 'integer',
'enum': [200, 400, 404, 422],
},
'name': {
'type': 'string',
'enum': [
'network-changed',
'network-vif-plugged',
'network-vif-unplugged',
'network-vif-deleted',
],
},
'server_uuid': {'type': 'string', 'format': 'uuid'},
'status': {
'type': 'string',
'enum': external_event_obj.EVENT_STATUSES,
},
'tag': {
'type': 'string',
'maxLength': 255,
},
},
'required': [
'code',
'name',
'server_uuid',
'status',
# tag is not required in responses, although omitting it
# from requests will result in a failed event response
],
'additionalProperties': False,
},
},
},
'required': ['events'],
'additionalProperties': False,
}
create_response_v251 = copy.deepcopy(create_response)
name = create_response_v251['properties']['events']['items']['properties'][
'name'
]
name['enum'].append('volume-extended')
create_response_v276 = copy.deepcopy(create_response_v251)
name = create_response_v276['properties']['events']['items']['properties'][
'name'
]
name['enum'].append('power-update')
create_response_v282 = copy.deepcopy(create_response_v276)
name = create_response_v282['properties']['events']['items']['properties'][
'name'
]
name['enum'].append('accelerator-request-bound')
create_response_v293 = copy.deepcopy(create_response_v282)
name = create_response_v293['properties']['events']['items']['properties'][
'name'
]
name['enum'].append('volume-reimaged')

View File

@@ -14,7 +14,7 @@
from oslo_log import log as logging from oslo_log import log as logging
from nova.api.openstack.compute.schemas import server_external_events from nova.api.openstack.compute.schemas import server_external_events as schema
from nova.api.openstack import wsgi from nova.api.openstack import wsgi
from nova.api import validation from nova.api import validation
from nova.compute import api as compute from nova.compute import api as compute
@@ -30,6 +30,7 @@ TAG_REQUIRED = ('volume-extended', 'power-update',
'accelerator-request-bound') 'accelerator-request-bound')
@validation.validated
class ServerExternalEventsController(wsgi.Controller): class ServerExternalEventsController(wsgi.Controller):
def __init__(self): def __init__(self):
@@ -66,11 +67,16 @@ class ServerExternalEventsController(wsgi.Controller):
@wsgi.expected_errors(403) @wsgi.expected_errors(403)
@wsgi.response(200) @wsgi.response(200)
@validation.schema(server_external_events.create, '2.0', '2.50') @validation.schema(schema.create, '2.0', '2.50')
@validation.schema(server_external_events.create_v251, '2.51', '2.75') @validation.schema(schema.create_v251, '2.51', '2.75')
@validation.schema(server_external_events.create_v276, '2.76', '2.81') @validation.schema(schema.create_v276, '2.76', '2.81')
@validation.schema(server_external_events.create_v282, '2.82', '2.92') @validation.schema(schema.create_v282, '2.82', '2.92')
@validation.schema(server_external_events.create_v293, '2.93') @validation.schema(schema.create_v293, '2.93')
@validation.response_body_schema(schema.create_response, '2.0', '2.50')
@validation.response_body_schema(schema.create_response_v251, '2.51', '2.75') # noqa: E501
@validation.response_body_schema(schema.create_response_v276, '2.76', '2.81') # noqa: E501
@validation.response_body_schema(schema.create_response_v282, '2.82', '2.92') # noqa: E501
@validation.response_body_schema(schema.create_response_v293, '2.93')
def create(self, req, body): def create(self, req, body):
"""Creates a new instance event.""" """Creates a new instance event."""
context = req.environ['nova.context'] context = req.environ['nova.context']