From 562b5a452db7208b53022aba0e8b6a8f70150587 Mon Sep 17 00:00:00 2001 From: Mark McLoughlin Date: Tue, 8 Jan 2013 09:18:11 +0000 Subject: Move memcached_servers opt into common.memorycache Add a factory function to nova.common.memorycache which consolidates the code to choose between real or fake memcache. This then means that memcached_servers is used in just one place and we can move the config option there. blueprint: scope-config-opts Change-Id: I67c191e0db58364eda4162b9e881606063509b9d --- nova/api/ec2/__init__.py | 9 ++------- nova/api/metadata/handler.py | 9 ++------- 2 files changed, 4 insertions(+), 14 deletions(-) (limited to 'nova/api') diff --git a/nova/api/ec2/__init__.py b/nova/api/ec2/__init__.py index b7742a53c..7cd7e1c7d 100644 --- a/nova/api/ec2/__init__.py +++ b/nova/api/ec2/__init__.py @@ -31,6 +31,7 @@ from nova.api.ec2 import apirequest from nova.api.ec2 import ec2utils from nova.api.ec2 import faults from nova.api import validator +from nova.common import memorycache from nova import context from nova import exception from nova.openstack.common import cfg @@ -72,7 +73,6 @@ ec2_opts = [ CONF = cfg.CONF CONF.register_opts(ec2_opts) -CONF.import_opt('memcached_servers', 'nova.config') CONF.import_opt('use_forwarded_for', 'nova.api.auth') @@ -162,12 +162,7 @@ class Lockout(wsgi.Middleware): def __init__(self, application): """middleware can use fake for testing.""" - if CONF.memcached_servers: - import memcache - else: - from nova.common import memorycache as memcache - self.mc = memcache.Client(CONF.memcached_servers, - debug=0) + self.mc = memorycache.get_client() super(Lockout, self).__init__(application) @webob.dec.wsgify(RequestClass=wsgi.Request) diff --git a/nova/api/metadata/handler.py b/nova/api/metadata/handler.py index b164c5fea..fbb46930b 100644 --- a/nova/api/metadata/handler.py +++ b/nova/api/metadata/handler.py @@ -25,6 +25,7 @@ import webob.dec import webob.exc from nova.api.metadata import base +from nova.common import memorycache from nova import exception from nova.openstack.common import cfg from nova.openstack.common import log as logging @@ -33,7 +34,6 @@ from nova import wsgi CACHE_EXPIRATION = 15 # in seconds CONF = cfg.CONF -CONF.import_opt('memcached_servers', 'nova.config') CONF.import_opt('use_forwarded_for', 'nova.api.auth') metadata_proxy_opts = [ @@ -52,17 +52,12 @@ CONF.register_opts(metadata_proxy_opts) LOG = logging.getLogger(__name__) -if CONF.memcached_servers: - import memcache -else: - from nova.common import memorycache as memcache - class MetadataRequestHandler(wsgi.Application): """Serve metadata.""" def __init__(self): - self._cache = memcache.Client(CONF.memcached_servers, debug=0) + self._cache = memorycache.get_client() def get_metadata_by_remote_address(self, address): if not address: -- cgit