api: Add response body schemas for server IPs APIs

We also resolve a small mishap that has led to some unused schemas.

Change-Id: Iad8ab646f5c14ec1396fd48616e09d4271ccb304
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
This commit is contained in:
Stephen Finucane
2024-11-05 11:25:34 +00:00
parent c918fcc587
commit 2b3eb6b015
5 changed files with 72 additions and 35 deletions

View File

@@ -16,8 +16,8 @@
from webob import exc
from nova.api.openstack import common
from nova.api.openstack.compute.schemas import addresses as schema
from nova.api.openstack.compute.views import addresses as views_addresses
from nova.api.openstack.compute.schemas import ips as schema
from nova.api.openstack.compute.views import ips as views
from nova.api.openstack import wsgi
from nova.api import validation
from nova.compute import api as compute
@@ -25,9 +25,10 @@ from nova.i18n import _
from nova.policies import ips as ips_policies
@validation.validated
class IPsController(wsgi.Controller):
"""The servers addresses API controller for the OpenStack API."""
_view_builder_class = views_addresses.ViewBuilder
_view_builder_class = views.ViewBuilder
def __init__(self):
super(IPsController, self).__init__()
@@ -35,6 +36,7 @@ class IPsController(wsgi.Controller):
@wsgi.expected_errors(404)
@validation.query_schema(schema.index_query)
@validation.response_body_schema(schema.index_response)
def index(self, req, server_id):
context = req.environ["nova.context"]
instance = common.get_instance(self._compute_api, context, server_id)
@@ -45,6 +47,7 @@ class IPsController(wsgi.Controller):
@wsgi.expected_errors(404)
@validation.query_schema(schema.show_query)
@validation.response_body_schema(schema.show_response)
def show(self, req, server_id, id):
context = req.environ["nova.context"]
instance = common.get_instance(self._compute_api, context, server_id)

View File

@@ -1,25 +0,0 @@
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
# TODO(stephenfin): Remove additionalProperties in a future API version
index_query = {
'type': 'object',
'properties': {},
'additionalProperties': True,
}
# TODO(stephenfin): Remove additionalProperties in a future API version
show_query = {
'type': 'object',
'properties': {},
'additionalProperties': True,
}

View File

@@ -10,8 +10,67 @@
# License for the specific language governing permissions and limitations
# under the License.
# NOTE(stephenfin): These schemas are intentionally empty since these APIs have
# been removed
import copy
index_query = {}
show_query = {}
# TODO(stephenfin): Remove additionalProperties in a future API version
index_query = {
'type': 'object',
'properties': {},
'additionalProperties': True,
}
# TODO(stephenfin): Remove additionalProperties in a future API version
show_query = {
'type': 'object',
'properties': {},
'additionalProperties': True,
}
_ip_address = {
'type': 'object',
'properties': {
'addr': {
'type': 'string',
'oneOf': [
{'format': 'ipv4'},
{'format': 'ipv6'},
],
},
'version': {
'enum': [4, 6],
},
},
'required': ['addr', 'version'],
'additionalProperties': False,
}
index_response = {
'type': 'object',
'properties': {
'addresses': {
'type': 'object',
'patternProperties': {
# TODO(stephenfin): Surely there are some limitations on
# network names?
'^.+$': {
'type': 'array',
'items': copy.deepcopy(_ip_address),
},
},
},
},
'required': ['addresses'],
'additionalProperties': False,
}
show_response = {
'type': 'object',
'patternProperties': {
# TODO(stephenfin): Surely there are some limitations on
# network names?
'^.+$': {
'type': 'array',
'items': copy.deepcopy(_ip_address),
},
},
}

View File

@@ -19,9 +19,9 @@ from oslo_serialization import jsonutils
from nova.api.openstack import api_version_request
from nova.api.openstack import common
from nova.api.openstack.compute.views import addresses as views_addresses
from nova.api.openstack.compute.views import flavors as views_flavors
from nova.api.openstack.compute.views import images as views_images
from nova.api.openstack.compute.views import ips as views_ips
from nova import availability_zones as avail_zone
from nova.compute import api as compute
from nova.compute import vm_states
@@ -69,8 +69,8 @@ class ViewBuilder(common.ViewBuilder):
def __init__(self):
"""Initialize view builder."""
super(ViewBuilder, self).__init__()
self._address_builder = views_addresses.ViewBuilder()
self._image_builder = views_images.ViewBuilder()
self._ips_builder = views_ips.ViewBuilder()
self._flavor_builder = views_flavors.ViewBuilder()
self.compute_api = compute.API()
@@ -614,7 +614,7 @@ class ViewBuilder(common.ViewBuilder):
context = request.environ["nova.context"]
networks = common.get_networks_for_instance(context, instance)
return self._address_builder.index(
return self._ips_builder.index(
request, networks, extend_address,
)["addresses"]