summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYuriy Taraday <yorik.sar@gmail.com>2011-05-31 23:36:49 +0400
committerYuriy Taraday <yorik.sar@gmail.com>2011-05-31 23:36:49 +0400
commitf2da479b8988cd55d39e89935b10e0b348df43c9 (patch)
tree316c803f3c5aec3e02992f59c86bb480c4d6a497
parent2fcc10656222bea6056742ef943c1b82724c0b56 (diff)
downloadnova-f2da479b8988cd55d39e89935b10e0b348df43c9.tar.gz
nova-f2da479b8988cd55d39e89935b10e0b348df43c9.tar.xz
nova-f2da479b8988cd55d39e89935b10e0b348df43c9.zip
Moved everything from thread-local storage to class attributes
-rw-r--r--nova/auth/ldapdriver.py38
-rw-r--r--nova/auth/manager.py14
2 files changed, 14 insertions, 38 deletions
diff --git a/nova/auth/ldapdriver.py b/nova/auth/ldapdriver.py
index 9fe0165a1..91f412baa 100644
--- a/nova/auth/ldapdriver.py
+++ b/nova/auth/ldapdriver.py
@@ -26,7 +26,6 @@ public methods.
import functools
import sys
-import threading
from nova import exception
from nova import flags
@@ -106,7 +105,8 @@ class LdapDriver(object):
isadmin_attribute = 'isNovaAdmin'
project_attribute = 'owner'
project_objectclass = 'groupOfNames'
- __local = threading.local()
+ conn = None
+ mc = None
def __init__(self):
"""Imports the LDAP module"""
@@ -117,15 +117,22 @@ class LdapDriver(object):
LdapDriver.project_attribute = 'projectManager'
LdapDriver.project_objectclass = 'novaProject'
self.__cache = None
+ if LdapDriver.conn is None:
+ LdapDriver.conn = self.ldap.initialize(FLAGS.ldap_url)
+ LdapDriver.conn.simple_bind_s(FLAGS.ldap_user_dn, FLAGS.ldap_password)
+ if LdapDriver.mc is None:
+ if FLAGS.memcached_servers:
+ import memcache
+ else:
+ from nova import fakememcache as memcache
+ LdapDriver.mc = memcache.Client(FLAGS.memcached_servers, debug=0)
def __enter__(self):
- """Creates the connection to LDAP"""
# TODO(yorik-sar): Should be per-request cache, not per-driver-request
self.__cache = {}
return self
def __exit__(self, exc_type, exc_value, traceback):
- """Destroys the connection to LDAP"""
self.__cache = None
return False
@@ -149,29 +156,6 @@ class LdapDriver(object):
return inner
return do_wrap
- @property
- def conn(self):
- try:
- return self.__local.conn
- except AttributeError:
- conn = self.ldap.initialize(FLAGS.ldap_url)
- conn.simple_bind_s(FLAGS.ldap_user_dn, FLAGS.ldap_password)
- self.__local.conn = conn
- return conn
-
- @property
- def mc(self):
- try:
- return self.__local.mc
- except AttributeError:
- if FLAGS.memcached_servers:
- import memcache
- else:
- from nova import fakememcache as memcache
- mc = memcache.Client(FLAGS.memcached_servers, debug=0)
- self.__local.mc = mc
- return mc
-
@sanitize
@__local_cache('uid_user-%s')
def get_user(self, uid):
diff --git a/nova/auth/manager.py b/nova/auth/manager.py
index c71f0f161..c887297f3 100644
--- a/nova/auth/manager.py
+++ b/nova/auth/manager.py
@@ -23,7 +23,6 @@ Nova authentication management
import os
import shutil
import string # pylint: disable=W0402
-import threading
import tempfile
import uuid
import zipfile
@@ -207,7 +206,7 @@ class AuthManager(object):
"""
_instance = None
- __local = threading.local()
+ mc = None
def __new__(cls, *args, **kwargs):
"""Returns the AuthManager singleton"""
@@ -224,19 +223,12 @@ class AuthManager(object):
self.network_manager = utils.import_object(FLAGS.network_manager)
if driver or not getattr(self, 'driver', None):
self.driver = utils.import_class(driver or FLAGS.auth_driver)
-
- @property
- def mc(self):
- try:
- return self.__local.mc
- except AttributeError:
+ if AuthManager.mc is None:
if FLAGS.memcached_servers:
import memcache
else:
from nova import fakememcache as memcache
- mc = memcache.Client(FLAGS.memcached_servers, debug=0)
- self.__local.mc = mc
- return mc
+ AuthManager.mc = memcache.Client(FLAGS.memcached_servers, debug=0)
def authenticate(self, access, signature, params, verb='GET',
server_string='127.0.0.1:8773', path='/',