diff --git a/quantum/api/extensions.py b/quantum/api/extensions.py index 5062ee15e..d321a8668 100644 --- a/quantum/api/extensions.py +++ b/quantum/api/extensions.py @@ -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__ diff --git a/quantum/extensions/l3.py b/quantum/extensions/l3.py index 5499c7a60..e3a1263d2 100644 --- a/quantum/extensions/l3.py +++ b/quantum/extensions/l3.py @@ -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 diff --git a/quantum/extensions/loadbalancer.py b/quantum/extensions/loadbalancer.py index df423233c..7484ba508 100644 --- a/quantum/extensions/loadbalancer.py +++ b/quantum/extensions/loadbalancer.py @@ -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 diff --git a/quantum/extensions/securitygroup.py b/quantum/extensions/securitygroup.py index 756c0753c..cd3ee9c18 100644 --- a/quantum/extensions/securitygroup.py +++ b/quantum/extensions/securitygroup.py @@ -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 diff --git a/quantum/extensions/servicetype.py b/quantum/extensions/servicetype.py index d4a987cd4..58fae25f6 100644 --- a/quantum/extensions/servicetype.py +++ b/quantum/extensions/servicetype.py @@ -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)] diff --git a/quantum/plugins/nec/extensions/packetfilter.py b/quantum/plugins/nec/extensions/packetfilter.py index e885535ee..cb510374c 100644 --- a/quantum/plugins/nec/extensions/packetfilter.py +++ b/quantum/plugins/nec/extensions/packetfilter.py @@ -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)] diff --git a/quantum/tests/unit/test_extensions.py b/quantum/tests/unit/test_extensions.py index e287ab1da..c5d50e9d3 100644 --- a/quantum/tests/unit/test_extensions.py +++ b/quantum/tests/unit/test_extensions.py @@ -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))