From 0af6afb76f7b946df5d1de826727c317c4554a27 Mon Sep 17 00:00:00 2001 From: Michael Basnight Date: Mon, 26 Mar 2012 15:39:16 -0500 Subject: [PATCH] Adding list_users for mysql users * Added MVC for mysql users * Hooked up the MVC to the guest * Fixed a dual import bug in dbaas.py --- .gitignore | 1 + reddwarf/extensions/mysql.py | 53 ++++----------------------- reddwarf/extensions/mysql/__init__.py | 16 ++++++++ reddwarf/extensions/mysql/models.py | 47 ++++++++++++++++++++++++ reddwarf/extensions/mysql/service.py | 50 +++++++++++++++++++++++++ reddwarf/extensions/mysql/views.py | 43 ++++++++++++++++++++++ reddwarf/guestagent/dbaas.py | 1 - 7 files changed, 165 insertions(+), 46 deletions(-) create mode 100644 reddwarf/extensions/mysql/__init__.py create mode 100644 reddwarf/extensions/mysql/models.py create mode 100644 reddwarf/extensions/mysql/service.py create mode 100644 reddwarf/extensions/mysql/views.py diff --git a/.gitignore b/.gitignore index ef9a631192..7f3880bdd4 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,4 @@ reddwarf/vcsversion.py covhtml/ .DS_Store host-syslog.log +tags diff --git a/reddwarf/extensions/mysql.py b/reddwarf/extensions/mysql.py index 413f0729e0..2158ee8ec2 100644 --- a/reddwarf/extensions/mysql.py +++ b/reddwarf/extensions/mysql.py @@ -17,50 +17,11 @@ import logging -from novaclient.v1_1.client import Client -from reddwarf.common import config from reddwarf.common import extensions +from reddwarf.extensions.mysql import service -CONFIG = config.Config -LOG = logging.getLogger('reddwarf.extensions.mysql') - - -class BaseController(object): - """Base controller class.""" - - def __init__(self): - self.proxy_admin_user = CONFIG.get('reddwarf_proxy_admin_user', - 'admin') - self.proxy_admin_pass = CONFIG.get('reddwarf_proxy_admin_pass', - '3de4922d8b6ac5a1aad9') - self.proxy_admin_tenant_name = CONFIG.get( - 'reddwarf_proxy_admin_tenant_name', 'admin') - self.auth_url = CONFIG.get('reddwarf_auth_url', - 'http://0.0.0.0:5000/v2.0') - - def get_client(self, req): - proxy_token = req.headers["X-Auth-Token"] - client = Client(self.proxy_admin_user, self.proxy_admin_pass, - self.proxy_admin_tenant_name, self.auth_url, token=proxy_token) - client.authenticate() - return client - - -class UserController(BaseController): - """Controller for instance functionality""" - - def index(self, req, tenant_id): - """Return all users.""" - return "User List" - - -class SchemaController(BaseController): - """Controller for instance functionality""" - - def index(self, req, tenant_id): - """Return all schemas.""" - return "Schema list" +LOG = logging.getLogger(__name__) class Mysql(extensions.ExtensionsDescriptor): @@ -82,11 +43,13 @@ class Mysql(extensions.ExtensionsDescriptor): def get_resources(self): resources = [] - resource = extensions.ResourceExtension('{tenant_id}/schemas', - SchemaController()) + resource = extensions.ResourceExtension( + '{tenant_id}/schemas/{instance_id}', + service.SchemaController()) resources.append(resource) - resource = extensions.ResourceExtension('{tenant_id}/users', - UserController()) + resource = extensions.ResourceExtension( + '{tenant_id}/users/{instance_id}', + service.UserController()) resources.append(resource) return resources diff --git a/reddwarf/extensions/mysql/__init__.py b/reddwarf/extensions/mysql/__init__.py new file mode 100644 index 0000000000..d65c689a83 --- /dev/null +++ b/reddwarf/extensions/mysql/__init__.py @@ -0,0 +1,16 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +# Copyright 2011 OpenStack LLC. +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. diff --git a/reddwarf/extensions/mysql/models.py b/reddwarf/extensions/mysql/models.py new file mode 100644 index 0000000000..fc520ab121 --- /dev/null +++ b/reddwarf/extensions/mysql/models.py @@ -0,0 +1,47 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +# Copyright 2010-2011 OpenStack LLC. +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http: //www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +"""Model classes that form the core of instances functionality.""" + +import logging + +from reddwarf import db + +from reddwarf.common import config +from reddwarf.guestagent import api as guest_api + +CONFIG = config.Config +LOG = logging.getLogger(__name__) + + +class User(object): + + _data_fields = ['name', 'password', 'databases'] + + def __init__(self, name, password, databases): + self.name = name + self.password = password + self.databases = databases + + +class Users(object): + + @classmethod + def load(cls, context, instance_id): + user_list = guest_api.API().list_users(context, instance_id) + return [User(user['_name'], user['_password'], user['_databases']) + for user in user_list] diff --git a/reddwarf/extensions/mysql/service.py b/reddwarf/extensions/mysql/service.py new file mode 100644 index 0000000000..cf6210b645 --- /dev/null +++ b/reddwarf/extensions/mysql/service.py @@ -0,0 +1,50 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +# Copyright 2011 OpenStack LLC. +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +import logging + +from reddwarf.common import context as rd_context +from reddwarf.common import wsgi +from reddwarf.extensions.mysql import models +from reddwarf.extensions.mysql import views + +LOG = logging.getLogger(__name__) + + +class BaseController(wsgi.Controller): + """Base controller class.""" + + +class UserController(BaseController): + """Controller for instance functionality""" + + def index(self, req, tenant_id, instance_id): + """Return all users.""" + context = rd_context.ReddwarfContext( + auth_tok=req.headers["X-Auth-Token"], + tenant=tenant_id) + users = models.Users.load(context, instance_id) + # Not exactly sure why we cant return a wsgi.Result() here + return views.UsersView(users).data() + + +class SchemaController(BaseController): + """Controller for instance functionality""" + + def index(self, req, tenant_id): + """Return all schemas.""" + return "Schema list" diff --git a/reddwarf/extensions/mysql/views.py b/reddwarf/extensions/mysql/views.py new file mode 100644 index 0000000000..5ff7096dd3 --- /dev/null +++ b/reddwarf/extensions/mysql/views.py @@ -0,0 +1,43 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +# Copyright 2011 OpenStack LLC. +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + + +class UserView(object): + + def __init__(self, user): + self.user = user + + def data(self): + user_dict = { + "name": self.user.name, + "databases": self.user.databases + } + return {"users": user_dict} + + +class UsersView(object): + + def __init__(self, users): + self.users = users + + def data(self): + data = [] + # These are model instances + for user in self.users: + data.append(UserView(user).data()) + + return data diff --git a/reddwarf/guestagent/dbaas.py b/reddwarf/guestagent/dbaas.py index 145d5bb96a..37eb6f5171 100644 --- a/reddwarf/guestagent/dbaas.py +++ b/reddwarf/guestagent/dbaas.py @@ -43,7 +43,6 @@ from reddwarf.common.exception import ProcessExecutionError from reddwarf.common import config from reddwarf.common import utils from reddwarf.guestagent.db import models -from reddwarf.instance import models ADMIN_USER_NAME = "os_admin" LOG = logging.getLogger(__name__)