Fixing the mysql list calls
* Became compliant with the new guest api code * Fixed a small guest api bug * Fixed the views to return the proper data * Added databases in list_users * Fixed the issue with bad nova data * Misc pep8 fixes
This commit is contained in:
parent
10433a88c7
commit
feb567f647
@ -65,4 +65,3 @@ if CONFIG.get("remote_implementation", "real") == "fake":
|
||||
|
||||
def create_nova_client(context):
|
||||
return fake_create_nova_client(context)
|
||||
|
||||
|
@ -25,7 +25,7 @@ from reddwarf.common import config
|
||||
from reddwarf.common import exception
|
||||
from reddwarf.instance import models as base_models
|
||||
from reddwarf.guestagent.db import models as guest_models
|
||||
from reddwarf.guestagent import api as guest_api
|
||||
from reddwarf.common.remote import create_guest_client
|
||||
|
||||
CONFIG = config.Config
|
||||
LOG = logging.getLogger(__name__)
|
||||
@ -90,12 +90,12 @@ class User(object):
|
||||
def create(cls, context, instance_id, users):
|
||||
# Load InstanceServiceStatus to verify if its running
|
||||
load_and_verify(context, instance_id)
|
||||
guest_api.API().create_user(context, instance_id, users)
|
||||
create_guest_client(context, instance_id).create_user(users)
|
||||
|
||||
@classmethod
|
||||
def delete(cls, context, instance_id, username):
|
||||
load_and_verify(context, instance_id)
|
||||
guest_api.API().delete_user(context, instance_id, username)
|
||||
create_guest_client(context, instance_id).delete_user(username)
|
||||
|
||||
|
||||
class Root(object):
|
||||
@ -103,12 +103,12 @@ class Root(object):
|
||||
@classmethod
|
||||
def load(cls, context, instance_id):
|
||||
load_and_verify(context, instance_id)
|
||||
return guest_api.API().is_root_enabled(context, instance_id)
|
||||
return create_guest_client(context, instance_id).is_root_enabled()
|
||||
|
||||
@classmethod
|
||||
def create(cls, context, instance_id):
|
||||
load_and_verify(context, instance_id)
|
||||
root = guest_api.API().enable_root(context, instance_id)
|
||||
root = create_guest_client(context, instance_id).enable_root()
|
||||
root_user = guest_models.MySQLUser()
|
||||
root_user.deserialize(root)
|
||||
return root_user
|
||||
@ -119,7 +119,7 @@ class Users(object):
|
||||
@classmethod
|
||||
def load(cls, context, instance_id):
|
||||
load_and_verify(context, instance_id)
|
||||
user_list = guest_api.API().list_users(context, instance_id)
|
||||
user_list = create_guest_client(context, instance_id).list_users()
|
||||
model_users = []
|
||||
for user in user_list:
|
||||
mysql_user = guest_models.MySQLUser()
|
||||
@ -147,12 +147,12 @@ class Schema(object):
|
||||
@classmethod
|
||||
def create(cls, context, instance_id, schemas):
|
||||
load_and_verify(context, instance_id)
|
||||
guest_api.API().create_database(context, instance_id, schemas)
|
||||
create_guest_client(context, instance_id).create_database(schemas)
|
||||
|
||||
@classmethod
|
||||
def delete(cls, context, instance_id, schema):
|
||||
load_and_verify(context, instance_id)
|
||||
guest_api.API().delete_database(context, instance_id, schema)
|
||||
create_guest_client(context, instance_id).delete_database(schema)
|
||||
|
||||
|
||||
class Schemas(object):
|
||||
@ -160,9 +160,9 @@ class Schemas(object):
|
||||
@classmethod
|
||||
def load(cls, context, instance_id):
|
||||
load_and_verify(context, instance_id)
|
||||
schema_list = guest_api.API().list_databases(context, instance_id)
|
||||
schemas = create_guest_client(context, instance_id).list_databases()
|
||||
model_schemas = []
|
||||
for schema in schema_list:
|
||||
for schema in schemas:
|
||||
mysql_schema = guest_models.MySQLDatabase()
|
||||
mysql_schema.deserialize(schema)
|
||||
model_schemas.append(Schema(mysql_schema.name,
|
||||
|
@ -26,7 +26,7 @@ class UserView(object):
|
||||
"name": self.user.name,
|
||||
"databases": self.user.databases
|
||||
}
|
||||
return {"users": user_dict}
|
||||
return user_dict
|
||||
|
||||
|
||||
class UsersView(object):
|
||||
@ -40,7 +40,7 @@ class UsersView(object):
|
||||
for user in self.users:
|
||||
data.append(UserView(user).data())
|
||||
|
||||
return data
|
||||
return {"users": data}
|
||||
|
||||
|
||||
class RootCreatedView(UserView):
|
||||
@ -68,12 +68,7 @@ class SchemaView(object):
|
||||
self.schema = schema
|
||||
|
||||
def data(self):
|
||||
schema_dict = {
|
||||
"name": self.schema.name,
|
||||
"collate": self.schema.collate,
|
||||
"character_set": self.schema.character_set
|
||||
}
|
||||
return {"databases": schema_dict}
|
||||
return {"name": self.schema.name}
|
||||
|
||||
|
||||
class SchemasView(object):
|
||||
@ -87,4 +82,4 @@ class SchemasView(object):
|
||||
for schema in self.schemas:
|
||||
data.append(SchemaView(schema).data())
|
||||
|
||||
return data
|
||||
return {"databases": data}
|
||||
|
@ -14,4 +14,3 @@
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
|
@ -77,4 +77,3 @@ class Flavors(NovaRemoteModelBase):
|
||||
def __iter__(self):
|
||||
for item in self.flavors:
|
||||
yield item
|
||||
|
||||
|
@ -73,6 +73,7 @@ class FlavorController(BaseController):
|
||||
flavors = models.Flavors(context=context)
|
||||
return wsgi.Result(views.FlavorsView(flavors, req).data(), 200)
|
||||
|
||||
|
||||
class API(wsgi.Router):
|
||||
"""API"""
|
||||
def __init__(self):
|
||||
|
@ -15,6 +15,7 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
|
||||
class FlavorView(object):
|
||||
|
||||
def __init__(self, flavor, req=None):
|
||||
|
@ -53,7 +53,7 @@ class API(object):
|
||||
def list_users(self):
|
||||
"""Make an asynchronous call to list database users"""
|
||||
LOG.debug("Listing Users for Instance %s", self.id)
|
||||
return rpc.call(context, self._get_routing_key(),
|
||||
return rpc.call(self.context, self._get_routing_key(),
|
||||
{"method": "list_users"})
|
||||
|
||||
def delete_user(self, user):
|
||||
|
@ -137,6 +137,18 @@ class DBaaSAgent(object):
|
||||
LOG.debug("user = " + str(row))
|
||||
mysql_user = models.MySQLUser()
|
||||
mysql_user.name = row['User']
|
||||
# Now get the databases
|
||||
t = text("""SELECT grantee, table_schema
|
||||
from information_schema.SCHEMA_PRIVILEGES
|
||||
group by grantee, table_schema;""")
|
||||
db_result = client.execute(t)
|
||||
for db in db_result:
|
||||
matches = re.match("^'(.+)'@", db['grantee'])
|
||||
if matches is not None and \
|
||||
matches.group(1) == mysql_user.name:
|
||||
mysql_db = models.MySQLDatabase()
|
||||
mysql_db.name = db['table_schema']
|
||||
mysql_user.databases.append(mysql_db.serialize())
|
||||
users.append(mysql_user.serialize())
|
||||
LOG.debug("users = " + str(users))
|
||||
return users
|
||||
|
@ -250,7 +250,18 @@ class Instances(object):
|
||||
find_server = create_server_list_matcher(servers)
|
||||
for db in db_infos:
|
||||
status = InstanceServiceStatus.find_by(instance_id=db.id)
|
||||
try:
|
||||
# TODO(hub-cap): Figure out if this is actually correct.
|
||||
# We are not sure if we should be doing some validation.
|
||||
# Basically if the server find returns nothing, but we
|
||||
# have something, there is a mismatch between what the
|
||||
# nova db has compared to what we have. We should have
|
||||
# a way to handle this.
|
||||
server = find_server(db.id, db.compute_instance_id)
|
||||
except rd_exceptions.ComputeInstanceNotFound:
|
||||
LOG.info(_("Could not find server %s") %
|
||||
db.compute_instance_id)
|
||||
continue
|
||||
ret.append(Instance(context, db, server, status))
|
||||
return ret
|
||||
|
||||
|
@ -266,7 +266,8 @@ class API(wsgi.Router):
|
||||
mapper = routes.Mapper()
|
||||
super(API, self).__init__(mapper)
|
||||
self._instance_router(mapper)
|
||||
self._flavor_router(mapper) #TODO(ed-): Remove after restructure
|
||||
# TODO(ed-): Remove after restructure
|
||||
self._flavor_router(mapper)
|
||||
|
||||
def _instance_router(self, mapper):
|
||||
instance_resource = InstanceController().create_resource()
|
||||
@ -274,7 +275,8 @@ class API(wsgi.Router):
|
||||
mapper.resource("instance", path, controller=instance_resource,
|
||||
collection={'detail': 'GET'})
|
||||
|
||||
#TODO(ed-): remove this when all mention of flavorservice et cetera are moved away
|
||||
# TODO(ed-): remove this when all mention of flavorservice
|
||||
# et cetera are moved away
|
||||
def _flavor_router(self, mapper):
|
||||
flavor_resource = flavorservice.FlavorController().create_resource()
|
||||
path = "/{tenant_id}/flavors"
|
||||
|
@ -33,6 +33,7 @@ class FakeGuest(object):
|
||||
def prepare(self, memory_mb, databases):
|
||||
from reddwarf.instance.models import InstanceServiceStatus
|
||||
from reddwarf.instance.models import ServiceStatuses
|
||||
|
||||
def update_db():
|
||||
status = InstanceServiceStatus.find_by(instance_id=self.id)
|
||||
status.status = ServiceStatuses.RUNNING
|
||||
|
@ -46,7 +46,8 @@ class FakeFlavor(object):
|
||||
return "flavors/%s" % self.id
|
||||
|
||||
def to_dict(self):
|
||||
return {"id":self.id, "links":self.links}
|
||||
return {"id": self.id, "links": self.links}
|
||||
|
||||
|
||||
class FakeFlavors(object):
|
||||
|
||||
@ -76,6 +77,7 @@ class FakeFlavors(object):
|
||||
return value
|
||||
raise nova_exceptions.NotFound(404, "Flavor href not found %s" % href)
|
||||
|
||||
|
||||
class FakeServer(object):
|
||||
|
||||
def __init__(self, parent, id, name, image_id, flavor_ref):
|
||||
@ -131,7 +133,7 @@ class FakeServers(object):
|
||||
def __init__(self, flavors):
|
||||
self.db = {}
|
||||
self.flavors = flavors
|
||||
self.next_id = 10;
|
||||
self.next_id = 10
|
||||
self.events = EventSimulator()
|
||||
|
||||
def create(self, name, image_id, flavor_ref, files):
|
||||
|
Loading…
Reference in New Issue
Block a user