summaryrefslogtreecommitdiffstats
path: root/nova/api
diff options
context:
space:
mode:
authorgtt116 <gtt116@gmail.com>2013-05-08 14:18:21 +0000
committergtt116 <gtt116@gmail.com>2013-05-11 09:10:04 +0800
commit488fcb4ad345bfb4fd614a140b317b606e008872 (patch)
treee2e93836736088ed1a287c5d0476ca75ace30bd6 /nova/api
parent5dba32a23e67341bfdc03a00781ab491238e21f4 (diff)
Extract getting instance's AZ into a helper module.
An instance's availability zone logic may used by many modules, so move it from extend API into helper module `nova.availability_zones`. Also add some tests for the new method. part of bp: different-availability-zone-filter Change-Id: I5916a0b09d5dddec338e8e36503953720dfd6bcd
Diffstat (limited to 'nova/api')
-rw-r--r--nova/api/openstack/compute/contrib/extended_availability_zone.py22
1 files changed, 2 insertions, 20 deletions
diff --git a/nova/api/openstack/compute/contrib/extended_availability_zone.py b/nova/api/openstack/compute/contrib/extended_availability_zone.py
index 9eec055b1..00765e209 100644
--- a/nova/api/openstack/compute/contrib/extended_availability_zone.py
+++ b/nova/api/openstack/compute/contrib/extended_availability_zone.py
@@ -21,34 +21,16 @@ 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.openstack.common import memorycache
-# 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):
- host = str(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] = self._get_host_az(context, instance)
+ server[key] = availability_zones.get_instance_availability_zone(
+ context, instance)
@wsgi.extends
def show(self, req, resp_obj, id):