summaryrefslogtreecommitdiffstats
path: root/nova/api
diff options
context:
space:
mode:
authorVishvananda Ishaya <vishvananda@gmail.com>2013-02-07 14:46:08 -0800
committerVishvananda Ishaya <vishvananda@gmail.com>2013-02-12 09:00:33 -0800
commit80bd1de65a3b8e7502ece9cedca3c027d176de39 (patch)
treeb3338d44722325e7d39abe7be34edab1fc695cf9 /nova/api
parent64fcd4de113dea91cd36e0fb8ed74f001089a3a9 (diff)
downloadnova-80bd1de65a3b8e7502ece9cedca3c027d176de39.tar.gz
nova-80bd1de65a3b8e7502ece9cedca3c027d176de39.tar.xz
nova-80bd1de65a3b8e7502ece9cedca3c027d176de39.zip
Simplify and optimize az server output extension.
Displaying two different az results to users is confusing, so just return the az that the instance is actually in. Also, cache the result from looking up the az by host for an hour to avoid making lots of expensive db requests. DocImpact Change-Id: Ib39bf94c608874695aab00e61035e64f9594a985
Diffstat (limited to 'nova/api')
-rw-r--r--nova/api/openstack/compute/contrib/extended_availability_zone.py27
1 files changed, 16 insertions, 11 deletions
diff --git a/nova/api/openstack/compute/contrib/extended_availability_zone.py b/nova/api/openstack/compute/contrib/extended_availability_zone.py
index b7451cb6a..734ddf7c8 100644
--- a/nova/api/openstack/compute/contrib/extended_availability_zone.py
+++ b/nova/api/openstack/compute/contrib/extended_availability_zone.py
@@ -21,26 +21,35 @@ from nova.api.openstack import extensions
from nova.api.openstack import wsgi
from nova.api.openstack import xmlutil
from nova import availability_zones
+from nova.common import memorycache
from nova.openstack.common import log as logging
LOG = logging.getLogger(__name__)
+# NOTE(vish): azs don't change that often, so cache them for an hour to
+# avoid hitting the db multiple times on every request.
+AZ_CACHE_SECONDS = 60 * 60
authorize = extensions.soft_extension_authorizer('compute',
'extended_availability_zone')
class ExtendedAZController(wsgi.Controller):
+ def __init__(self):
+ self.mc = memorycache.get_client()
def _get_host_az(self, context, instance):
- admin_context = context.elevated()
- if instance['host']:
- return availability_zones.get_host_availability_zone(
- admin_context, instance['host'])
+ host = instance.get('host')
+ if not host:
+ return None
+ cache_key = "azcache-%s" % host
+ az = self.mc.get(cache_key)
+ if not az:
+ elevated = context.elevated()
+ az = availability_zones.get_host_availability_zone(elevated, host)
+ self.mc.set(cache_key, az, AZ_CACHE_SECONDS)
+ return az
def _extend_server(self, context, server, instance):
key = "%s:availability_zone" % Extended_availability_zone.alias
- server[key] = instance.get('availability_zone', None)
-
- key = "%s:host_availability_zone" % Extended_availability_zone.alias
server[key] = self._get_host_az(context, instance)
@wsgi.extends
@@ -81,10 +90,6 @@ class Extended_availability_zone(extensions.ExtensionDescriptor):
def make_server(elem):
elem.set('{%s}availability_zone' % Extended_availability_zone.namespace,
'%s:availability_zone' % Extended_availability_zone.alias)
- elem.set('{%s}host_availability_zone' %
- Extended_availability_zone.namespace,
- '%s:host_availability_zone' %
- Extended_availability_zone.alias)
class ExtendedAZTemplate(xmlutil.TemplateBuilder):