summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVishvananda Ishaya <vishvananda@gmail.com>2010-07-28 23:42:35 +0000
committerTarmac <>2010-07-28 23:42:35 +0000
commit4e5737815bd62e0d78add8932ceb220b1ac3787d (patch)
treecd107dd9f2e9f519219b3fca478265d6c2580c22
parent96995456ccd24ec46f703bfa3e784eb193858bbb (diff)
parenta7e5d47d8e49f8fc10900ede3376ddc515799811 (diff)
Allow driver specification in AuthManager creation.
-rw-r--r--nova/auth/manager.py24
-rw-r--r--nova/utils.py10
2 files changed, 20 insertions, 14 deletions
diff --git a/nova/auth/manager.py b/nova/auth/manager.py
index 7307f673b..2da53a736 100644
--- a/nova/auth/manager.py
+++ b/nova/auth/manager.py
@@ -323,25 +323,21 @@ class AuthManager(object):
"""
_instance=None
def __new__(cls, *args, **kwargs):
- """Returns the AuthManager singleton with driver set
-
- __init__ is run every time AuthManager() is called, so we need to do
- any constructor related stuff here. The driver that is specified
- in the flagfile is loaded here.
- """
+ """Returns the AuthManager singleton"""
if not cls._instance:
cls._instance = super(AuthManager, cls).__new__(
cls, *args, **kwargs)
- mod_str, sep, driver_str = FLAGS.auth_driver.rpartition('.')
- try:
- __import__(mod_str)
- cls._instance.driver = getattr(sys.modules[mod_str],
- driver_str)
- except (ImportError, AttributeError):
- raise exception.Error('Auth driver %s cannot be found'
- % FLAGS.auth_driver)
return cls._instance
+ def __init__(self, driver=None, *args, **kwargs):
+ """Inits the driver from parameter or flag
+
+ __init__ is run every time AuthManager() is called, so we only
+ reset the driver if it is not set or a new driver is specified.
+ """
+ if driver or not getattr(self, 'driver', None):
+ self.driver = utils.import_class(driver or FLAGS.auth_driver)
+
def authenticate(self, access, signature, params, verb='GET',
server_string='127.0.0.1:8773', path='/',
check_type='ec2', headers=None):
diff --git a/nova/utils.py b/nova/utils.py
index a1eb0a092..0016b656e 100644
--- a/nova/utils.py
+++ b/nova/utils.py
@@ -29,11 +29,21 @@ import subprocess
import socket
import sys
+from nova import exception
from nova import flags
FLAGS = flags.FLAGS
TIME_FORMAT = "%Y-%m-%dT%H:%M:%SZ"
+def import_class(import_str):
+ """Returns a class from a string including module and class"""
+ mod_str, _sep, class_str = import_str.rpartition('.')
+ try:
+ __import__(mod_str)
+ return getattr(sys.modules[mod_str], class_str)
+ except (ImportError, AttributeError):
+ raise exception.NotFound('Class %s cannot be found' % class_str)
+
def fetchfile(url, target):
logging.debug("Fetching %s" % url)
# c = pycurl.Curl()