Skip to content

Commit

Permalink
Manual creation of the routes to resources.
Browse files Browse the repository at this point in the history
This avoids URL ending in .* to be splitted in id, format
Needed for the network link ids which contain IP addresses.
  • Loading branch information
enolfc committed Apr 30, 2015
1 parent c098e32 commit 507c2ef
Showing 1 changed file with 38 additions and 47 deletions.
85 changes: 38 additions & 47 deletions ooi/wsgi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit 507c2ef

Please sign in to comment.