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
This commit is contained in:
parent
50687b9678
commit
0af6afb76f
1
.gitignore
vendored
1
.gitignore
vendored
@ -12,3 +12,4 @@ reddwarf/vcsversion.py
|
|||||||
covhtml/
|
covhtml/
|
||||||
.DS_Store
|
.DS_Store
|
||||||
host-syslog.log
|
host-syslog.log
|
||||||
|
tags
|
||||||
|
@ -17,50 +17,11 @@
|
|||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from novaclient.v1_1.client import Client
|
|
||||||
from reddwarf.common import config
|
|
||||||
from reddwarf.common import extensions
|
from reddwarf.common import extensions
|
||||||
|
from reddwarf.extensions.mysql import service
|
||||||
|
|
||||||
|
|
||||||
CONFIG = config.Config
|
LOG = logging.getLogger(__name__)
|
||||||
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"
|
|
||||||
|
|
||||||
|
|
||||||
class Mysql(extensions.ExtensionsDescriptor):
|
class Mysql(extensions.ExtensionsDescriptor):
|
||||||
@ -82,11 +43,13 @@ class Mysql(extensions.ExtensionsDescriptor):
|
|||||||
|
|
||||||
def get_resources(self):
|
def get_resources(self):
|
||||||
resources = []
|
resources = []
|
||||||
resource = extensions.ResourceExtension('{tenant_id}/schemas',
|
resource = extensions.ResourceExtension(
|
||||||
SchemaController())
|
'{tenant_id}/schemas/{instance_id}',
|
||||||
|
service.SchemaController())
|
||||||
resources.append(resource)
|
resources.append(resource)
|
||||||
resource = extensions.ResourceExtension('{tenant_id}/users',
|
resource = extensions.ResourceExtension(
|
||||||
UserController())
|
'{tenant_id}/users/{instance_id}',
|
||||||
|
service.UserController())
|
||||||
resources.append(resource)
|
resources.append(resource)
|
||||||
|
|
||||||
return resources
|
return resources
|
||||||
|
16
reddwarf/extensions/mysql/__init__.py
Normal file
16
reddwarf/extensions/mysql/__init__.py
Normal file
@ -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.
|
47
reddwarf/extensions/mysql/models.py
Normal file
47
reddwarf/extensions/mysql/models.py
Normal file
@ -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]
|
50
reddwarf/extensions/mysql/service.py
Normal file
50
reddwarf/extensions/mysql/service.py
Normal file
@ -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"
|
43
reddwarf/extensions/mysql/views.py
Normal file
43
reddwarf/extensions/mysql/views.py
Normal file
@ -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
|
@ -43,7 +43,6 @@ from reddwarf.common.exception import ProcessExecutionError
|
|||||||
from reddwarf.common import config
|
from reddwarf.common import config
|
||||||
from reddwarf.common import utils
|
from reddwarf.common import utils
|
||||||
from reddwarf.guestagent.db import models
|
from reddwarf.guestagent.db import models
|
||||||
from reddwarf.instance import models
|
|
||||||
|
|
||||||
ADMIN_USER_NAME = "os_admin"
|
ADMIN_USER_NAME = "os_admin"
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user