コード例 #1
0
ファイル: users.py プロジェクト: ISCAS-VDI/trove-base
    def get_user(self, context, username, hostname):
        """Return a single user matching the criteria.

        The username and hostname parameter are strings.

        The return value is a dictionary in the following form:

            {"_name": "", "_host": None, "_password": None,
             "_databases": [{"_name": ""}, ...]}

        Where "_databases" is a list of databases the user has access to.
        """
        results = pgutil.query(
            pgutil.UserQuery.get(name=username),
            timeout=30,
        )
        results = tuple(results)
        if len(results) < 1:
            return None

        return {
            "_name": results[0][0],
            "_host": None,
            "_password": None,
            "_databases": self.list_access(context, username, None),
        }
コード例 #2
0
ファイル: root.py プロジェクト: mmasaki/trove
    def is_root_enabled(self, context):
        """Return True if there is a superuser account enabled.
        """
        results = pgutil.query(pgutil.UserQuery.list_root(), timeout=30)

        # There should be only one superuser (Trove's administrative account).
        return len(results) > 1 or (results[0] != self.ADMIN_USER)
コード例 #3
0
    def _run_pre_backup(self):
        self.backup_label = self.base_filename
        r = pgutil.query("SELECT pg_start_backup('%s', true)" %
                         self.backup_label)
        self.start_segment = r[0][0]

        r = pgutil.query("SELECT pg_xlogfile_name('%s')" % self.start_segment)
        self.start_wal_file = r[0][0]

        r = pgutil.query("SELECT pg_stop_backup()")
        self.stop_segment = r[0][0]

        # We have to hack this because self.command is
        # initialized in the base class before we get here, which is
        # when we will know exactly what WAL files we want to archive
        self.command = self._cmd()
コード例 #4
0
ファイル: users.py プロジェクト: melvinj1123/trove
 def _get_users(self, context):
     """Return all non-system Postgres users on the instance."""
     results = pgutil.query(
         pgutil.UserQuery.list(ignore=cfg.get_ignored_users()),
         timeout=30,
     )
     return [self._build_user(context, row[0].strip()) for row in results]
コード例 #5
0
 def _get_users(self, context):
     """Return all non-system Postgres users on the instance."""
     results = pgutil.query(
         pgutil.UserQuery.list(ignore=cfg.get_ignored_users()),
         timeout=30,
     )
     return [self._build_user(context, row[0].strip()) for row in results]
コード例 #6
0
    def _run_pre_backup(self):
        self.backup_label = self.base_filename
        r = pgutil.query("SELECT pg_start_backup('%s', true)" %
                         self.backup_label)
        self.start_segment = r[0][0]

        r = pgutil.query("SELECT pg_xlogfile_name('%s')" % self.start_segment)
        self.start_wal_file = r[0][0]

        r = pgutil.query("SELECT pg_stop_backup()")
        self.stop_segment = r[0][0]

        # We have to hack this because self.command is
        # initialized in the base class before we get here, which is
        # when we will know exactly what WAL files we want to archive
        self.command = self._cmd()
コード例 #7
0
ファイル: users.py プロジェクト: stanleykao72/trove
    def get_user(self, context, username, hostname):
        """Return a single user matching the criteria.

        The username and hostname parameter are strings.

        The return value is a dictionary in the following form:

            {"_name": "", "_host": None, "_password": None,
             "_databases": [{"_name": ""}, ...]}

        Where "_databases" is a list of databases the user has access to.
        """
        results = pgutil.query(
            pgutil.UserQuery.get(name=username),
            timeout=30,
        )
        results = tuple(results)
        if len(results) < 1:
            return None

        return {
            "_name": results[0][0],
            "_host": None,
            "_password": None,
            "_databases": self.list_access(context, username, None),
        }
コード例 #8
0
    def user_exists(self, username):
        """Return whether a given user exists on the instance."""
        results = pgutil.query(
            pgutil.UserQuery.get(name=username),
            timeout=30,
        )

        return bool(results)
コード例 #9
0
ファイル: users.py プロジェクト: melvinj1123/trove
    def user_exists(self, username):
        """Return whether a given user exists on the instance."""
        results = pgutil.query(
            pgutil.UserQuery.get(name=username),
            timeout=30,
        )

        return bool(results)
コード例 #10
0
ファイル: access.py プロジェクト: cdelatte/tesora-trove
 def _get_databases_for(self, username):
     """Return all Postgres databases accessible by a given user."""
     results = pgutil.query(
         pgutil.AccessQuery.list(user=username),
         timeout=30,
     )
     return [models.PostgreSQLSchema(
         row[0].strip(), character_set=row[1], collate=row[2])
         for row in results]
コード例 #11
0
ファイル: database.py プロジェクト: paramtech/tesora-trove
 def _get_databases(self):
     """Return all non-system Postgres databases on the instance."""
     results = pgutil.query(
         pgutil.DatabaseQuery.list(ignore=IGNORE_DBS_LIST),
         timeout=30,
     )
     return [models.PostgreSQLSchema(
         row[0].strip(), character_set=row[1], collate=row[2])
         for row in results]
コード例 #12
0
    def is_root_enabled(self, context):
        """Return True if there is a superuser account enabled.
        """
        results = pgutil.query(
            pgutil.UserQuery.list_root(),
            timeout=30,
        )

        # There should be only one superuser (Trove's administrative account).
        return len(results) > 1 or (results[0][0] != self.ADMIN_USER)
コード例 #13
0
ファイル: access.py プロジェクト: raman-mystack/tesora-trove
 def _get_databases_for(self, username):
     """Return all Postgres databases accessible by a given user."""
     results = pgutil.query(
         pgutil.AccessQuery.list(user=username),
         timeout=30,
     )
     return [
         models.PostgreSQLSchema(row[0].strip(),
                                 character_set=row[1],
                                 collate=row[2]) for row in results
     ]
コード例 #14
0
ファイル: users.py プロジェクト: stewie925/trove
    def list_users(
            self,
            context,
            limit=None,
            marker=None,
            include_marker=False,
    ):
        """List all users on the instance along with their access permissions.

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

            [{"_name": "", "_password": None, "_host": None,
              "_databases": [{"_name": ""}, ...]}, ...]
        """
        results = pgutil.query(
            pgutil.UserQuery.list(ignore=cfg.get_ignored_users(
                manager='postgresql')),
            timeout=30,
        )
        # Convert results into dictionaries.
        results = (
            {
                '_name': r[0].strip(),
                '_password': None,
                '_host': None,
                '_databases': self.list_access(context, r[0], None),
            }
            for r in results
        )

        # Force __iter__ of generator until marker found.
        if marker is not None:
            try:
                item = next(results)
                while item['_name'] != marker:
                    item = next(results)
            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 = next(remainder)
            except StopIteration:
                pass

        return results, next_marker
コード例 #15
0
ファイル: users.py プロジェクト: bhaskarduvvuri/trove
    def list_users(
            self,
            context,
            limit=None,
            marker=None,
            include_marker=False,
    ):
        """List all users on the instance along with their access permissions.

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

            [{"_name": "", "_password": None, "_host": None,
              "_databases": [{"_name": ""}, ...]}, ...]
        """
        results = pgutil.query(
            pgutil.UserQuery.list(ignore=cfg.get_ignored_users(
                manager='postgresql')),
            timeout=30,
        )
        # Convert results into dictionaries.
        results = (
            {
                '_name': r[0].strip(),
                '_password': None,
                '_host': None,
                '_databases': self.list_access(context, r[0], None),
            }
            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
コード例 #16
0
 def _get_databases(self):
     """Return all non-system Postgres databases on the instance."""
     results = pgutil.query(
         pgutil.DatabaseQuery.list(ignore=IGNORE_DBS_LIST),
         timeout=30,
     )
     return [
         models.PostgreSQLSchema(row[0].strip(),
                                 character_set=row[1],
                                 collate=row[2]) for row in results
     ]
コード例 #17
0
    def _find_user(self, context, username):
        """Lookup a user with a given username.
        Return a new Postgres user instance or raise if no match is found.
        """
        results = pgutil.query(
            pgutil.UserQuery.get(name=username),
            timeout=30,
        )

        if results:
            return self._build_user(context, username)

        return None
コード例 #18
0
    def is_root_enabled(self, context):
        """Return True if there is a superuser account enabled.

        This ignores the built-in superuser of postgres and the potential
        system administration superuser of os_admin.
        """
        results = pgutil.query(
            pgutil.UserQuery.list_root(ignore=IGNORE_USERS_LIST),
            timeout=30,
        )
        # Reduce iter of iters to iter of single values.
        results = (r[0] for r in results)
        return len(tuple(results)) > 0
コード例 #19
0
ファイル: users.py プロジェクト: cdelatte/tesora-trove
    def _find_user(self, context, username):
        """Lookup a user with a given username.
        Return a new Postgres user instance or raise if no match is found.
        """
        results = pgutil.query(
            pgutil.UserQuery.get(name=username),
            timeout=30,
        )

        if results:
            return self._build_user(context, username)

        raise exception.UserNotFound()
コード例 #20
0
ファイル: root.py プロジェクト: cretta/trove
    def is_root_enabled(self, context):
        """Return True if there is a superuser account enabled.

        This ignores the built-in superuser of postgres and the potential
        system administration superuser of os_admin.
        """
        results = pgutil.query(
            pgutil.UserQuery.list_root(ignore=IGNORE_USERS_LIST),
            timeout=30,
        )
        # Reduce iter of iters to iter of single values.
        results = (r[0] for r in results)
        return len(tuple(results)) > 0
コード例 #21
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
コード例 #22
0
ファイル: database.py プロジェクト: pombredanne/trove
    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
コード例 #23
0
ファイル: access.py プロジェクト: CMSS-BCRDB/RDSV1.0
    def list_access(self, context, username, hostname):
        """List database for which the given user as access.

        The username and hostname parameters are strings.

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

            [{"_name": "", "_collate": None, "_character_set": None}, ...]
        """
        results = pgutil.query(
            pgutil.AccessQuery.list(user=username),
            timeout=30,
        )

        # Convert to dictionaries.
        results = (
            {'_name': r[0].strip(), '_collate': None, '_character_set': None}
            for r in results
        )
        return tuple(results)
コード例 #24
0
    def list_access(self, context, username, hostname):
        """List database for which the given user as access.

        The username and hostname parameters are strings.

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

            [{"_name": "", "_collate": None, "_character_set": None}, ...]
        """
        results = pgutil.query(
            pgutil.AccessQuery.list(user=username),
            timeout=30,
        )

        # Convert to dictionaries.
        results = ({
            '_name': r[0].strip(),
            '_collate': None,
            '_character_set': None
        } for r in results)
        return tuple(results)
コード例 #25
0
ファイル: process.py プロジェクト: peterstac/tesora-trove
 def pg_is_in_recovery(self):
     """Wrapper for pg_is_in_recovery() for detecting a server in
     standby mode
     """
     r = pgutil.query("SELECT pg_is_in_recovery()")
     return r[0][0]
コード例 #26
0
ファイル: process.py プロジェクト: peterstac/tesora-trove
 def pg_last_xlog_replay_location(self):
     """Wrapper for pg_last_xlog_replay_location()
      For use on standby servers
      """
     r = pgutil.query("SELECT pg_last_xlog_replay_location()")
     return r[0][0]
コード例 #27
0
ファイル: process.py プロジェクト: peterstac/tesora-trove
 def pg_current_xlog_location(self):
     """Wrapper for pg_current_xlog_location()
     Cannot be used against a running slave
     """
     r = pgutil.query("SELECT pg_current_xlog_location()")
     return r[0][0]
コード例 #28
0
ファイル: process.py プロジェクト: paramtech/tesora-trove
 def pg_current_xlog_location(self):
     """Wrapper for pg_current_xlog_location()
     Cannot be used against a running slave
     """
     r = pgutil.query("SELECT pg_current_xlog_location()")
     return r[0][0]
コード例 #29
0
ファイル: process.py プロジェクト: paramtech/tesora-trove
 def pg_last_xlog_replay_location(self):
     """Wrapper for pg_last_xlog_replay_location()
      For use on standby servers
      """
     r = pgutil.query("SELECT pg_last_xlog_replay_location()")
     return r[0][0]
コード例 #30
0
ファイル: process.py プロジェクト: paramtech/tesora-trove
 def pg_is_in_recovery(self):
     """Wrapper for pg_is_in_recovery() for detecting a server in
     standby mode
     """
     r = pgutil.query("SELECT pg_is_in_recovery()")
     return r[0][0]