Skip to content
Permalink
Browse files

Use sysmetadata to get instance AZ in API cell

Change-Id: I606a900775810ba4151727ff36fd8e969a884251
  • Loading branch information...
sorrison committed Apr 29, 2014
1 parent 6bf1cf7 commit 95e4cccac623c601e074a618ea71d121a359e00f
Showing with 18 additions and 3 deletions.
  1. +18 −3 nova/availability_zones.py
@@ -20,7 +20,10 @@
from oslo.config import cfg

from nova import objects
from nova.cells import opts as cell_opts
from nova import db
from nova.openstack.common import memorycache
from nova import utils

# NOTE(vish): azs don't change that often, so cache them for an hour to
# avoid hitting the db multiple times on every request.
@@ -183,12 +186,24 @@ def get_instance_availability_zone(context, instance):
host = str(instance.get('host'))
if not host:
return None

cache_key = _make_cache_key(host)
cache_string = host
cell_type = cell_opts.get_cell_type()
if cell_type == 'api':
cell_name = str(instance.get('cell_name'))
if not cell_name:
return None
cache_string += cell_name
cache_key = _make_cache_key(cache_string)
cache = _get_cache()
az = cache.get(cache_key)
if not az:
elevated = context.elevated()
az = get_host_availability_zone(elevated, host)
if cell_type == 'api':
sys_metadata = utils.instance_sys_meta(instance)
az = sys_metadata.get('availability_zone')
if not az:
return None
else:
az = get_host_availability_zone(elevated, host)
cache.set(cache_key, az, AZ_CACHE_SECONDS)
return az

0 comments on commit 95e4ccc

Please sign in to comment.
You can’t perform that action at this time.