コード例 #1
0
 def list_databases(self, limit=None, marker=None, include_marker=False):
     '''Lists all the CouchDB databases.'''
     databases = []
     db_names = self.list_database_names()
     pag_dblist, marker = pagination.paginate_list(db_names, limit, marker,
                                                   include_marker)
     databases = [
         models.CouchDBSchema(db_name).serialize() for db_name in pag_dblist
     ]
     LOG.debug('databases = ' + str(databases))
     return databases, marker
コード例 #2
0
    def create_user(self, users):
        LOG.debug("Creating user(s) for accessing CouchDB database(s).")
        self._admin_user()
        try:
            for item in users:
                user = models.CouchDBUser()
                user.deserialize(item)
                try:
                    LOG.debug("Creating user: %s." % user.name)
                    utils.execute_with_timeout(
                        system.CREATE_USER_COMMAND % {
                            'admin_name': self._admin_user().name,
                            'admin_password': self._admin_user().password,
                            'username': user.name,
                            'username': user.name,
                            'password': user.password
                        },
                        shell=True)
                except exception.ProcessExecutionError as pe:
                    LOG.exception(_("Error creating user: %s.") % user.name)
                    pass

                for database in user.databases:
                    mydb = models.CouchDBSchema()
                    mydb.deserialize(database)
                    try:
                        LOG.debug("Granting user: %s access to database: %s." %
                                  (user.name, mydb.name))
                        out, err = utils.execute_with_timeout(
                            system.GRANT_ACCESS_COMMAND % {
                                'admin_name': self._admin_user().name,
                                'admin_password': self._admin_user().password,
                                'dbname': mydb.name,
                                'username': user.name
                            },
                            shell=True)
                    except exception.ProcessExecutionError as pe:
                        LOG.debug("Error granting user: %s access to"
                                  "database: %s." % (user.name, mydb.name))
                        LOG.debug(pe)
                        pass
        except exception.ProcessExecutionError as pe:
            LOG.exception(
                _("An error occurred creating users: %s.") % pe.message)
            pass