def test_and(self): @args.validate(foo=args.and_valid( args.string, args.name )) def doit(foo): return foo # valid self.assertEqual('bar', doit('bar')) # invalid, not a string self.assertRaises(exception.InvalidParameterValue, doit, 2) # invalid, not a name self.assertRaises(exception.InvalidParameterValue, doit, 'not a name')
class EventsController(pecan.rest.RestController): """REST controller for Events.""" @pecan.expose() def _lookup(self): if not api_utils.allow_expose_events(): pecan.abort(http_client.NOT_FOUND) @METRICS.timer('EventsController.post') @method.expose(status_code=http_client.NO_CONTENT) @method.body('evts') @args.validate(evts=args.and_valid(args.schema(EVENTS_SCHEMA), events_valid)) def post(self, evts): if not api_utils.allow_expose_events(): raise exception.NotFound() api_utils.check_policy('baremetal:events:post') for e in evts['events']: LOG.debug("Received external event: %s", e)
'type': 'string' }, 'uuid': { 'type': ['string', 'null'] }, }, 'required': ['boot_index', 'node_uuid', 'volume_id', 'volume_type'], 'additionalProperties': False, } TARGET_VALIDATOR_EXTRA = args.dict_valid( node_uuid=args.uuid, uuid=args.uuid, ) TARGET_VALIDATOR = args.and_valid(args.schema(TARGET_SCHEMA), TARGET_VALIDATOR_EXTRA) PATCH_ALLOWED_FIELDS = [ 'boot_index', 'extra', 'node_uuid', 'properties', 'volume_id', 'volume_type' ] def convert_with_links(rpc_target, fields=None, sanitize=True): target = api_utils.object_to_dict(rpc_target, link_resource='volume/targets', fields=('boot_index', 'extra', 'properties', 'volume_id', 'volume_type')) api_utils.populate_node_uuid(rpc_target, target)
'uuid': { 'type': ['string', 'null'] }, }, 'required': ['node_uuid'], 'additionalProperties': False, } PORTGROUP_PATCH_SCHEMA = PORTGROUP_SCHEMA PORTGROUP_VALIDATOR_EXTRA = args.dict_valid( address=args.mac_address, node_uuid=args.uuid, standalone_ports_supported=args.boolean, uuid=args.uuid) PORTGROUP_VALIDATOR = args.and_valid(args.schema(PORTGROUP_SCHEMA), PORTGROUP_VALIDATOR_EXTRA) PORTGROUP_PATCH_VALIDATOR = args.and_valid(args.schema(PORTGROUP_PATCH_SCHEMA), PORTGROUP_VALIDATOR_EXTRA) PATCH_ALLOWED_FIELDS = [ 'address', 'extra', 'mode', 'name', 'node_uuid', 'properties', 'standalone_ports_supported' ] def convert_with_links(rpc_portgroup, fields=None, sanitize=True): """Add links to the portgroup.""" portgroup = api_utils.object_to_dict( rpc_portgroup, link_resource='portgroups',
'resource_class': { 'type': ['string', 'null'], 'maxLength': 80 }, 'traits': { 'type': ['array', 'null'], 'items': api_utils.TRAITS_SCHEMA }, 'uuid': { 'type': ['string', 'null'] }, }, 'additionalProperties': False, } ALLOCATION_VALIDATOR = args.and_valid(args.schema(ALLOCATION_SCHEMA), args.dict_valid(uuid=args.uuid)) PATCH_ALLOWED_FIELDS = ['name', 'extra'] def hide_fields_in_newer_versions(allocation): # if requested version is < 1.60, hide owner field if not api_utils.allow_allocation_owner(): allocation.pop('owner', None) def convert_with_links(rpc_allocation, fields=None, sanitize=True): allocation = api_utils.object_to_dict( rpc_allocation, link_resource='allocations',
'extra': {'type': ['object', 'null']}, 'node_uuid': {'type': 'string'}, 'type': {'type': 'string'}, 'uuid': {'type': ['string', 'null']}, }, 'required': ['connector_id', 'node_uuid', 'type'], 'additionalProperties': False, } CONNECTOR_VALIDATOR_EXTRA = args.dict_valid( node_uuid=args.uuid, uuid=args.uuid, ) CONNECTOR_VALIDATOR = args.and_valid( args.schema(CONNECTOR_SCHEMA), CONNECTOR_VALIDATOR_EXTRA ) PATCH_ALLOWED_FIELDS = [ 'connector_id', 'extra', 'node_uuid', 'type' ] def convert_with_links(rpc_connector, fields=None, sanitize=True): connector = api_utils.object_to_dict( rpc_connector, link_resource='volume/connectors', fields=('connector_id', 'extra', 'type')
(step['interface'], step['step']) for step in value['steps']) duplicates = {key for key, count in counter.items() if count > 1} if duplicates: duplicates = { "interface: %s, step: %s" % (interface, step) for interface, step in duplicates } err = _("Duplicate deploy steps. A deploy template cannot have " "multiple deploy steps with the same interface and step. " "Duplicates: %s") % "; ".join(duplicates) raise exception.InvalidDeployTemplate(err=err) return value TEMPLATE_VALIDATOR = args.and_valid(args.schema(TEMPLATE_SCHEMA), duplicate_steps, args.dict_valid(uuid=args.uuid)) def convert_steps(rpc_steps): for step in rpc_steps: yield { 'interface': step['interface'], 'step': step['step'], 'args': step['args'], 'priority': step['priority'], } def convert_with_links(rpc_template, fields=None, sanitize=True): """Add links to the deploy template."""
NETWORK_EVENT_VALIDATOR = args.and_valid( args.schema({ 'type': 'object', 'properties': { 'event': { 'type': 'string' }, 'port_id': { 'type': 'string' }, 'mac_address': { 'type': 'string' }, 'status': { 'type': 'string' }, 'device_id': { 'type': ['string', 'null'] }, 'binding:host_id': { 'type': ['string', 'null'] }, 'binding:vnic_type': { 'type': ['string', 'null'] }, }, 'required': ['event', 'port_id', 'mac_address', 'status'], 'additionalProperties': False, }), args.dict_valid( **{ 'port_id': args.uuid, 'mac_address': args.mac_address, 'device_id': args.uuid, 'binding:host_id': args.uuid }))
'properties': { 'uuid': { 'type': ['string', 'null'] }, 'extra': { 'type': ['object', 'null'] }, 'description': { 'type': ['string', 'null'], 'maxLength': 255 }, }, 'additionalProperties': False, } CHASSIS_VALIDATOR = args.and_valid(args.schema(CHASSIS_SCHEMA), args.dict_valid(uuid=args.uuid)) DEFAULT_RETURN_FIELDS = ['uuid', 'description'] def convert_with_links(rpc_chassis, fields=None, sanitize=True): chassis = api_utils.object_to_dict(rpc_chassis, fields=('description', 'extra'), link_resource='chassis') url = api.request.public_url chassis['nodes'] = [ link.make_link('self', url, 'chassis', rpc_chassis.uuid + "/nodes"), link.make_link('bookmark', url, 'chassis',