Beispiel #1
0
 def get_database(self, name):
     """
     Finds the database in this instance with the specified name, and
     returns a CloudDatabaseDatabase object. If no match is found, a
     NoSuchDatabase exception is raised.
     """
     try:
         return [db for db in self.list_databases() if db.name == name][0]
     except IndexError:
         raise exc.NoSuchDatabase("No database by the name '%s' exists." %
                                  name)
Beispiel #2
0
 def _get_db_names(self, dbs, strict=True):
     """
     Accepts a single db (name or object) or a list of dbs, and returns a
     list of database names. If any of the supplied dbs do not exist, a
     NoSuchDatabase exception will be raised, unless you pass strict=False.
     """
     dbs = utils.coerce_string_to_list(dbs)
     db_names = [utils.get_name(db) for db in dbs]
     if strict:
         good_dbs = self.instance.list_databases()
         good_names = [utils.get_name(good_db) for good_db in good_dbs]
         bad_names = [db_name for db_name in db_names
                 if db_name not in good_names]
         if bad_names:
             bad = ", ".join(bad_names)
             raise exc.NoSuchDatabase("The following database(s) were not "
                     "found: %s" % bad)
     return db_names