summaryrefslogtreecommitdiffstats
path: root/openstack/common
diff options
context:
space:
mode:
authorRajaram Mallya <rajarammallya@gmail.com>2011-09-07 18:08:28 +0530
committerRajaram Mallya <rajarammallya@gmail.com>2011-09-07 18:08:28 +0530
commit87dceb46c403305264387925efd5baa1ecb91c54 (patch)
tree7f7ee416f26c911da27a9b7cd33046bbfc051218 /openstack/common
parent2a529c6cb7cfed08a7afe8fc0f8249bc9bdb2621 (diff)
downloadoslo-87dceb46c403305264387925efd5baa1ecb91c54.tar.gz
oslo-87dceb46c403305264387925efd5baa1ecb91c54.tar.xz
oslo-87dceb46c403305264387925efd5baa1ecb91c54.zip
Rajaram/Vinkesh | Fixed the extension bug where custom collection actions' routes in resource extension were not getting registered
Diffstat (limited to 'openstack/common')
-rw-r--r--openstack/common/extensions.py48
1 files changed, 33 insertions, 15 deletions
diff --git a/openstack/common/extensions.py b/openstack/common/extensions.py
index 4bef1e7..7044227 100644
--- a/openstack/common/extensions.py
+++ b/openstack/common/extensions.py
@@ -247,21 +247,20 @@ class ExtensionMiddleware(wsgi.Middleware):
mapper = routes.Mapper()
# extended resources
- for resource in ext_mgr.get_resources():
- LOG.debug(_('Extended resource: %s'),
- resource.collection)
-
- kargs = dict(
- controller=wsgi.Resource(
- resource.controller, resource.deserializer,
- resource.serializer),
- collection=resource.collection_actions,
- member=resource.member_actions)
-
- if resource.parent:
- kargs['parent_resource'] = resource.parent
-
- mapper.resource(resource.collection, resource.collection, **kargs)
+ for resource_ext in ext_mgr.get_resources():
+ LOG.debug(_('Extended resource: %s'), resource_ext.collection)
+ controller_resource = wsgi.Resource(resource_ext.controller,
+ resource_ext.deserializer,
+ resource_ext.serializer)
+ self._map_custom_collection_actions(resource_ext, mapper,
+ controller_resource)
+ kargs = dict(controller=controller_resource,
+ collection=resource_ext.collection_actions,
+ member=resource_ext.member_actions)
+ if resource_ext.parent:
+ kargs['parent_resource'] = resource_ext.parent
+ mapper.resource(resource_ext.collection,
+ resource_ext.collection, **kargs)
# extended actions
action_resources = self._action_ext_resources(application, ext_mgr,
@@ -284,6 +283,25 @@ class ExtensionMiddleware(wsgi.Middleware):
super(ExtensionMiddleware, self).__init__(application)
+ def _map_custom_collection_actions(self, resource_ext, mapper,
+ controller_resource):
+ for action, method in resource_ext.collection_actions.iteritems():
+ parent = resource_ext.parent
+ conditions = dict(method=[method])
+ path = "/%s/%s" % (resource_ext.collection, action)
+
+ path_prefix = ""
+ if parent:
+ path_prefix = "/%s/{%s_id}" % (parent["collection_name"],
+ parent["member_name"])
+
+ with mapper.submapper(controller=controller_resource,
+ action=action,
+ path_prefix=path_prefix,
+ conditions=conditions) as submap:
+ submap.connect(path)
+ submap.connect("%s.:(format)" % path)
+
@webob.dec.wsgify(RequestClass=wsgi.Request)
def __call__(self, req):
"""Route the incoming request with router."""