[placement] Separate API schemas (resource_class)

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/resource_class.py.

Subsequent patches will move schemas of other handlers.

Change-Id: I61bfc96953d1158d3204d3f578a5255c18af2d6e
This commit is contained in:
Takashi NATSUME 2017-11-16 23:51:39 +09:00
parent eabd1c11fd
commit 5ca83f11a0
2 changed files with 35 additions and 22 deletions

View File

@ -11,14 +11,13 @@
# under the License.
"""Placement API handlers for resource classes."""
import copy
from oslo_serialization import jsonutils
from oslo_utils import encodeutils
from oslo_utils import timeutils
import webob
from nova.api.openstack.placement import microversion
from nova.api.openstack.placement.schemas import resource_class as schema
from nova.api.openstack.placement import util
from nova.api.openstack.placement import wsgi_wrapper
from nova import exception
@ -26,23 +25,6 @@ from nova.i18n import _
from nova.objects import resource_provider as rp_obj
POST_RC_SCHEMA_V1_2 = {
"type": "object",
"properties": {
"name": {
"type": "string",
"pattern": "^CUSTOM\_[A-Z0-9_]+$",
"maxLength": 255,
},
},
"required": [
"name"
],
"additionalProperties": False,
}
PUT_RC_SCHEMA_V1_2 = copy.deepcopy(POST_RC_SCHEMA_V1_2)
def _serialize_links(environ, rc):
url = util.resource_class_url(environ, rc)
links = [{'rel': 'self', 'href': url}]
@ -80,7 +62,7 @@ def create_resource_class(req):
header pointing to the newly created resource class.
"""
context = req.environ['placement.context']
data = util.extract_json(req.body, POST_RC_SCHEMA_V1_2)
data = util.extract_json(req.body, schema.POST_RC_SCHEMA_V1_2)
try:
rc = rp_obj.ResourceClass(context, name=data['name'])
@ -191,7 +173,7 @@ def update_resource_class(req):
name = util.wsgi_path_item(req.environ, 'name')
context = req.environ['placement.context']
data = util.extract_json(req.body, PUT_RC_SCHEMA_V1_2)
data = util.extract_json(req.body, schema.PUT_RC_SCHEMA_V1_2)
# The containing application will catch a not found here.
rc = rp_obj.ResourceClass.get_by_name(context, name)
@ -230,7 +212,7 @@ def update_resource_class(req):
context = req.environ['placement.context']
# Use JSON validation to validation resource class name.
util.extract_json('{"name": "%s"}' % name, PUT_RC_SCHEMA_V1_2)
util.extract_json('{"name": "%s"}' % name, schema.PUT_RC_SCHEMA_V1_2)
status = 204
try:

View File

@ -0,0 +1,31 @@
# 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 resource classes."""
import copy
POST_RC_SCHEMA_V1_2 = {
"type": "object",
"properties": {
"name": {
"type": "string",
"pattern": "^CUSTOM\_[A-Z0-9_]+$",
"maxLength": 255,
},
},
"required": [
"name"
],
"additionalProperties": False,
}
PUT_RC_SCHEMA_V1_2 = copy.deepcopy(POST_RC_SCHEMA_V1_2)