Finish singletonizing UserManager usage.
This commit is contained in:
@@ -43,13 +43,11 @@ FLAGS = flags.FLAGS
|
||||
|
||||
|
||||
def main(_argv):
|
||||
user_manager = users.UserManager()
|
||||
host_manager = model.Host
|
||||
controllers = {
|
||||
'Cloud': cloud.CloudController(),
|
||||
'Admin': admin.AdminController(user_manager, host_manager)
|
||||
'Admin': admin.AdminController()
|
||||
}
|
||||
_app = api.APIServerApplication(user_manager, controllers)
|
||||
_app = api.APIServerApplication(controllers)
|
||||
|
||||
conn = rpc.Connection.instance()
|
||||
consumer = rpc.AdapterConsumer(connection=conn,
|
||||
|
@@ -24,6 +24,9 @@ Admin API controller, exposed through http via the api worker.
|
||||
|
||||
import base64
|
||||
|
||||
from nova.auth import users
|
||||
from nova.compute import model
|
||||
|
||||
def user_dict(user, base64_file=None):
|
||||
"""Convert the user object to a result dict"""
|
||||
if user:
|
||||
@@ -62,28 +65,24 @@ class AdminController(object):
|
||||
allowing project managers to administer project users.
|
||||
"""
|
||||
|
||||
def __init__(self, user_manager, host_manager):
|
||||
self.user_manager = user_manager
|
||||
self.host_manager = host_manager
|
||||
|
||||
def __str__(self):
|
||||
return 'AdminController'
|
||||
|
||||
@admin_only
|
||||
def describe_user(self, _context, name, **_kwargs):
|
||||
"""Returns user data, including access and secret keys."""
|
||||
return user_dict(self.user_manager.get_user(name))
|
||||
return user_dict(users.UserManager.instance().get_user(name))
|
||||
|
||||
@admin_only
|
||||
def describe_users(self, _context, **_kwargs):
|
||||
"""Returns all users - should be changed to deal with a list."""
|
||||
return {'userSet':
|
||||
[user_dict(u) for u in self.user_manager.get_users()] }
|
||||
[user_dict(u) for u in users.UserManager.instance().get_users()] }
|
||||
|
||||
@admin_only
|
||||
def register_user(self, _context, name, **_kwargs):
|
||||
"""Creates a new user, and returns generated credentials."""
|
||||
return user_dict(self.user_manager.create_user(name))
|
||||
return user_dict(users.UserManager.instance().create_user(name))
|
||||
|
||||
@admin_only
|
||||
def deregister_user(self, _context, name, **_kwargs):
|
||||
@@ -91,7 +90,7 @@ class AdminController(object):
|
||||
Should throw an exception if the user has instances,
|
||||
volumes, or buckets remaining.
|
||||
"""
|
||||
self.user_manager.delete_user(name)
|
||||
users.UserManager.instance().delete_user(name)
|
||||
|
||||
return True
|
||||
|
||||
@@ -103,8 +102,8 @@ class AdminController(object):
|
||||
"""
|
||||
if project is None:
|
||||
project = name
|
||||
project = self.user_manager.get_project(project)
|
||||
user = self.user_manager.get_user(name)
|
||||
project = users.UserManager.instance().get_project(project)
|
||||
user = users.UserManager.instance().get_user(name)
|
||||
return user_dict(user, base64.b64encode(project.get_credentials(user)))
|
||||
|
||||
@admin_only
|
||||
@@ -117,9 +116,9 @@ class AdminController(object):
|
||||
* DHCP servers running
|
||||
* Iptables / bridges
|
||||
"""
|
||||
return {'hostSet': [host_dict(h) for h in self.host_manager.all()]}
|
||||
return {'hostSet': [host_dict(h) for h in model.Host.all()]}
|
||||
|
||||
@admin_only
|
||||
def describe_host(self, _context, name, **_kwargs):
|
||||
"""Returns status info for single node."""
|
||||
return host_dict(self.host_manager.lookup(name))
|
||||
return host_dict(model.Host.lookup(name))
|
||||
|
@@ -324,7 +324,7 @@ class APIRequestHandler(tornado.web.RequestHandler):
|
||||
|
||||
|
||||
class APIServerApplication(tornado.web.Application):
|
||||
def __init__(self, user_manager, controllers):
|
||||
def __init__(self, controllers):
|
||||
tornado.web.Application.__init__(self, [
|
||||
(r'/', RootRequestHandler),
|
||||
(r'/cloudpipe/(.*)', nova.cloudpipe.api.CloudPipeRequestHandler),
|
||||
@@ -341,5 +341,4 @@ class APIServerApplication(tornado.web.Application):
|
||||
(r'/2007-01-19/([-A-Za-z0-9/]*)', MetadataRequestHandler),
|
||||
(r'/1.0/([-A-Za-z0-9/]*)', MetadataRequestHandler),
|
||||
], pool=multiprocessing.Pool(4))
|
||||
self.user_manager = user_manager
|
||||
self.controllers = controllers
|
||||
|
@@ -159,7 +159,7 @@ class ApiEc2TestCase(test.BaseTestCase):
|
||||
|
||||
self.host = '127.0.0.1'
|
||||
|
||||
self.app = api.APIServerApplication(self.users, {'Cloud': self.cloud})
|
||||
self.app = api.APIServerApplication({'Cloud': self.cloud})
|
||||
self.ec2 = boto.connect_ec2(
|
||||
aws_access_key_id='fake',
|
||||
aws_secret_access_key='fake',
|
||||
|
@@ -42,5 +42,4 @@ class ValidationTestCase(test.TrialTestCase):
|
||||
|
||||
@validate.typetest(instanceid=str, size=int, number_of_instances=int)
|
||||
def type_case(instanceid, size, number_of_instances):
|
||||
print ("type_case was successfully executed")
|
||||
return True
|
||||
return True
|
||||
|
Reference in New Issue
Block a user