Merge branch 'handle_delete_trailing_slash' into compute_controller

Conflicts:
	ooi/api/base.py
This commit is contained in:
Alvaro Lopez Garcia 2015-04-10 14:09:58 +02:00
commit 65edb4b8c7
3 changed files with 39 additions and 2 deletions

View File

@ -26,7 +26,11 @@ class Controller(object):
self.app = app
self.openstack_version = openstack_version
def _get_req(self, req, path=None, content_type=None, body=None):
def _get_req(self, req,
path=None,
content_type=None,
body=None,
method=None):
"""Return a new Request object to interact with OpenStack.
This method will create a new request starting with the same WSGI
@ -49,6 +53,8 @@ class Controller(object):
new_req.content_type = content_type
if body is not None:
new_req.body = utils.utf8(body)
if method is not None:
new_req.method = method
return new_req
@staticmethod

View File

@ -34,6 +34,27 @@ class Controller(ooi.api.base.Controller):
return occi_compute_resources
def _get_compute_ids(self, req):
tenant_id = req.environ["keystone.token_auth"].user.project_id
req = self._get_req(req,
path="/%s/servers" % tenant_id,
method="GET")
response = req.get_response(self.app)
return [s["id"] for s in self.get_from_response(response,
"servers", [])]
def _delete(self, req, ids):
tenant_id = req.environ["keystone.token_auth"].user.project_id
for id in ids:
req = self._get_req(req,
path="/%s/servers/%s" % (tenant_id,
id),
method="DELETE")
response = req.get_response(self.app)
if response.status_int not in [204]:
raise ooi.api.base.exception_from_response(response)
return []
def index(self, req):
tenant_id = req.environ["keystone.token_auth"].user.project_id
req = self._get_req(req, path="/%s/servers" % tenant_id)
@ -71,7 +92,7 @@ class Controller(ooi.api.base.Controller):
return collection.Collection(resources=occi_compute_resources)
def show(self, id, req):
def show(self, req, id):
tenant_id = req.environ["keystone.token_auth"].user.project_id
# get info from server
@ -106,3 +127,9 @@ class Controller(ooi.api.base.Controller):
state=helpers.occi_state(s["status"]),
mixins=[os_tpl, res_tpl])
return [comp]
def delete(self, req, id):
return self._delete(req, [id])
def delete_all(self, req):
return self._delete(req, self._get_compute_ids(req))

View File

@ -118,6 +118,10 @@ class OCCIMiddleware(object):
ooi.api.compute.Controller)
self.mapper.resource("server", "compute",
controller=self.resources["compute"])
self.mapper.connect("compute", "/compute/",
controller=self.resources["compute"],
action="delete_all",
conditions=dict(method=["DELETE"]))
@webob.dec.wsgify(RequestClass=Request)
def __call__(self, req):