Adds API parameters to quantum.api.extension.ResourceExtension

Part of blueprint quantum-api-wadl

Fixes bug #1104882

Change-Id: I0d30864d3176ab001b10948f1deb37b3c062987c
This commit is contained in:
Zhongyue Luo 2013-01-25 16:48:21 +08:00
parent 4538eebf44
commit ed39d8a71b
7 changed files with 41 additions and 8 deletions

View File

@ -590,13 +590,14 @@ class ResourceExtension(object):
"""Add top level resources to the OpenStack API in Quantum."""
def __init__(self, collection, controller, parent=None, path_prefix="",
collection_actions={}, member_actions={}):
collection_actions={}, member_actions={}, attr_map={}):
self.collection = collection
self.controller = controller
self.parent = parent
self.collection_actions = collection_actions
self.member_actions = member_actions
self.path_prefix = path_prefix
self.attr_map = attr_map
# Returns the extention paths from a config entry and the __path__

View File

@ -207,7 +207,8 @@ class L3(extensions.ExtensionDescriptor):
ex = extensions.ResourceExtension(collection_name,
controller,
member_actions=member_actions)
member_actions=member_actions,
attr_map=params)
exts.append(ex)
return exts

View File

@ -281,7 +281,8 @@ class Loadbalancer(extensions.ExtensionDescriptor):
collection_name,
controller,
path_prefix=constants.COMMON_PREFIXES[constants.LOADBALANCER],
member_actions=member_actions)
member_actions=member_actions,
attr_map=params)
resources.append(resource)
for collection_name in SUB_RESOURCE_ATTRIBUTE_MAP:
@ -300,7 +301,8 @@ class Loadbalancer(extensions.ExtensionDescriptor):
resource = extensions.ResourceExtension(
collection_name,
controller, parent,
path_prefix=constants.COMMON_PREFIXES[constants.LOADBALANCER])
path_prefix=constants.COMMON_PREFIXES[constants.LOADBALANCER],
attr_map=params)
resources.append(resource)
return resources

View File

@ -302,7 +302,8 @@ class Securitygroup(extensions.ExtensionDescriptor):
plugin, params, allow_bulk=True)
ex = extensions.ResourceExtension(collection_name,
controller)
controller,
attr_map=params)
exts.append(ex)
return exts

View File

@ -188,9 +188,12 @@ class Servicetype(extensions.ExtensionDescriptor):
key in RESOURCE_ATTRIBUTE_MAP.keys()]
my_plurals.append(('service_definitions', 'service_definition'))
attributes.PLURALS.update(dict(my_plurals))
attr_map = RESOURCE_ATTRIBUTE_MAP[COLLECTION_NAME]
controller = base.create_resource(
COLLECTION_NAME,
RESOURCE_NAME,
servicetype_db.ServiceTypeManager.get_instance(),
RESOURCE_ATTRIBUTE_MAP[COLLECTION_NAME])
return [extensions.ResourceExtension(COLLECTION_NAME, controller)]
attr_map)
return [extensions.ResourceExtension(COLLECTION_NAME,
controller,
attr_map=attr_map)]

View File

@ -127,4 +127,6 @@ class Packetfilter(extensions.ExtensionDescriptor):
quota._count_resource,
'quota_packet_filter')
quota.QUOTAS.register_resource(qresource)
return [extensions.ResourceExtension('packet_filters', resource)]
return [extensions.ResourceExtension('packet_filters',
resource,
attr_map=PACKET_FILTER_ATTR_MAP)]

View File

@ -277,6 +277,29 @@ class ResourceExtensionTest(unittest.TestCase):
self.assertEqual(200, response.status_int)
self.assertEqual(jsonutils.loads(response.body)['collection'], "value")
def test_resource_extension_with_custom_member_action_and_attr_map(self):
controller = self.ResourceExtensionController()
member = {'custom_member_action': "GET"}
params = {
'tweedles': {
'id': {'allow_post': False, 'allow_put': False,
'validate': {'type:uuid': None},
'is_visible': True},
'name': {'allow_post': True, 'allow_put': True,
'validate': {'type:string': None},
'default': '', 'is_visible': True},
}
}
res_ext = extensions.ResourceExtension('tweedles', controller,
member_actions=member,
attr_map=params)
test_app = _setup_extensions_test_app(SimpleExtensionManager(res_ext))
response = test_app.get("/tweedles/some_id/custom_member_action")
self.assertEqual(200, response.status_int)
self.assertEqual(jsonutils.loads(response.body)['member_action'],
"value")
def test_returns_404_for_non_existent_extension(self):
test_app = _setup_extensions_test_app(SimpleExtensionManager(None))