Merge "Add jsonschema validation for karbor copies API"
This commit is contained in:
commit
3248b59e16
|
@ -0,0 +1,37 @@
|
|||
# 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.
|
||||
|
||||
"""
|
||||
Schema for Karbor V1 Copies API.
|
||||
|
||||
"""
|
||||
|
||||
from karbor.api.validation import parameter_types
|
||||
|
||||
|
||||
create = {
|
||||
'type': 'object',
|
||||
'properties': {
|
||||
'type': 'object',
|
||||
'copy': {
|
||||
'type': 'object',
|
||||
'properties': {
|
||||
'plan_id': parameter_types.uuid,
|
||||
'parameters': parameter_types.parameters,
|
||||
},
|
||||
'required': ['plan_id'],
|
||||
'additionalProperties': False,
|
||||
},
|
||||
},
|
||||
'required': ['copy'],
|
||||
'additionalProperties': False,
|
||||
}
|
|
@ -20,6 +20,8 @@ from webob import exc
|
|||
|
||||
from karbor.api import common
|
||||
from karbor.api.openstack import wsgi
|
||||
from karbor.api.schemas import copies as copy_schema
|
||||
from karbor.api import validation
|
||||
from karbor import exception
|
||||
from karbor.i18n import _
|
||||
|
||||
|
@ -58,10 +60,9 @@ class CopiesController(wsgi.Controller):
|
|||
self.protection_api = protection_api.API()
|
||||
super(CopiesController, self).__init__()
|
||||
|
||||
@validation.schema(copy_schema.create)
|
||||
def create(self, req, provider_id, body):
|
||||
"""Creates a new copy."""
|
||||
if not self.is_valid_body(body, 'copy'):
|
||||
raise exc.HTTPUnprocessableEntity()
|
||||
|
||||
LOG.debug('Create copy request body: %s', body)
|
||||
context = req.environ['karbor.context']
|
||||
|
@ -69,20 +70,11 @@ class CopiesController(wsgi.Controller):
|
|||
copy = body['copy']
|
||||
plan_id = copy.get("plan_id", None)
|
||||
|
||||
if not uuidutils.is_uuid_like(plan_id):
|
||||
msg = _("Invalid plan id provided.")
|
||||
raise exception.InvalidInput(reason=msg)
|
||||
|
||||
if not uuidutils.is_uuid_like(provider_id):
|
||||
msg = _("Invalid provider id provided.")
|
||||
raise exception.InvalidInput(reason=msg)
|
||||
|
||||
parameters = copy.get("parameters", None)
|
||||
if parameters:
|
||||
if not isinstance(parameters, dict):
|
||||
msg = _("The parameters must be a dict when creating"
|
||||
" a copy.")
|
||||
raise exception.InvalidInput(reason=msg)
|
||||
|
||||
try:
|
||||
plan = objects.Plan.get_by_id(context, plan_id)
|
||||
|
|
Loading…
Reference in New Issue