[placement] Separate API schemas (usage)
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/usage.py. Subsequent patches will move schemas of other handlers. Change-Id: I38fc7e848fb3f95d79482e5903679e585e3675cc
This commit is contained in:
parent
6a09908757
commit
0060c0bd8d
@ -17,6 +17,7 @@ from oslo_utils import timeutils
|
|||||||
import webob
|
import webob
|
||||||
|
|
||||||
from nova.api.openstack.placement import microversion
|
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 util
|
||||||
from nova.api.openstack.placement import wsgi_wrapper
|
from nova.api.openstack.placement import wsgi_wrapper
|
||||||
from nova import exception
|
from nova import exception
|
||||||
@ -24,28 +25,6 @@ from nova.i18n import _
|
|||||||
from nova.objects import resource_provider as rp_obj
|
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):
|
def _serialize_usages(resource_provider, usage):
|
||||||
usage_dict = {resource.resource_class: resource.usage
|
usage_dict = {resource.resource_class: resource.usage
|
||||||
for resource in usage}
|
for resource in usage}
|
||||||
@ -111,9 +90,7 @@ def get_total_usages(req):
|
|||||||
context = req.environ['placement.context']
|
context = req.environ['placement.context']
|
||||||
want_version = req.environ[microversion.MICROVERSION_ENVIRON]
|
want_version = req.environ[microversion.MICROVERSION_ENVIRON]
|
||||||
|
|
||||||
schema = GET_USAGES_SCHEMA_1_9
|
util.validate_query_params(req, schema.GET_USAGES_SCHEMA_1_9)
|
||||||
|
|
||||||
util.validate_query_params(req, schema)
|
|
||||||
|
|
||||||
project_id = req.GET.get('project_id')
|
project_id = req.GET.get('project_id')
|
||||||
user_id = req.GET.get('user_id')
|
user_id = req.GET.get('user_id')
|
||||||
|
0
nova/api/openstack/placement/schemas/__init__.py
Normal file
0
nova/api/openstack/placement/schemas/__init__.py
Normal file
33
nova/api/openstack/placement/schemas/usage.py
Normal file
33
nova/api/openstack/placement/schemas/usage.py
Normal 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,
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user