diff options
author | Jenkins <jenkins@review.openstack.org> | 2014-06-25 12:50:15 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2014-06-25 12:50:15 +0000 |
commit | 2d9045a313aa6b8e10dcdf1f413fd1c71c824d45 (patch) | |
tree | d4c34a988a11915fe8a8a5b815237555c69d62bd /nova/api/openstack | |
parent | 96195fd0ab203156e5fce57260fb030a52c81511 (diff) | |
parent | d457f5fb51b1c725bf868f04fe2977008ddc261b (diff) | |
download | nova-2d9045a313aa6b8e10dcdf1f413fd1c71c824d45.tar.gz |
Merge "Add API schema for v2.1/v3 flavor_manage API"
Diffstat (limited to 'nova/api/openstack')
-rw-r--r-- | nova/api/openstack/compute/plugins/v3/flavor_manage.py | 18 | ||||
-rw-r--r-- | nova/api/openstack/compute/schemas/v3/flavor_manage.py | 71 |
2 files changed, 78 insertions, 11 deletions
diff --git a/nova/api/openstack/compute/plugins/v3/flavor_manage.py b/nova/api/openstack/compute/plugins/v3/flavor_manage.py index 7ad9f5f041..cb9707fb1c 100644 --- a/nova/api/openstack/compute/plugins/v3/flavor_manage.py +++ b/nova/api/openstack/compute/plugins/v3/flavor_manage.py @@ -12,12 +12,13 @@ import webob +from nova.api.openstack.compute.schemas.v3 import flavor_manage from nova.api.openstack.compute.views import flavors as flavors_view from nova.api.openstack import extensions from nova.api.openstack import wsgi +from nova.api import validation from nova.compute import flavors from nova import exception -from nova.openstack.common.gettextutils import _ ALIAS = "flavor-manage" @@ -50,21 +51,18 @@ class FlavorManageController(wsgi.Controller): @wsgi.response(201) @wsgi.action("create") @extensions.expected_errors((400, 409)) + @validation.schema(flavor_manage.create) def _create(self, req, body): context = req.environ['nova.context'] authorize(context) - if not self.is_valid_body(body, 'flavor'): - msg = _('Invalid request body') - raise webob.exc.HTTPBadRequest(explanation=msg) - vals = body['flavor'] - name = vals.get('name') + name = vals['name'] flavorid = vals.get('id') - memory = vals.get('ram') - vcpus = vals.get('vcpus') - root_gb = vals.get('disk') + memory = vals['ram'] + vcpus = vals['vcpus'] + root_gb = vals['disk'] ephemeral_gb = vals.get('ephemeral', 0) swap = vals.get('swap', 0) rxtx_factor = vals.get('os-flavor-rxtx:rxtx_factor', 1.0) @@ -83,8 +81,6 @@ class FlavorManageController(wsgi.Controller): except (exception.FlavorExists, exception.FlavorIdExists) as err: raise webob.exc.HTTPConflict(explanation=err.format_message()) - except exception.InvalidInput as exc: - raise webob.exc.HTTPBadRequest(explanation=exc.format_message()) return self._view_builder.show(req, flavor) diff --git a/nova/api/openstack/compute/schemas/v3/flavor_manage.py b/nova/api/openstack/compute/schemas/v3/flavor_manage.py new file mode 100644 index 0000000000..173dd1783c --- /dev/null +++ b/nova/api/openstack/compute/schemas/v3/flavor_manage.py @@ -0,0 +1,71 @@ +# 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. + +from nova.api.openstack.compute.plugins.v3 import flavor_rxtx +from nova.api.validation import parameter_types + +create = { + 'type': 'object', + 'properties': { + 'flavor': { + 'type': 'object', + 'properties': { + # in nova/flavors.py, name with all white spaces is forbidden. + 'name': parameter_types.name, + # forbid leading/trailing whitespaces + 'id': { + 'type': ['string', 'number', 'null'], + 'minLength': 1, 'maxLength': 255, + 'pattern': '^(?! )[a-zA-Z0-9. _-]+(?<! )$' + }, + # positive ( > 0) integer + 'ram': { + 'type': ['integer', 'string'], + 'pattern': '^[0-9]*$', 'minimum': 1 + }, + # positive ( > 0) integer + 'vcpus': { + 'type': ['integer', 'string'], + 'pattern': '^[0-9]*$', 'minimum': 1 + }, + # non-negative ( >= 0) integer + 'disk': { + 'type': ['integer', 'string'], + 'pattern': '^[0-9]*$', 'minimum': 0 + }, + # non-negative ( >= 0) integer + 'ephemeral': { + 'type': ['integer', 'string'], + 'pattern': '^[0-9]*$', 'minimum': 0 + }, + # non-negative ( >= 0) integer + 'swap': { + 'type': ['integer', 'string'], + 'pattern': '^[0-9]*$', 'minimum': 0 + }, + # positive ( > 0) float + '%s:rxtx_factor' % flavor_rxtx.ALIAS: { + 'type': ['number', 'string'], + 'pattern': '^[0-9]+(\.[0-9]+)?$', + 'minimum': 0, 'exclusiveMinimum': True + }, + 'flavor-access:is_public': parameter_types.boolean, + }, + 'required': ['name', 'id', 'ram', 'vcpus', 'disk'], + 'additionalProperties': False, + }, + }, + 'required': ['flavor'], + 'additionalProperties': False, +} |