[placement] Regex consts for placement schema
Factor out some regexes used across multiple schemata into a new nova.api.openstack.placement.schemas.common module. The UUID part of this is in preparation for fixing the related bug. Change-Id: If62bfeeb32d0ad77dd1205116ee4e5e844bb07e4 Related-Bug: #1758057
This commit is contained in:
parent
a32d765f98
commit
fa66d9a730
@ -13,6 +13,8 @@
|
||||
|
||||
import copy
|
||||
|
||||
from nova.api.openstack.placement.schemas import common
|
||||
|
||||
|
||||
ALLOCATION_SCHEMA = {
|
||||
"type": "object",
|
||||
@ -38,7 +40,7 @@ ALLOCATION_SCHEMA = {
|
||||
"type": "object",
|
||||
"minProperties": 1,
|
||||
"patternProperties": {
|
||||
"^[0-9A-Z_]+$": {
|
||||
common.RC_PATTERN: {
|
||||
"type": "integer",
|
||||
"minimum": 1,
|
||||
}
|
||||
@ -78,7 +80,7 @@ ALLOCATION_SCHEMA_V1_12 = {
|
||||
"minProperties": 1,
|
||||
# resource provider uuid
|
||||
"patternProperties": {
|
||||
"^[0-9a-fA-F-]{36}$": {
|
||||
common.UUID_PATTERN: {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
# generation is optional
|
||||
@ -90,7 +92,7 @@ ALLOCATION_SCHEMA_V1_12 = {
|
||||
"minProperties": 1,
|
||||
# resource class
|
||||
"patternProperties": {
|
||||
"^[0-9A-Z_]+$": {
|
||||
common.RC_PATTERN: {
|
||||
"type": "integer",
|
||||
"minimum": 1,
|
||||
}
|
||||
@ -137,7 +139,7 @@ POST_ALLOCATIONS_V1_13 = {
|
||||
"minProperties": 1,
|
||||
"additionalProperties": False,
|
||||
"patternProperties": {
|
||||
"^[0-9a-fA-F-]{36}$": DELETABLE_ALLOCATIONS
|
||||
common.UUID_PATTERN: DELETABLE_ALLOCATIONS
|
||||
}
|
||||
}
|
||||
|
||||
@ -163,5 +165,5 @@ alloc_props['consumer_generation'] = {
|
||||
REQUIRED_GENERATION_ALLOCS_POST['required'].append("consumer_generation")
|
||||
POST_ALLOCATIONS_V1_28 = copy.deepcopy(POST_ALLOCATIONS_V1_13)
|
||||
POST_ALLOCATIONS_V1_28["patternProperties"] = {
|
||||
"^[0-9a-fA-F-]{36}$": REQUIRED_GENERATION_ALLOCS_POST
|
||||
common.UUID_PATTERN: REQUIRED_GENERATION_ALLOCS_POST
|
||||
}
|
||||
|
22
nova/api/openstack/placement/schemas/common.py
Normal file
22
nova/api/openstack/placement/schemas/common.py
Normal file
@ -0,0 +1,22 @@
|
||||
# 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.
|
||||
_UUID_CHAR = "[0-9a-fA-F-]"
|
||||
# TODO(efried): Use this stricter pattern, and replace string/uuid with it:
|
||||
# UUID_PATTERN = "^%s{8}-%s{4}-%s{4}-%s{4}-%s{12}$" % ((_UUID_CHAR,) * 5)
|
||||
UUID_PATTERN = "^%s{36}$" % _UUID_CHAR
|
||||
|
||||
_RC_TRAIT_CHAR = "[A-Z0-9_]"
|
||||
_RC_TRAIT_PATTERN = "^%s+$" % _RC_TRAIT_CHAR
|
||||
RC_PATTERN = _RC_TRAIT_PATTERN
|
||||
_CUSTOM_RC_TRAIT_PATTERN = "^CUSTOM_%s+$" % _RC_TRAIT_CHAR
|
||||
CUSTOM_RC_PATTERN = _CUSTOM_RC_TRAIT_PATTERN
|
||||
CUSTOM_TRAIT_PATTERN = _CUSTOM_RC_TRAIT_PATTERN
|
@ -13,10 +13,10 @@
|
||||
|
||||
import copy
|
||||
|
||||
from nova.api.openstack.placement.schemas import common
|
||||
from nova.db import constants as db_const
|
||||
|
||||
|
||||
RESOURCE_CLASS_IDENTIFIER = "^[A-Z0-9_]+$"
|
||||
BASE_INVENTORY_SCHEMA = {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
@ -64,7 +64,7 @@ BASE_INVENTORY_SCHEMA = {
|
||||
POST_INVENTORY_SCHEMA = copy.deepcopy(BASE_INVENTORY_SCHEMA)
|
||||
POST_INVENTORY_SCHEMA['properties']['resource_class'] = {
|
||||
"type": "string",
|
||||
"pattern": RESOURCE_CLASS_IDENTIFIER,
|
||||
"pattern": common.RC_PATTERN,
|
||||
}
|
||||
POST_INVENTORY_SCHEMA['required'].append('resource_class')
|
||||
POST_INVENTORY_SCHEMA['required'].remove('resource_provider_generation')
|
||||
@ -81,7 +81,7 @@ PUT_INVENTORY_SCHEMA = {
|
||||
"inventories": {
|
||||
"type": "object",
|
||||
"patternProperties": {
|
||||
RESOURCE_CLASS_IDENTIFIER: PUT_INVENTORY_RECORD_SCHEMA,
|
||||
common.RC_PATTERN: PUT_INVENTORY_RECORD_SCHEMA,
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -13,13 +13,15 @@
|
||||
|
||||
import copy
|
||||
|
||||
from nova.api.openstack.placement.schemas import common
|
||||
|
||||
|
||||
POST_RC_SCHEMA_V1_2 = {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string",
|
||||
"pattern": "^CUSTOM\_[A-Z0-9_]+$",
|
||||
"pattern": common.CUSTOM_RC_PATTERN,
|
||||
"maxLength": 255,
|
||||
},
|
||||
},
|
||||
|
@ -13,13 +13,16 @@
|
||||
|
||||
import copy
|
||||
|
||||
from nova.api.openstack.placement.schemas import common
|
||||
|
||||
|
||||
TRAIT = {
|
||||
"type": "string",
|
||||
'minLength': 1, 'maxLength': 255,
|
||||
}
|
||||
|
||||
CUSTOM_TRAIT = copy.deepcopy(TRAIT)
|
||||
CUSTOM_TRAIT.update({"pattern": "^CUSTOM_[A-Z0-9_]+$"})
|
||||
CUSTOM_TRAIT.update({"pattern": common.CUSTOM_TRAIT_PATTERN})
|
||||
|
||||
PUT_TRAITS_SCHEMA = {
|
||||
"type": "object",
|
||||
|
Loading…
x
Reference in New Issue
Block a user