Adds ignore_dbs to configs, and makes the models respect it.

This commit is contained in:
Ed Cranford 2012-07-30 11:46:07 -05:00
parent 81838d268b
commit b9038e6fd5
4 changed files with 15 additions and 2 deletions

View File

@ -64,6 +64,7 @@ admin_roles = admin
# Users to ignore for user create/list/delete operations
ignore_users = os_admin, root
ignore_dbs = lost+found, mysql, information_schema
# Guest related conf
agent_heartbeat_time = 10

View File

@ -70,6 +70,7 @@ admin_roles = admin
# Users to ignore for user create/list/delete operations
ignore_users = os_admin, root
ignore_dbs = lost+found, mysql, information_schema
# Guest related conf
agent_heartbeat_time = 10

View File

@ -219,9 +219,12 @@ class Schemas(object):
schemas, next_marker = client.list_databases(limit=limit,
marker=marker, include_marker=include_marker)
model_schemas = []
ignore_dbs = CONFIG.get_list('ignore_dbs', [])
for schema in schemas:
mysql_schema = guest_models.MySQLDatabase()
mysql_schema.deserialize(schema)
if mysql_schema.name in ignore_dbs:
continue
model_schemas.append(Schema(mysql_schema.name,
mysql_schema.collate,
mysql_schema.character_set))

View File

@ -32,6 +32,8 @@ class Base(object):
class MySQLDatabase(Base):
"""Represents a Database and its properties"""
_ignore_dbs = config.Config.get_list("ignore_dbs", [])
# Defaults
__charset__ = "utf8"
__collation__ = "utf8_general_ci"
@ -276,10 +278,16 @@ class MySQLDatabase(Base):
def name(self):
return self._name
def _is_valid(self, value):
return value.lower() not in self._ignore_dbs
@name.setter
def name(self, value):
if not value or not self.dbname.match(value) or \
string.find("%r" % value, "\\") != -1:
if any([not value,
not self._is_valid(value),
not self.dbname.match(value),
string.find("%r" % value, "\\") != -1,
]):
raise ValueError("'%s' is not a valid database name" % value)
elif len(value) > 64:
raise ValueError("Database name '%s' is too long. Max length = 64"