Merge "Add validate decorator to expose"
This commit is contained in:
commit
84223be57e
@ -17,7 +17,6 @@ from ironic_lib import metrics_utils
|
||||
from oslo_utils import uuidutils
|
||||
import pecan
|
||||
from webob import exc as webob_exc
|
||||
import wsme
|
||||
|
||||
from ironic import api
|
||||
from ironic.api.controllers import base
|
||||
@ -475,7 +474,7 @@ class AllocationsController(pecan.rest.RestController):
|
||||
self._check_allowed_allocation_fields(fields)
|
||||
|
||||
@METRICS.timer('AllocationsController.patch')
|
||||
@wsme.validate(types.uuid, [AllocationPatchType])
|
||||
@expose.validate(types.uuid, [AllocationPatchType])
|
||||
@expose.expose(Allocation, types.uuid_or_name, body=[AllocationPatchType])
|
||||
def patch(self, allocation_ident, patch):
|
||||
"""Update an existing allocation.
|
||||
|
@ -19,7 +19,6 @@ from http import client as http_client
|
||||
from ironic_lib import metrics_utils
|
||||
from oslo_utils import uuidutils
|
||||
from pecan import rest
|
||||
import wsme
|
||||
|
||||
from ironic import api
|
||||
from ironic.api.controllers import base
|
||||
@ -313,7 +312,7 @@ class ChassisController(rest.RestController):
|
||||
return Chassis.convert_with_links(new_chassis)
|
||||
|
||||
@METRICS.timer('ChassisController.patch')
|
||||
@wsme.validate(types.uuid, [ChassisPatchType])
|
||||
@expose.validate(types.uuid, [ChassisPatchType])
|
||||
@expose.expose(Chassis, types.uuid, body=[ChassisPatchType])
|
||||
def patch(self, chassis_uuid, patch):
|
||||
"""Update an existing chassis.
|
||||
|
@ -21,7 +21,6 @@ from oslo_utils import uuidutils
|
||||
import pecan
|
||||
from pecan import rest
|
||||
from webob import exc as webob_exc
|
||||
import wsme
|
||||
|
||||
from ironic import api
|
||||
from ironic.api.controllers import base
|
||||
@ -383,7 +382,7 @@ class DeployTemplatesController(rest.RestController):
|
||||
return api_template
|
||||
|
||||
@METRICS.timer('DeployTemplatesController.patch')
|
||||
@wsme.validate(types.uuid, types.boolean, [DeployTemplatePatchType])
|
||||
@expose.validate(types.uuid, types.boolean, [DeployTemplatePatchType])
|
||||
@expose.expose(DeployTemplate, types.uuid_or_name, types.boolean,
|
||||
body=[DeployTemplatePatchType])
|
||||
def patch(self, template_ident, patch=None):
|
||||
|
@ -26,7 +26,6 @@ from oslo_utils import strutils
|
||||
from oslo_utils import uuidutils
|
||||
import pecan
|
||||
from pecan import rest
|
||||
import wsme
|
||||
|
||||
from ironic import api
|
||||
from ironic.api.controllers import base
|
||||
@ -2356,7 +2355,7 @@ class NodesController(rest.RestController):
|
||||
policy_checks, node_ident, with_suffix=True)
|
||||
|
||||
@METRICS.timer('NodesController.patch')
|
||||
@wsme.validate(types.uuid, types.boolean, [NodePatchType])
|
||||
@expose.validate(types.uuid, types.boolean, [NodePatchType])
|
||||
@expose.expose(Node, types.uuid_or_name, types.boolean,
|
||||
body=[NodePatchType])
|
||||
def patch(self, node_ident, reset_interfaces=None, patch=None):
|
||||
|
@ -20,7 +20,6 @@ from ironic_lib import metrics_utils
|
||||
from oslo_log import log
|
||||
from oslo_utils import uuidutils
|
||||
from pecan import rest
|
||||
import wsme
|
||||
|
||||
from ironic import api
|
||||
from ironic.api.controllers import base
|
||||
@ -660,7 +659,7 @@ class PortsController(rest.RestController):
|
||||
return Port.convert_with_links(new_port)
|
||||
|
||||
@METRICS.timer('PortsController.patch')
|
||||
@wsme.validate(types.uuid, [PortPatchType])
|
||||
@expose.validate(types.uuid, [PortPatchType])
|
||||
@expose.expose(Port, types.uuid, body=[PortPatchType])
|
||||
def patch(self, port_uuid, patch):
|
||||
"""Update an existing port.
|
||||
|
@ -16,7 +16,6 @@ from http import client as http_client
|
||||
from ironic_lib import metrics_utils
|
||||
from oslo_utils import uuidutils
|
||||
import pecan
|
||||
import wsme
|
||||
|
||||
from ironic import api
|
||||
from ironic.api.controllers import base
|
||||
@ -511,7 +510,7 @@ class PortgroupsController(pecan.rest.RestController):
|
||||
return Portgroup.convert_with_links(new_portgroup)
|
||||
|
||||
@METRICS.timer('PortgroupsController.patch')
|
||||
@wsme.validate(types.uuid_or_name, [PortgroupPatchType])
|
||||
@expose.validate(types.uuid_or_name, [PortgroupPatchType])
|
||||
@expose.expose(Portgroup, types.uuid_or_name, body=[PortgroupPatchType])
|
||||
def patch(self, portgroup_ident, patch):
|
||||
"""Update an existing portgroup.
|
||||
|
@ -18,7 +18,6 @@ from http import client as http_client
|
||||
from ironic_lib import metrics_utils
|
||||
from oslo_utils import uuidutils
|
||||
from pecan import rest
|
||||
import wsme
|
||||
|
||||
from ironic import api
|
||||
from ironic.api.controllers import base
|
||||
@ -377,7 +376,7 @@ class VolumeConnectorsController(rest.RestController):
|
||||
return VolumeConnector.convert_with_links(new_connector)
|
||||
|
||||
@METRICS.timer('VolumeConnectorsController.patch')
|
||||
@wsme.validate(types.uuid, [VolumeConnectorPatchType])
|
||||
@expose.validate(types.uuid, [VolumeConnectorPatchType])
|
||||
@expose.expose(VolumeConnector, types.uuid,
|
||||
body=[VolumeConnectorPatchType])
|
||||
def patch(self, connector_uuid, patch):
|
||||
|
@ -18,7 +18,6 @@ from http import client as http_client
|
||||
from ironic_lib import metrics_utils
|
||||
from oslo_utils import uuidutils
|
||||
from pecan import rest
|
||||
import wsme
|
||||
|
||||
from ironic import api
|
||||
from ironic.api.controllers import base
|
||||
@ -391,7 +390,7 @@ class VolumeTargetsController(rest.RestController):
|
||||
return VolumeTarget.convert_with_links(new_target)
|
||||
|
||||
@METRICS.timer('VolumeTargetsController.patch')
|
||||
@wsme.validate(types.uuid, [VolumeTargetPatchType])
|
||||
@expose.validate(types.uuid, [VolumeTargetPatchType])
|
||||
@expose.expose(VolumeTarget, types.uuid,
|
||||
body=[VolumeTargetPatchType])
|
||||
def patch(self, target_uuid, patch):
|
||||
|
@ -194,3 +194,25 @@ def format_exception(excinfo, debug=False):
|
||||
else:
|
||||
r['debuginfo'] = None
|
||||
return r
|
||||
|
||||
|
||||
class validate(object):
|
||||
"""Decorator that define the arguments types of a function.
|
||||
|
||||
|
||||
Example::
|
||||
|
||||
class MyController(object):
|
||||
@expose(str)
|
||||
@validate(datetime.date, datetime.time)
|
||||
def format(self, d, t):
|
||||
return d.isoformat() + ' ' + t.isoformat()
|
||||
"""
|
||||
def __init__(self, *param_types):
|
||||
self.param_types = param_types
|
||||
|
||||
def __call__(self, func):
|
||||
argspec = wsme.api.getargspec(func)
|
||||
fd = wsme.api.FunctionDefinition.get(func)
|
||||
fd.set_arg_types(argspec, self.param_types)
|
||||
return func
|
||||
|
@ -20,7 +20,6 @@ import platform
|
||||
|
||||
import mock
|
||||
from pecan import rest
|
||||
import wsme
|
||||
|
||||
from ironic.api.controllers.v1 import types
|
||||
from ironic.api import expose
|
||||
@ -107,7 +106,7 @@ class MyPatchType(types.JsonPatchType):
|
||||
class MyTest(rest.RestController):
|
||||
"""Helper class for TestJsonPatchType tests."""
|
||||
|
||||
@wsme.validate([MyPatchType])
|
||||
@expose.validate([MyPatchType])
|
||||
@expose.expose([str], body=[MyPatchType])
|
||||
def patch(self, patch):
|
||||
return patch
|
||||
|
Loading…
x
Reference in New Issue
Block a user