Exemple #1
0
 def list_users(self, limit=None, marker=None, include_marker=False):
     LOG.debug("Listing users (limit of %s, marker %s, "
               "%s marker)." %
               (limit, marker,
                ('including' if include_marker else 'not including')))
     user_names = []
     with self.cursor(self.database_name) as cursor:
         q = sql_query.Query(columns=['GRANTEE'],
                             tables=['DBA_ROLE_PRIVS'],
                             where=[
                                 "GRANTED_ROLE = '%s'" %
                                 self.cloud_role_name, "GRANTEE != 'SYS'"
                             ])
         cursor.execute(str(q))
         for row in cursor:
             user_names.append(row[0])
     user_list_page, next_marker = pagination.paginate_list(
         list(set(user_names)), limit, marker, include_marker)
     users_page = []
     for user_name in user_list_page:
         user = models.OracleUser(user_name)
         user.databases = self.database_name
         users_page.append(user.serialize())
     LOG.debug("Successfully listed users. "
               "Users: %s (next marker %s)." %
               (user_list_page, next_marker))
     return users_page, marker
Exemple #2
0
 def database_open_mode(self):
     with self.cursor(self.database_name) as cursor:
         cursor.execute(
             str(
                 sql_query.Query(columns=['OPEN_MODE'],
                                 tables=['V$DATABASE'])))
         row = cursor.fetchone()
     return row[0]
Exemple #3
0
 def _log_apply_is_running(self, cursor):
     cursor.execute(
         str(
             sql_query.Query(columns=['COUNT(*)'],
                             tables=['V$MANAGED_STANDBY'],
                             where=["PROCESS LIKE 'MRP%'"])))
     row = cursor.fetchone()
     return int(row[0]) > 0
Exemple #4
0
 def _force_logging_enabled(self, cursor):
     """Checking whether the database is in force logging mode.
     """
     cursor.execute(
         str(
             sql_query.Query(columns=['FORCE_LOGGING'],
                             tables=['V$DATABASE'])))
     row = cursor.fetchone()
     return (row[0] == 'YES')
Exemple #5
0
 def _get_user(self, username):
     with self.cursor(self.database_name) as cursor:
         q = sql_query.Query(columns=['USERNAME'],
                             tables=['ALL_USERS'],
                             where=["USERNAME = '******'" % username.upper()])
         # Check that the user exists
         cursor.execute(str(q))
         if not cursor.fetchone():
             return None
     user = models.OracleUser(username)
     user.databases = self.database_name
     return user
 def estimate_backup_size(self):
     """Estimate the backup size. The estimation is 1/3 the total size
     of datafiles, which is a conservative figure derived from the
     Oracle RMAN backupset compression ratio.
     """
     with self.app.cursor(self.db_name) as cursor:
         cursor.execute(
             str(
                 sql_query.Query(columns=['sum(bytes)'],
                                 tables=['dba_data_files'])))
         result = cursor.fetchall()
         return result[0][0] / 3
Exemple #7
0
 def get_parameter(self, parameter):
     parameter = parameter.lower()
     LOG.debug("Getting current value of initialization parameter %s." %
               parameter)
     with self.cursor(self.database_name) as cursor:
         cursor.execute(
             str(
                 sql_query.Query(columns=['VALUE'],
                                 tables=['V$PARAMETER'],
                                 where=["NAME = '%s'" % parameter])))
         value = cursor.fetchone()[0]
     LOG.debug('Found parameter %s = %s.' % (parameter, value))
     return value
    def _truncate_backup_chain(self):
        """Truncate all backups in the backup chain after the
        specified parent backup."""

        max_recid = sql_query.Query(
            columns=['max(recid)'],
            tables=['v$backup_piece'],
            where=["handle like '%%%s%%'" % self.parent_id])
        q = sql_query.Query(columns=['recid'],
                            tables=['v$backup_piece'],
                            where=['recid > (%s)' % str(max_recid)])
        with self.app.cursor(self.db_name) as cursor:
            cursor.execute(str(q))
            delete_list = [str(row[0]) for row in cursor]

        if delete_list:
            self.app.rman_scripter(
                commands='delete force noprompt backupset %s' %
                ','.join(delete_list),
                sid=self.app.admin.database_name,
                t_user=self.app.admin_user_name,
                t_pswd=self.app.admin.ora_config.admin_password).run()
Exemple #9
0
    def get_master_ref(self, service, snapshot_info):
        """Capture information from a master node"""
        ctlfile = path.join(TMP_DIR,
                            '%s_stby.ctl' % service.admin.database_name)
        datafile = path.join(TMP_DIR, 'oradata.tar.gz')

        def _cleanup_tmp_files():
            operating_system.remove(ctlfile, force=True, as_root=True)
            operating_system.remove(datafile, force=True, as_root=True)

        _cleanup_tmp_files()

        with service.cursor(service.admin.database_name) as cursor:
            cursor.execute(
                str(
                    sql_query.AlterDatabase(
                        "CREATE STANDBY CONTROLFILE AS '%s'" % ctlfile)))
            cursor.execute(
                str(
                    sql_query.Query(columns=['VALUE'],
                                    tables=['V$PARAMETER'],
                                    where=["NAME = 'fal_server'"])))
            row = cursor.fetchone()
            db_list = []
            if row is not None and row[0] is not None:
                db_list = str(row[0]).split(",")
            db_list.insert(0, service.admin.database_name)

        # Create a tar file containing files needed for slave creation
        utils.execute_with_timeout('tar',
                                   '-Pczvf',
                                   datafile,
                                   ctlfile,
                                   service.paths.orapw_file,
                                   service.paths.oratab_file,
                                   CONF.get(MANAGER).conf_file,
                                   run_as_root=True,
                                   root_helper='sudo')
        oradata_encoded = operating_system.read_file(
            datafile,
            codec=stream_codecs.Base64Codec(),
            as_root=True,
            decode=False)
        _cleanup_tmp_files()
        master_ref = {
            'host': netutils.get_my_ipv4(),
            'db_name': service.admin.database_name,
            'db_list': db_list,
            'oradata': oradata_encoded,
        }
        return master_ref
Exemple #10
0
 def start_db(self, update_db=False):
     LOG.debug("Start the Oracle database.")
     self.update_spfile()
     self.status.start_db_service()
     with self.cursor(self.admin.database_name) as cursor:
         cursor.execute(
             str(
                 sql_query.Query(columns=['DATABASE_ROLE', 'OPEN_MODE'],
                                 tables=['V$DATABASE'])))
         row = cursor.fetchone()
         if row[0] == 'PHYSICAL STANDBY' and row[1] == 'READ ONLY':
             # Start up log apply if this database is supposed to be
             # a standby.
             cursor.execute(
                 str(
                     sql_query.AlterDatabase(
                         "RECOVER MANAGED STANDBY DATABASE USING CURRENT LOGFILE "
                         "DISCONNECT FROM SESSION")))