Merge "[placement] Separate API schemas (usage)"

This commit is contained in:
Zuul 2017-12-15 18:41:13 +00:00 committed by Gerrit Code Review
commit 42afe5577b
3 changed files with 35 additions and 25 deletions

View File

@ -17,6 +17,7 @@ from oslo_utils import timeutils
import webob
from nova.api.openstack.placement import microversion
from nova.api.openstack.placement.schemas import usage as schema
from nova.api.openstack.placement import util
from nova.api.openstack.placement import wsgi_wrapper
from nova import exception
@ -24,28 +25,6 @@ from nova.i18n import _
from nova.objects import resource_provider as rp_obj
# Represents the allowed query string parameters to GET /usages
GET_USAGES_SCHEMA_1_9 = {
"type": "object",
"properties": {
"project_id": {
"type": "string",
"minLength": 1,
"maxLength": 255,
},
"user_id": {
"type": "string",
"minLength": 1,
"maxLength": 255,
},
},
"required": [
"project_id"
],
"additionalProperties": False,
}
def _serialize_usages(resource_provider, usage):
usage_dict = {resource.resource_class: resource.usage
for resource in usage}
@ -111,9 +90,7 @@ def get_total_usages(req):
context = req.environ['placement.context']
want_version = req.environ[microversion.MICROVERSION_ENVIRON]
schema = GET_USAGES_SCHEMA_1_9
util.validate_query_params(req, schema)
util.validate_query_params(req, schema.GET_USAGES_SCHEMA_1_9)
project_id = req.GET.get('project_id')
user_id = req.GET.get('user_id')

View File

@ -0,0 +1,33 @@
# 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 usage information."""
# Represents the allowed query string parameters to GET /usages
GET_USAGES_SCHEMA_1_9 = {
"type": "object",
"properties": {
"project_id": {
"type": "string",
"minLength": 1,
"maxLength": 255,
},
"user_id": {
"type": "string",
"minLength": 1,
"maxLength": 255,
},
},
"required": [
"project_id"
],
"additionalProperties": False,
}