Skip to content

Commit 0060c0b

Browse files
[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
1 parent 6a09908 commit 0060c0b

File tree

3 files changed

+35
-25
lines changed

3 files changed

+35
-25
lines changed

nova/api/openstack/placement/handlers/usage.py

+2-25
Original file line numberDiff line numberDiff line change
@@ -17,35 +17,14 @@
1717
import webob
1818

1919
from nova.api.openstack.placement import microversion
20+
from nova.api.openstack.placement.schemas import usage as schema
2021
from nova.api.openstack.placement import util
2122
from nova.api.openstack.placement import wsgi_wrapper
2223
from nova import exception
2324
from nova.i18n import _
2425
from nova.objects import resource_provider as rp_obj
2526

2627

27-
# Represents the allowed query string parameters to GET /usages
28-
GET_USAGES_SCHEMA_1_9 = {
29-
"type": "object",
30-
"properties": {
31-
"project_id": {
32-
"type": "string",
33-
"minLength": 1,
34-
"maxLength": 255,
35-
},
36-
"user_id": {
37-
"type": "string",
38-
"minLength": 1,
39-
"maxLength": 255,
40-
},
41-
},
42-
"required": [
43-
"project_id"
44-
],
45-
"additionalProperties": False,
46-
}
47-
48-
4928
def _serialize_usages(resource_provider, usage):
5029
usage_dict = {resource.resource_class: resource.usage
5130
for resource in usage}
@@ -111,9 +90,7 @@ def get_total_usages(req):
11190
context = req.environ['placement.context']
11291
want_version = req.environ[microversion.MICROVERSION_ENVIRON]
11392

114-
schema = GET_USAGES_SCHEMA_1_9
115-
116-
util.validate_query_params(req, schema)
93+
util.validate_query_params(req, schema.GET_USAGES_SCHEMA_1_9)
11794

11895
project_id = req.GET.get('project_id')
11996
user_id = req.GET.get('user_id')

nova/api/openstack/placement/schemas/__init__.py

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
2+
# not use this file except in compliance with the License. You may obtain
3+
# a copy of the License at
4+
#
5+
# http://www.apache.org/licenses/LICENSE-2.0
6+
#
7+
# Unless required by applicable law or agreed to in writing, software
8+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10+
# License for the specific language governing permissions and limitations
11+
# under the License.
12+
"""Placement API schemas for usage information."""
13+
14+
# Represents the allowed query string parameters to GET /usages
15+
GET_USAGES_SCHEMA_1_9 = {
16+
"type": "object",
17+
"properties": {
18+
"project_id": {
19+
"type": "string",
20+
"minLength": 1,
21+
"maxLength": 255,
22+
},
23+
"user_id": {
24+
"type": "string",
25+
"minLength": 1,
26+
"maxLength": 255,
27+
},
28+
},
29+
"required": [
30+
"project_id"
31+
],
32+
"additionalProperties": False,
33+
}

0 commit comments

Comments
 (0)