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):
|
def create_nova_client(context):
|
||||||
return fake_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.common import exception
|
||||||
from reddwarf.instance import models as base_models
|
from reddwarf.instance import models as base_models
|
||||||
from reddwarf.guestagent.db import models as guest_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
|
CONFIG = config.Config
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
@ -90,12 +90,12 @@ class User(object):
|
|||||||
def create(cls, context, instance_id, users):
|
def create(cls, context, instance_id, users):
|
||||||
# Load InstanceServiceStatus to verify if its running
|
# Load InstanceServiceStatus to verify if its running
|
||||||
load_and_verify(context, instance_id)
|
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
|
@classmethod
|
||||||
def delete(cls, context, instance_id, username):
|
def delete(cls, context, instance_id, username):
|
||||||
load_and_verify(context, instance_id)
|
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):
|
class Root(object):
|
||||||
@ -103,12 +103,12 @@ class Root(object):
|
|||||||
@classmethod
|
@classmethod
|
||||||
def load(cls, context, instance_id):
|
def load(cls, context, instance_id):
|
||||||
load_and_verify(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
|
@classmethod
|
||||||
def create(cls, context, instance_id):
|
def create(cls, context, instance_id):
|
||||||
load_and_verify(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 = guest_models.MySQLUser()
|
||||||
root_user.deserialize(root)
|
root_user.deserialize(root)
|
||||||
return root_user
|
return root_user
|
||||||
@ -119,7 +119,7 @@ class Users(object):
|
|||||||
@classmethod
|
@classmethod
|
||||||
def load(cls, context, instance_id):
|
def load(cls, context, instance_id):
|
||||||
load_and_verify(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 = []
|
model_users = []
|
||||||
for user in user_list:
|
for user in user_list:
|
||||||
mysql_user = guest_models.MySQLUser()
|
mysql_user = guest_models.MySQLUser()
|
||||||
@ -147,12 +147,12 @@ class Schema(object):
|
|||||||
@classmethod
|
@classmethod
|
||||||
def create(cls, context, instance_id, schemas):
|
def create(cls, context, instance_id, schemas):
|
||||||
load_and_verify(context, instance_id)
|
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
|
@classmethod
|
||||||
def delete(cls, context, instance_id, schema):
|
def delete(cls, context, instance_id, schema):
|
||||||
load_and_verify(context, instance_id)
|
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):
|
class Schemas(object):
|
||||||
@ -160,9 +160,9 @@ class Schemas(object):
|
|||||||
@classmethod
|
@classmethod
|
||||||
def load(cls, context, instance_id):
|
def load(cls, context, instance_id):
|
||||||
load_and_verify(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 = []
|
model_schemas = []
|
||||||
for schema in schema_list:
|
for schema in schemas:
|
||||||
mysql_schema = guest_models.MySQLDatabase()
|
mysql_schema = guest_models.MySQLDatabase()
|
||||||
mysql_schema.deserialize(schema)
|
mysql_schema.deserialize(schema)
|
||||||
model_schemas.append(Schema(mysql_schema.name,
|
model_schemas.append(Schema(mysql_schema.name,
|
||||||
|
@ -26,7 +26,7 @@ class UserView(object):
|
|||||||
"name": self.user.name,
|
"name": self.user.name,
|
||||||
"databases": self.user.databases
|
"databases": self.user.databases
|
||||||
}
|
}
|
||||||
return {"users": user_dict}
|
return user_dict
|
||||||
|
|
||||||
|
|
||||||
class UsersView(object):
|
class UsersView(object):
|
||||||
@ -40,7 +40,7 @@ class UsersView(object):
|
|||||||
for user in self.users:
|
for user in self.users:
|
||||||
data.append(UserView(user).data())
|
data.append(UserView(user).data())
|
||||||
|
|
||||||
return data
|
return {"users": data}
|
||||||
|
|
||||||
|
|
||||||
class RootCreatedView(UserView):
|
class RootCreatedView(UserView):
|
||||||
@ -68,12 +68,7 @@ class SchemaView(object):
|
|||||||
self.schema = schema
|
self.schema = schema
|
||||||
|
|
||||||
def data(self):
|
def data(self):
|
||||||
schema_dict = {
|
return {"name": self.schema.name}
|
||||||
"name": self.schema.name,
|
|
||||||
"collate": self.schema.collate,
|
|
||||||
"character_set": self.schema.character_set
|
|
||||||
}
|
|
||||||
return {"databases": schema_dict}
|
|
||||||
|
|
||||||
|
|
||||||
class SchemasView(object):
|
class SchemasView(object):
|
||||||
@ -87,4 +82,4 @@ class SchemasView(object):
|
|||||||
for schema in self.schemas:
|
for schema in self.schemas:
|
||||||
data.append(SchemaView(schema).data())
|
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
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
@ -77,4 +77,3 @@ class Flavors(NovaRemoteModelBase):
|
|||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
for item in self.flavors:
|
for item in self.flavors:
|
||||||
yield item
|
yield item
|
||||||
|
|
||||||
|
@ -73,6 +73,7 @@ class FlavorController(BaseController):
|
|||||||
flavors = models.Flavors(context=context)
|
flavors = models.Flavors(context=context)
|
||||||
return wsgi.Result(views.FlavorsView(flavors, req).data(), 200)
|
return wsgi.Result(views.FlavorsView(flavors, req).data(), 200)
|
||||||
|
|
||||||
|
|
||||||
class API(wsgi.Router):
|
class API(wsgi.Router):
|
||||||
"""API"""
|
"""API"""
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
|
||||||
class FlavorView(object):
|
class FlavorView(object):
|
||||||
|
|
||||||
def __init__(self, flavor, req=None):
|
def __init__(self, flavor, req=None):
|
||||||
@ -31,7 +32,7 @@ class FlavorView(object):
|
|||||||
def _build_links(self):
|
def _build_links(self):
|
||||||
result = []
|
result = []
|
||||||
#scheme = self.req.scheme
|
#scheme = self.req.scheme
|
||||||
scheme = 'https' # Forcing https
|
scheme = 'https' # Forcing https
|
||||||
endpoint = self.req.host
|
endpoint = self.req.host
|
||||||
splitpath = self.req.path.split('/')
|
splitpath = self.req.path.split('/')
|
||||||
detailed = ''
|
detailed = ''
|
||||||
@ -49,8 +50,8 @@ class FlavorView(object):
|
|||||||
path = '/'.join(splitpath)
|
path = '/'.join(splitpath)
|
||||||
href = href_template % locals()
|
href = href_template % locals()
|
||||||
elif rlink['rel'] == 'bookmark':
|
elif rlink['rel'] == 'bookmark':
|
||||||
splitpath.pop(2) # Remove the version.
|
splitpath.pop(2) # Remove the version.
|
||||||
splitpath.pop(1) # Remove the tenant id.
|
splitpath.pop(1) # Remove the tenant id.
|
||||||
path = '/'.join(splitpath)
|
path = '/'.join(splitpath)
|
||||||
href = href_template % locals()
|
href = href_template % locals()
|
||||||
|
|
||||||
|
@ -53,7 +53,7 @@ class API(object):
|
|||||||
def list_users(self):
|
def list_users(self):
|
||||||
"""Make an asynchronous call to list database users"""
|
"""Make an asynchronous call to list database users"""
|
||||||
LOG.debug("Listing Users for Instance %s", self.id)
|
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"})
|
{"method": "list_users"})
|
||||||
|
|
||||||
def delete_user(self, user):
|
def delete_user(self, user):
|
||||||
|
@ -137,6 +137,18 @@ class DBaaSAgent(object):
|
|||||||
LOG.debug("user = " + str(row))
|
LOG.debug("user = " + str(row))
|
||||||
mysql_user = models.MySQLUser()
|
mysql_user = models.MySQLUser()
|
||||||
mysql_user.name = row['User']
|
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())
|
users.append(mysql_user.serialize())
|
||||||
LOG.debug("users = " + str(users))
|
LOG.debug("users = " + str(users))
|
||||||
return users
|
return users
|
||||||
|
@ -250,7 +250,18 @@ class Instances(object):
|
|||||||
find_server = create_server_list_matcher(servers)
|
find_server = create_server_list_matcher(servers)
|
||||||
for db in db_infos:
|
for db in db_infos:
|
||||||
status = InstanceServiceStatus.find_by(instance_id=db.id)
|
status = InstanceServiceStatus.find_by(instance_id=db.id)
|
||||||
server = find_server(db.id, db.compute_instance_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))
|
ret.append(Instance(context, db, server, status))
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
@ -266,7 +266,8 @@ class API(wsgi.Router):
|
|||||||
mapper = routes.Mapper()
|
mapper = routes.Mapper()
|
||||||
super(API, self).__init__(mapper)
|
super(API, self).__init__(mapper)
|
||||||
self._instance_router(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):
|
def _instance_router(self, mapper):
|
||||||
instance_resource = InstanceController().create_resource()
|
instance_resource = InstanceController().create_resource()
|
||||||
@ -274,7 +275,8 @@ class API(wsgi.Router):
|
|||||||
mapper.resource("instance", path, controller=instance_resource,
|
mapper.resource("instance", path, controller=instance_resource,
|
||||||
collection={'detail': 'GET'})
|
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):
|
def _flavor_router(self, mapper):
|
||||||
flavor_resource = flavorservice.FlavorController().create_resource()
|
flavor_resource = flavorservice.FlavorController().create_resource()
|
||||||
path = "/{tenant_id}/flavors"
|
path = "/{tenant_id}/flavors"
|
||||||
|
@ -33,6 +33,7 @@ class FakeGuest(object):
|
|||||||
def prepare(self, memory_mb, databases):
|
def prepare(self, memory_mb, databases):
|
||||||
from reddwarf.instance.models import InstanceServiceStatus
|
from reddwarf.instance.models import InstanceServiceStatus
|
||||||
from reddwarf.instance.models import ServiceStatuses
|
from reddwarf.instance.models import ServiceStatuses
|
||||||
|
|
||||||
def update_db():
|
def update_db():
|
||||||
status = InstanceServiceStatus.find_by(instance_id=self.id)
|
status = InstanceServiceStatus.find_by(instance_id=self.id)
|
||||||
status.status = ServiceStatuses.RUNNING
|
status.status = ServiceStatuses.RUNNING
|
||||||
|
@ -46,7 +46,8 @@ class FakeFlavor(object):
|
|||||||
return "flavors/%s" % self.id
|
return "flavors/%s" % self.id
|
||||||
|
|
||||||
def to_dict(self):
|
def to_dict(self):
|
||||||
return {"id":self.id, "links":self.links}
|
return {"id": self.id, "links": self.links}
|
||||||
|
|
||||||
|
|
||||||
class FakeFlavors(object):
|
class FakeFlavors(object):
|
||||||
|
|
||||||
@ -76,6 +77,7 @@ class FakeFlavors(object):
|
|||||||
return value
|
return value
|
||||||
raise nova_exceptions.NotFound(404, "Flavor href not found %s" % href)
|
raise nova_exceptions.NotFound(404, "Flavor href not found %s" % href)
|
||||||
|
|
||||||
|
|
||||||
class FakeServer(object):
|
class FakeServer(object):
|
||||||
|
|
||||||
def __init__(self, parent, id, name, image_id, flavor_ref):
|
def __init__(self, parent, id, name, image_id, flavor_ref):
|
||||||
@ -131,7 +133,7 @@ class FakeServers(object):
|
|||||||
def __init__(self, flavors):
|
def __init__(self, flavors):
|
||||||
self.db = {}
|
self.db = {}
|
||||||
self.flavors = flavors
|
self.flavors = flavors
|
||||||
self.next_id = 10;
|
self.next_id = 10
|
||||||
self.events = EventSimulator()
|
self.events = EventSimulator()
|
||||||
|
|
||||||
def create(self, name, image_id, flavor_ref, files):
|
def create(self, name, image_id, flavor_ref, files):
|
||||||
|
Loading…
Reference in New Issue
Block a user