From 507c2ef511bb500c69a4787057032ba0a842d3e5 Mon Sep 17 00:00:00 2001 From: Enol Fernandez Date: Thu, 30 Apr 2015 19:44:01 +0000 Subject: [PATCH] Manual creation of the routes to resources. This avoids URL ending in .* to be splitted in id, format Needed for the network link ids which contain IP addresses. --- ooi/wsgi/__init__.py | 85 ++++++++++++++++++++------------------------ 1 file changed, 38 insertions(+), 47 deletions(-) diff --git a/ooi/wsgi/__init__.py b/ooi/wsgi/__init__.py index f65c951..619e983 100644 --- a/ooi/wsgi/__init__.py +++ b/ooi/wsgi/__init__.py @@ -94,6 +94,33 @@ def __init__(self, application, openstack_version="/v2.1"): def _create_resource(self, controller): return Resource(controller(self.application, self.openstack_version)) + def _setup_resource_routes(self, resource, controller): + path = "/" + resource + # This could be removed for total OCCI compliance + self.mapper.connect(resource, path, controller=controller, + action="index", conditions=dict(method=["GET"])) + # OCCI states that paths must end with a "/" when operating on pahts, + # that are not location pahts or resource instances + self.mapper.connect(resource, path + "/", controller=controller, + action="index", conditions=dict(method=["GET"])) + self.mapper.connect(resource, path, controller=controller, + action="create", conditions=dict(method=["POST"])) + self.mapper.connect(resource, path + "/{id}", controller=controller, + action="update", conditions=dict(method=["PUT"])) + self.mapper.connect(resource, path + "/{id}", controller=controller, + action="delete", + conditions=dict(method=["DELETE"])) + self.mapper.connect(resource, path + "/{id}", controller=controller, + action="show", conditions=dict(method=["GET"])) + # OCCI specific, delete all resources + self.mapper.connect(path + "/", controller=controller, + action="delete_all", + conditions=dict(method=["DELETE"])) + # Actions + self.mapper.connect(path + "/{id}", controller=controller, + action="run_action", + conditions=dict(method=["POST"])) + def _setup_routes(self): """Setup the mapper routes. @@ -140,47 +167,23 @@ def index(self, *args, **kwargs): self.resources["compute"] = self._create_resource( ooi.api.compute.Controller) - self.mapper.resource("server", "compute", - controller=self.resources["compute"]) - # OCCI states that paths must end with a "/" when operating on pahts, - # that are not location pahts or resource instances, so we should add - # this rule manually - self.mapper.connect("compute", "/compute/", - controller=self.resources["compute"], - action="index", - conditions=dict(method=["GET"])) - self.mapper.connect("compute", "/compute/", - controller=self.resources["compute"], - action="delete_all", - conditions=dict(method=["DELETE"])) - self.mapper.connect("/compute/{id}", - controller=self.resources["compute"], - action="run_action", - conditions=dict(method=["POST"])) + self._setup_resource_routes("compute", self.resources["compute"]) self.resources["storage"] = self._create_resource( ooi.api.storage.Controller) - self.mapper.resource("volume", "storage", - controller=self.resources["storage"]) - # OCCI states that paths must end with a "/" when operating on pahts, - # that are not location pahts or resource instances, so we should add - # this rule manually - self.mapper.connect("storage", "/storage/", - controller=self.resources["storage"], - action="index", - conditions=dict(method=["GET"])) + self._setup_resource_routes("storage", self.resources["storage"]) + self.resources["storagelink"] = self._create_resource( ooi.api.storage_link.Controller) - self.mapper.resource("volume", "storagelink", - controller=self.resources["storagelink"]) - # OCCI states that paths must end with a "/" when operating on pahts, - # that are not location pahts or resource instances, so we should add - # this rule manually - self.mapper.connect("storagelink", "/storagelink/", - controller=self.resources["storagelink"], - action="index", - conditions=dict(method=["GET"])) + self._setup_resource_routes("storagelink", + self.resources["storagelink"]) + self.resources["networklink"] = self._create_resource( + ooi.api.network_link.Controller) + self._setup_resource_routes("networklink", + self.resources["networklink"]) + + # TODO(enolfc): move to _setup_resource_routes or similar # Network is a bit different from other resources # we have /network and below that /network/fixed # and /network/floating/* for the pools @@ -205,18 +208,6 @@ def index(self, *args, **kwargs): self.mapper.resource("floating_network", netpool_name, controller=self.resources["network"]) - self.resources["networklink"] = self._create_resource( - ooi.api.network_link.Controller) - self.mapper.resource("networkinterface", "networklink", - controller=self.resources["networklink"]) - # OCCI states that paths must end with a "/" when operating on pahts, - # that are not location pahts or resource instances, so we should add - # this rule manually - self.mapper.connect("networkinterface", "/networklink/", - controller=self.resources["networklink"], - action="index", - conditions=dict(method=["GET"])) - @webob.dec.wsgify(RequestClass=Request) def __call__(self, req): response = self.process_request(req)