There are some regexes used in the json-schema for complex string validation. When the validation failed, json-schema lib didn't generate a useful error info for the user, it shows the regex to the user. But regex is really unreadable for normal user. This patch override the default FormatChecker to support passed in custom error message. This required using custom format checker instead of using 'pattern'. For aggregates API, it enabled 'null' in the name input. As the 'format' keyword works for all allowed types and name format check will only validate string type, so this patch change the schema to use 'oneOf' keyword, then the 'format' will only against on string type. Change-Id: Ic0e608b8a18b635bfcd936f57f14c9f54e1ef8b4 Partial-Bug: #1541691
132 lines
3.6 KiB
Python
132 lines
3.6 KiB
Python
# Copyright 2014 NEC Corporation. All rights reserved.
|
|
#
|
|
# 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.
|
|
|
|
import copy
|
|
|
|
from nova.api.validation import parameter_types
|
|
|
|
availability_zone = {'oneOf': [parameter_types.name, {'type': 'null'}]}
|
|
availability_zone_with_leading_trailing_spaces = {
|
|
'oneOf': [parameter_types.name_with_leading_trailing_spaces,
|
|
{'type': 'null'}]
|
|
}
|
|
|
|
|
|
create = {
|
|
'type': 'object',
|
|
'properties': {
|
|
'type': 'object',
|
|
'aggregate': {
|
|
'type': 'object',
|
|
'properties': {
|
|
'name': parameter_types.name,
|
|
'availability_zone': availability_zone,
|
|
},
|
|
'required': ['name'],
|
|
'additionalProperties': False,
|
|
},
|
|
},
|
|
'required': ['aggregate'],
|
|
'additionalProperties': False,
|
|
}
|
|
|
|
|
|
create_v20 = copy.deepcopy(create)
|
|
create_v20['properties']['aggregate']['properties']['name'] = (parameter_types.
|
|
name_with_leading_trailing_spaces)
|
|
create_v20['properties']['aggregate']['properties']['availability_zone'] = (
|
|
availability_zone_with_leading_trailing_spaces)
|
|
|
|
|
|
update = {
|
|
'type': 'object',
|
|
'properties': {
|
|
'type': 'object',
|
|
'aggregate': {
|
|
'type': 'object',
|
|
'properties': {
|
|
'name': parameter_types.name_with_leading_trailing_spaces,
|
|
'availability_zone': availability_zone
|
|
},
|
|
'additionalProperties': False,
|
|
'anyOf': [
|
|
{'required': ['name']},
|
|
{'required': ['availability_zone']}
|
|
]
|
|
},
|
|
},
|
|
'required': ['aggregate'],
|
|
'additionalProperties': False,
|
|
}
|
|
|
|
|
|
update_v20 = copy.deepcopy(update)
|
|
update_v20['properties']['aggregate']['properties']['name'] = (parameter_types.
|
|
name_with_leading_trailing_spaces)
|
|
update_v20['properties']['aggregate']['properties']['availability_zone'] = (
|
|
availability_zone_with_leading_trailing_spaces)
|
|
|
|
|
|
add_host = {
|
|
'type': 'object',
|
|
'properties': {
|
|
'type': 'object',
|
|
'add_host': {
|
|
'type': 'object',
|
|
'properties': {
|
|
'host': parameter_types.hostname,
|
|
},
|
|
'required': ['host'],
|
|
'additionalProperties': False,
|
|
},
|
|
},
|
|
'required': ['add_host'],
|
|
'additionalProperties': False,
|
|
}
|
|
|
|
remove_host = {
|
|
'type': 'object',
|
|
'properties': {
|
|
'type': 'object',
|
|
'remove_host': {
|
|
'type': 'object',
|
|
'properties': {
|
|
'host': parameter_types.hostname,
|
|
},
|
|
'required': ['host'],
|
|
'additionalProperties': False,
|
|
},
|
|
},
|
|
'required': ['remove_host'],
|
|
'additionalProperties': False,
|
|
}
|
|
|
|
|
|
set_metadata = {
|
|
'type': 'object',
|
|
'properties': {
|
|
'type': 'object',
|
|
'set_metadata': {
|
|
'type': 'object',
|
|
'properties': {
|
|
'metadata': parameter_types.metadata_with_null
|
|
},
|
|
'required': ['metadata'],
|
|
'additionalProperties': False,
|
|
},
|
|
},
|
|
'required': ['set_metadata'],
|
|
'additionalProperties': False,
|
|
}
|