Dan Wendlandt 95b49fad57 API v2: mprove validation of post/put, rename few attributes
bug #1012438

Additional work for bp v2-api-melange-integration

- rename few attributes:
  op_state -> status
  additional_routes -> additional_host_routes
  prefix -> cidr

- expand request body validation to indicate whether fields can be
specified during create and or update.
- add test cases to validate defaults, and input validation.

- update db_base_plugin_v2 to generate gateway_ip for subnet and mac
for port when unspecified.

- validate that tenant-id is only specified in req by admin users

- automatically set tenant-id based on request.context.tenant_id if needed

- enable port tests in test_db_plugin.py

Change-Id: If7f5101e4974a6ef93ff8a1d945f8642dd21b16e
2012-06-13 10:41:36 -07:00

41 lines
1.3 KiB
Python

# Copyright (c) 2012 OpenStack, LLC.
#
# 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.
def resource(data, keys):
"""Formats the specified entity"""
return dict(item for item in data.iteritems() if item[0] in keys)
def port(port_data):
"""Represents a view for a port object"""
keys = ('id', 'network_id', 'mac_address', 'fixed_ips',
'device_id', 'admin_state_up', 'tenant_id', 'status')
return resource(port_data, keys)
def network(network_data):
"""Represents a view for a network object"""
keys = ('id', 'name', 'subnets', 'admin_state_up', 'status',
'tenant_id', 'mac_ranges')
return resource(network_data, keys)
def subnet(subnet_data):
"""Represents a view for a subnet object"""
keys = ('id', 'network_id', 'tenant_id', 'gateway_ip', 'ip_version',
'cidr')
return resource(subnet_data, keys)