summaryrefslogtreecommitdiffstats
path: root/nova/api
diff options
context:
space:
mode:
authorSandy Walsh <sandy.walsh@rackspace.com>2011-03-16 06:09:00 -0700
committerSandy Walsh <sandy.walsh@rackspace.com>2011-03-16 06:09:00 -0700
commitddeede35a5036aa3c80742fde69468aedbc74892 (patch)
tree65e1fd3329c8b7f0ccc9b0abefe64e1d5bf17354 /nova/api
parent7a61965908ebfc076ad3b1d9cdc5773ade50bf75 (diff)
downloadnova-ddeede35a5036aa3c80742fde69468aedbc74892.tar.gz
nova-ddeede35a5036aa3c80742fde69468aedbc74892.tar.xz
nova-ddeede35a5036aa3c80742fde69468aedbc74892.zip
Error codes handled properly now
Diffstat (limited to 'nova/api')
-rw-r--r--nova/api/zone_redirect.py94
1 files changed, 53 insertions, 41 deletions
diff --git a/nova/api/zone_redirect.py b/nova/api/zone_redirect.py
index 5e40a82dd..ad47a6216 100644
--- a/nova/api/zone_redirect.py
+++ b/nova/api/zone_redirect.py
@@ -30,6 +30,7 @@ from nova import log as logging
from nova import wsgi
import novaclient.client as client
+import novaclient.exceptions as osexceptions
try:
import json
@@ -49,52 +50,63 @@ class ZoneRedirectMiddleware(wsgi.Middleware):
try:
return req.get_response(self.application)
except exception.ZoneRouteException as e:
- if len(e.zones) == 0:
+ if not e.zones:
exc = webob.exc.HTTPInternalServerError(explanation=
_("No zones to reroute to."))
return faults.Fault(exc)
- zone = e.zones[0]
# Todo(sandy): This only works for OpenStack API currently.
# Needs to be broken out into a driver.
- url = zone.api_url
- LOG.info(_("Zone redirect to:[url:%(api_url)s, username:%(username)s]"
- % dict(api_url=zone.api_url, username=zone.username)))
-
- LOG.info(_("Zone Initial Req: %s"), req)
- nova = client.OpenStackClient(zone.username, zone.password,
- zone.api_url)
- nova.authenticate()
- new_req = req.copy()
- #m = re.search('(https?://.+)/(v\d+\.\d+)/', url)
-
- scheme, netloc, path, query, frag = urlparse.urlsplit(new_req.path_qs)
- query = urlparse.parse_qsl(query)
- LOG.debug("**** QUERY=%s^%s^%s", path, query, frag)
- query = [(key, value) for key, value in query if key != 'fresh']
- query = urllib.urlencode(query)
- url = urlparse.urlunsplit((scheme, netloc, path, query, frag))
-
- m = re.search('/(v\d+\.\d+)/(.+)', url)
- version = m.group(1)
- resource = m.group(2)
-
- LOG.info(_("New Request Data: %s"), new_req.body)
- #LOG.info(_("New Request Headers: %s"), new_req.headers)
- LOG.info(_("New Request Path: %s"), resource)
- if req.method == 'GET':
- response, body = nova.get(resource, body=new_req.body)
- elif req.method == 'POST':
- response, body = nova.post(resource, body=new_req.body)
- elif req.method == 'PUT':
- response, body = nova.put(resource, body=new_req.body)
- elif req.method == 'DELETE':
- response, body = nova.delete(resource, body=new_req.body)
- #response, body = nova.request(req.path_qs, headers=new_req.headers, body=new_req.body)
- LOG.info(_("Zone Response: %s / %s"), response, body)
+ for zone in e.zones:
+ url = zone.api_url
+ LOG.info(_("Zone redirect to:[url:%(api_url)s, "
+ "username:%(username)s]"
+ % dict(api_url=zone.api_url,
+ username=zone.username)))
+
+ nova = client.OpenStackClient(zone.username, zone.password,
+ zone.api_url)
+ nova.authenticate()
+ new_req = req.copy()
+
+ scheme, netloc, path, query, frag = \
+ urlparse.urlsplit(new_req.path_qs)
+ query = urlparse.parse_qsl(query)
+ query = [(key, value) for key, value in query if key != 'fresh']
+ query = urllib.urlencode(query)
+ url = urlparse.urlunsplit((scheme, netloc, path, query, frag))
+
+ m = re.search('/(v\d+\.\d+)/(.+)', url)
+ version = m.group(1)
+ resource = m.group(2)
+
+ #LOG.info(_("New Request Data: %s"), new_req.body)
+ #LOG.info(_("New Request Path: %s"), resource)
+ try:
+ if req.method == 'GET':
+ response, body = nova.get(resource, body=new_req.body)
+ elif req.method == 'POST':
+ response, body = nova.post(resource, body=new_req.body)
+ elif req.method == 'PUT':
+ response, body = nova.put(resource, body=new_req.body)
+ elif req.method == 'DELETE':
+ response, body = nova.delete(resource,
+ body=new_req.body)
+ except osexceptions.OpenStackException, e:
+ LOG.info(_("Zone returned error: %s ('%s', '%s')"),
+ e.code, e.message, e.details)
+ continue
+
+ LOG.info(_("Zone Response: %s [%s]/ %s"), response,
+ response.status, body)
+ if response.status == 200:
+ res = webob.Response()
+ res.status = response['status']
+ res.content_type = response['content-type']
+ res.body = json.dumps(body)
+ return res
+
+ LOG.info(_("Returning 404 ..."))
res = webob.Response()
- res.status = response['status']
- res.content_type = response['content-type']
- res.body = json.dumps(body)
- LOG.info(_("Zone WebOb Response: %s"), res)
+ res.status = "404"
return res