Moved everything from thread-local storage to class attributes
This commit is contained in:
@@ -26,7 +26,6 @@ public methods.
|
|||||||
|
|
||||||
import functools
|
import functools
|
||||||
import sys
|
import sys
|
||||||
import threading
|
|
||||||
|
|
||||||
from nova import exception
|
from nova import exception
|
||||||
from nova import flags
|
from nova import flags
|
||||||
@@ -106,7 +105,8 @@ class LdapDriver(object):
|
|||||||
isadmin_attribute = 'isNovaAdmin'
|
isadmin_attribute = 'isNovaAdmin'
|
||||||
project_attribute = 'owner'
|
project_attribute = 'owner'
|
||||||
project_objectclass = 'groupOfNames'
|
project_objectclass = 'groupOfNames'
|
||||||
__local = threading.local()
|
conn = None
|
||||||
|
mc = None
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
"""Imports the LDAP module"""
|
"""Imports the LDAP module"""
|
||||||
@@ -117,15 +117,22 @@ class LdapDriver(object):
|
|||||||
LdapDriver.project_attribute = 'projectManager'
|
LdapDriver.project_attribute = 'projectManager'
|
||||||
LdapDriver.project_objectclass = 'novaProject'
|
LdapDriver.project_objectclass = 'novaProject'
|
||||||
self.__cache = None
|
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):
|
def __enter__(self):
|
||||||
"""Creates the connection to LDAP"""
|
|
||||||
# TODO(yorik-sar): Should be per-request cache, not per-driver-request
|
# TODO(yorik-sar): Should be per-request cache, not per-driver-request
|
||||||
self.__cache = {}
|
self.__cache = {}
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def __exit__(self, exc_type, exc_value, traceback):
|
def __exit__(self, exc_type, exc_value, traceback):
|
||||||
"""Destroys the connection to LDAP"""
|
|
||||||
self.__cache = None
|
self.__cache = None
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@@ -149,29 +156,6 @@ class LdapDriver(object):
|
|||||||
return inner
|
return inner
|
||||||
return do_wrap
|
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
|
@sanitize
|
||||||
@__local_cache('uid_user-%s')
|
@__local_cache('uid_user-%s')
|
||||||
def get_user(self, uid):
|
def get_user(self, uid):
|
||||||
|
|||||||
@@ -23,7 +23,6 @@ Nova authentication management
|
|||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
import string # pylint: disable=W0402
|
import string # pylint: disable=W0402
|
||||||
import threading
|
|
||||||
import tempfile
|
import tempfile
|
||||||
import uuid
|
import uuid
|
||||||
import zipfile
|
import zipfile
|
||||||
@@ -207,7 +206,7 @@ class AuthManager(object):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
_instance = None
|
_instance = None
|
||||||
__local = threading.local()
|
mc = None
|
||||||
|
|
||||||
def __new__(cls, *args, **kwargs):
|
def __new__(cls, *args, **kwargs):
|
||||||
"""Returns the AuthManager singleton"""
|
"""Returns the AuthManager singleton"""
|
||||||
@@ -224,19 +223,12 @@ class AuthManager(object):
|
|||||||
self.network_manager = utils.import_object(FLAGS.network_manager)
|
self.network_manager = utils.import_object(FLAGS.network_manager)
|
||||||
if driver or not getattr(self, 'driver', None):
|
if driver or not getattr(self, 'driver', None):
|
||||||
self.driver = utils.import_class(driver or FLAGS.auth_driver)
|
self.driver = utils.import_class(driver or FLAGS.auth_driver)
|
||||||
|
if AuthManager.mc is None:
|
||||||
@property
|
|
||||||
def mc(self):
|
|
||||||
try:
|
|
||||||
return self.__local.mc
|
|
||||||
except AttributeError:
|
|
||||||
if FLAGS.memcached_servers:
|
if FLAGS.memcached_servers:
|
||||||
import memcache
|
import memcache
|
||||||
else:
|
else:
|
||||||
from nova import fakememcache as memcache
|
from nova import fakememcache as memcache
|
||||||
mc = memcache.Client(FLAGS.memcached_servers, debug=0)
|
AuthManager.mc = memcache.Client(FLAGS.memcached_servers, debug=0)
|
||||||
self.__local.mc = mc
|
|
||||||
return mc
|
|
||||||
|
|
||||||
def authenticate(self, access, signature, params, verb='GET',
|
def authenticate(self, access, signature, params, verb='GET',
|
||||||
server_string='127.0.0.1:8773', path='/',
|
server_string='127.0.0.1:8773', path='/',
|
||||||
|
|||||||
Reference in New Issue
Block a user