|
19 | 19 | import webob
|
20 | 20 |
|
21 | 21 | from nova.api.openstack.placement import microversion
|
| 22 | +from nova.api.openstack.placement.schemas import inventory as schema |
22 | 23 | from nova.api.openstack.placement import util
|
23 | 24 | from nova.api.openstack.placement import wsgi_wrapper
|
24 | 25 | from nova import db
|
25 | 26 | from nova import exception
|
26 | 27 | from nova.i18n import _
|
27 | 28 | from nova.objects import resource_provider as rp_obj
|
28 | 29 |
|
29 |
| -RESOURCE_CLASS_IDENTIFIER = "^[A-Z0-9_]+$" |
30 |
| -BASE_INVENTORY_SCHEMA = { |
31 |
| - "type": "object", |
32 |
| - "properties": { |
33 |
| - "resource_provider_generation": { |
34 |
| - "type": "integer" |
35 |
| - }, |
36 |
| - "total": { |
37 |
| - "type": "integer", |
38 |
| - "maximum": db.MAX_INT, |
39 |
| - "minimum": 1, |
40 |
| - }, |
41 |
| - "reserved": { |
42 |
| - "type": "integer", |
43 |
| - "maximum": db.MAX_INT, |
44 |
| - "minimum": 0, |
45 |
| - }, |
46 |
| - "min_unit": { |
47 |
| - "type": "integer", |
48 |
| - "maximum": db.MAX_INT, |
49 |
| - "minimum": 1 |
50 |
| - }, |
51 |
| - "max_unit": { |
52 |
| - "type": "integer", |
53 |
| - "maximum": db.MAX_INT, |
54 |
| - "minimum": 1 |
55 |
| - }, |
56 |
| - "step_size": { |
57 |
| - "type": "integer", |
58 |
| - "maximum": db.MAX_INT, |
59 |
| - "minimum": 1 |
60 |
| - }, |
61 |
| - "allocation_ratio": { |
62 |
| - "type": "number", |
63 |
| - "maximum": db.SQL_SP_FLOAT_MAX |
64 |
| - }, |
65 |
| - }, |
66 |
| - "required": [ |
67 |
| - "total", |
68 |
| - "resource_provider_generation" |
69 |
| - ], |
70 |
| - "additionalProperties": False |
71 |
| -} |
72 |
| -POST_INVENTORY_SCHEMA = copy.deepcopy(BASE_INVENTORY_SCHEMA) |
73 |
| -POST_INVENTORY_SCHEMA['properties']['resource_class'] = { |
74 |
| - "type": "string", |
75 |
| - "pattern": RESOURCE_CLASS_IDENTIFIER, |
76 |
| -} |
77 |
| -POST_INVENTORY_SCHEMA['required'].append('resource_class') |
78 |
| -POST_INVENTORY_SCHEMA['required'].remove('resource_provider_generation') |
79 |
| -PUT_INVENTORY_RECORD_SCHEMA = copy.deepcopy(BASE_INVENTORY_SCHEMA) |
80 |
| -PUT_INVENTORY_RECORD_SCHEMA['required'].remove('resource_provider_generation') |
81 |
| -PUT_INVENTORY_SCHEMA = { |
82 |
| - "type": "object", |
83 |
| - "properties": { |
84 |
| - "resource_provider_generation": { |
85 |
| - "type": "integer" |
86 |
| - }, |
87 |
| - "inventories": { |
88 |
| - "type": "object", |
89 |
| - "patternProperties": { |
90 |
| - RESOURCE_CLASS_IDENTIFIER: PUT_INVENTORY_RECORD_SCHEMA, |
91 |
| - } |
92 |
| - } |
93 |
| - }, |
94 |
| - "required": [ |
95 |
| - "resource_provider_generation", |
96 |
| - "inventories" |
97 |
| - ], |
98 |
| - "additionalProperties": False |
99 |
| -} |
100 | 30 |
|
101 | 31 | # NOTE(cdent): We keep our own representation of inventory defaults
|
102 | 32 | # and output fields, separate from the versioned object to avoid
|
@@ -229,7 +159,7 @@ def create_inventory(req):
|
229 | 159 | uuid = util.wsgi_path_item(req.environ, 'uuid')
|
230 | 160 | resource_provider = rp_obj.ResourceProvider.get_by_uuid(
|
231 | 161 | context, uuid)
|
232 |
| - data = _extract_inventory(req.body, POST_INVENTORY_SCHEMA) |
| 162 | + data = _extract_inventory(req.body, schema.POST_INVENTORY_SCHEMA) |
233 | 163 | resource_class = data.pop('resource_class')
|
234 | 164 |
|
235 | 165 | inventory = _make_inventory_object(resource_provider,
|
@@ -361,7 +291,7 @@ def set_inventories(req):
|
361 | 291 | resource_provider = rp_obj.ResourceProvider.get_by_uuid(
|
362 | 292 | context, uuid)
|
363 | 293 |
|
364 |
| - data = _extract_inventories(req.body, PUT_INVENTORY_SCHEMA) |
| 294 | + data = _extract_inventories(req.body, schema.PUT_INVENTORY_SCHEMA) |
365 | 295 | if data['resource_provider_generation'] != resource_provider.generation:
|
366 | 296 | raise webob.exc.HTTPConflict(
|
367 | 297 | _('resource provider generation conflict'))
|
@@ -456,7 +386,7 @@ def update_inventory(req):
|
456 | 386 | resource_provider = rp_obj.ResourceProvider.get_by_uuid(
|
457 | 387 | context, uuid)
|
458 | 388 |
|
459 |
| - data = _extract_inventory(req.body, BASE_INVENTORY_SCHEMA) |
| 389 | + data = _extract_inventory(req.body, schema.BASE_INVENTORY_SCHEMA) |
460 | 390 | if data['resource_provider_generation'] != resource_provider.generation:
|
461 | 391 | raise webob.exc.HTTPConflict(
|
462 | 392 | _('resource provider generation conflict'))
|
|
0 commit comments