From 5f3e749d57df5376f3c609f7f5c356e9cb6bc0dc Mon Sep 17 00:00:00 2001 From: Takashi NATSUME Date: Mon, 18 Dec 2017 14:50:13 +0900 Subject: [PATCH] [placement] Separate API schemas (allocation_candidate) In compute APIs, they have their schemas in the independent directory (nova/api/openstack/compute/schemas). Placement APIs should be like that as well. This patch separates API schemas to an independent directory (nova/api/openstack/placement/schemas) from nova/api/openstack/placement/handlers/allocation_candidate.py. Change-Id: I56a99e40a156e54923ea40fc71b18194e3ee8f7c --- .../handlers/allocation_candidate.py | 19 ++----------- .../placement/schemas/allocation_candidate.py | 27 +++++++++++++++++++ 2 files changed, 29 insertions(+), 17 deletions(-) create mode 100644 nova/api/openstack/placement/schemas/allocation_candidate.py diff --git a/nova/api/openstack/placement/handlers/allocation_candidate.py b/nova/api/openstack/placement/handlers/allocation_candidate.py index 56635f54c..4ed1fec58 100644 --- a/nova/api/openstack/placement/handlers/allocation_candidate.py +++ b/nova/api/openstack/placement/handlers/allocation_candidate.py @@ -21,6 +21,7 @@ from oslo_utils import timeutils import webob from nova.api.openstack.placement import microversion +from nova.api.openstack.placement.schemas import allocation_candidate as schema from nova.api.openstack.placement import util from nova.api.openstack.placement import wsgi_wrapper from nova import exception @@ -30,21 +31,6 @@ from nova.objects import resource_provider as rp_obj LOG = logging.getLogger(__name__) -# Represents the allowed query string parameters to the GET -# /allocation_candidates API call -_GET_SCHEMA_1_10 = { - "type": "object", - "properties": { - "resources": { - "type": "string" - }, - }, - "required": [ - "resources", - ], - "additionalProperties": False, -} - def _transform_allocation_requests_dict(alloc_reqs): """Turn supplied list of AllocationRequest objects into a list of @@ -208,8 +194,7 @@ def list_allocation_candidates(req): """ context = req.environ['placement.context'] want_version = req.environ[microversion.MICROVERSION_ENVIRON] - schema = _GET_SCHEMA_1_10 - util.validate_query_params(req, schema) + util.validate_query_params(req, schema.GET_SCHEMA_1_10) requests = util.parse_qs_request_groups(req.GET) diff --git a/nova/api/openstack/placement/schemas/allocation_candidate.py b/nova/api/openstack/placement/schemas/allocation_candidate.py new file mode 100644 index 000000000..0d7766cc7 --- /dev/null +++ b/nova/api/openstack/placement/schemas/allocation_candidate.py @@ -0,0 +1,27 @@ +# 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. +"""Placement API schemas for getting allocation candidates.""" + +# Represents the allowed query string parameters to the GET +# /allocation_candidates API call +GET_SCHEMA_1_10 = { + "type": "object", + "properties": { + "resources": { + "type": "string" + }, + }, + "required": [ + "resources", + ], + "additionalProperties": False, +}