Пример #1
0
 def _get_databases(self):
     """Return all non-system Postgres databases on the instance."""
     results = pgutil.query(
         pgutil.DatabaseQuery.list(ignore=cfg.get_ignored_dbs()),
         timeout=30,
     )
     return [models.PostgreSQLSchema(
         row[0].strip(), character_set=row[1], collate=row[2])
         for row in results]
Пример #2
0
 def list_databases(self, limit=None, marker=None, include_marker=False):
     """Lists the databases."""
     db_names = self.list_database_names()
     for hidden in cfg.get_ignored_dbs(manager=MANAGER):
         if hidden in db_names:
             db_names.remove(hidden)
     databases = [models.MongoDBSchema(db_name).serialize()
                  for db_name in db_names]
     LOG.debug('databases = ' + str(databases))
     return pagination.paginate_list(databases, limit, marker,
                                     include_marker)
Пример #3
0
 def __init__(self, name=None, deserializing=False):
     super(CouchDBSchema, self).__init__()
     self._ignore_dbs = cfg.get_ignored_dbs()
     # need one or the other, not both, not none (!= ~ XOR)
     if not (bool(deserializing) != bool(name)):
         raise ValueError(_("Bad args. name: %(name)s, "
                            "deserializing %(deser)s.")
                          % ({'name': bool(name),
                              'deser': bool(deserializing)}))
     if not deserializing:
         self.name = name
Пример #4
0
 def list_databases(self, limit=None, marker=None, include_marker=False):
     """Lists the databases."""
     db_names = self.list_database_names()
     for hidden in cfg.get_ignored_dbs():
         if hidden in db_names:
             db_names.remove(hidden)
     databases = [models.MongoDBSchema(db_name)
                  for db_name in db_names]
     LOG.debug('databases = ' + str(databases))
     return guestagent_utils.serialize_list(
         databases,
         limit=limit, marker=marker, include_marker=include_marker)
Пример #5
0
 def list_database_names(self):
     '''Get the list of database names.'''
     out, err = utils.execute_with_timeout(
         system.LIST_DB_COMMAND %
         {'admin_name': self._admin_user().name,
          'admin_password': self._admin_user().password},
         shell=True)
     dbnames_list = eval(out)
     for hidden in cfg.get_ignored_dbs(manager=MANAGER):
         if hidden in dbnames_list:
             dbnames_list.remove(hidden)
     return dbnames_list
Пример #6
0
 def load_with_client(cls, client, limit, marker, include_marker):
     schemas, next_marker = client.list_databases(
         limit=limit,
         marker=marker,
         include_marker=include_marker)
     model_schemas = []
     for schema in schemas:
         mysql_schema = guest_models.MySQLDatabase()
         mysql_schema.deserialize(schema)
         if mysql_schema.name in cfg.get_ignored_dbs():
             continue
         model_schemas.append(Schema(mysql_schema.name,
                                     mysql_schema.collate,
                                     mysql_schema.character_set))
     return model_schemas, next_marker
Пример #7
0
    def list_databases(
            self,
            context,
            limit=None,
            marker=None,
            include_marker=False,
    ):
        """List databases created on this instance.

        Return value is a list of dictionaries in the following form:

            [{"_name": "", "_character_set": "", "_collate": ""}, ...]
        """
        results = pgutil.query(
            pgutil.DatabaseQuery.list(ignore=cfg.get_ignored_dbs(
                manager='postgresql')),
            timeout=30,
        )
        # Convert results to dictionaries.
        results = (
            {'_name': r[0].strip(), '_character_set': r[1], '_collate': r[2]}
            for r in results
        )
        # Force __iter__ of generator until marker found.
        if marker is not None:
            try:
                item = results.next()
                while item['_name'] != marker:
                    item = results.next()
            except StopIteration:
                pass

        remainder = None
        if limit is not None:
            remainder = results
            results = itertools.islice(results, limit)

        results = tuple(results)

        next_marker = None
        if remainder is not None:
            try:
                next_marker = remainder.next()
            except StopIteration:
                pass

        return results, next_marker
Пример #8
0
 def list_databases(self, limit=None, marker=None, include_marker=False):
     """List databases the user created on this mysql instance."""
     LOG.debug("---Listing Databases---")
     ignored_database_names = "'%s'" % "', '".join(cfg.get_ignored_dbs())
     LOG.debug("The following database names are on ignore list and will "
               "be omitted from the listing: %s" % ignored_database_names)
     databases = []
     with self.local_sql_client(self.mysql_app.get_engine()) as client:
         # If you have an external volume mounted at /var/lib/mysql
         # the lost+found directory will show up in mysql as a database
         # which will create errors if you try to do any database ops
         # on it.  So we remove it here if it exists.
         q = sql_query.Query()
         q.columns = [
             'schema_name as name',
             'default_character_set_name as charset',
             'default_collation_name as collation',
         ]
         q.tables = ['information_schema.schemata']
         q.where = ["schema_name NOT IN (" + ignored_database_names + ")"]
         q.order = ['schema_name ASC']
         if limit:
             q.limit = limit + 1
         if marker:
             q.where.append("schema_name %s '%s'" %
                            (INCLUDE_MARKER_OPERATORS[include_marker],
                             marker))
         t = text(str(q))
         database_names = client.execute(t)
         next_marker = None
         LOG.debug("database_names = %r." % database_names)
         for count, database in enumerate(database_names):
             if count >= limit:
                 break
             LOG.debug("database = %s." % str(database))
             mysql_db = models.MySQLDatabase()
             mysql_db.name = database[0]
             next_marker = mysql_db.name
             mysql_db.character_set = database[1]
             mysql_db.collate = database[2]
             databases.append(mysql_db.serialize())
     LOG.debug("databases = " + str(databases))
     if database_names.rowcount <= limit:
         next_marker = None
     return databases, next_marker
Пример #9
0
 def __init__(self):
     self._name = None
     self._collate = None
     self._character_set = None
     self._ignore_dbs = cfg.get_ignored_dbs()
Пример #10
0
 def ignore_dbs(self):
     return cfg.get_ignored_dbs()
Пример #11
0
 def is_reserved_id(self, database_id):
     return database_id in cfg.get_ignored_dbs()
Пример #12
0
 def ignore_dbs(self):
     return cfg.get_ignored_dbs()
Пример #13
0
 def _is_modifiable_database(self, name):
     return name not in cfg.get_ignored_dbs()
Пример #14
0
 def __init__(self):
     self._name = None
     self._collate = None
     self._character_set = None
     self._ignore_dbs = cfg.get_ignored_dbs()
Пример #15
0
 def ignore_dbs(self):
     return cfg.get_ignored_dbs(manager=MANAGER)
Пример #16
0
 def _is_modifiable_database(self, name):
     return name not in cfg.get_ignored_dbs()