def _validation(self): # this required for dbvalidations database.OvirtUtils( plugin=self, dbenvkeys=oenginecons.Const.ENGINE_DB_ENV_KEYS, ).createPgPass()
def _misc(self): backupFile = None if not self.environment[oenginecons.EngineDBEnv.NEW_DATABASE]: dbovirtutils = database.OvirtUtils( plugin=self, dbenvkeys=oenginecons.Const.ENGINE_DB_ENV_KEYS, ) backupFile = dbovirtutils.backup( dir=self.environment[ oenginecons.ConfigEnv.OVIRT_ENGINE_DB_BACKUP_DIR], prefix=oenginecons.Const.ENGINE_DB_BACKUP_PREFIX, ) self.environment[otopicons.CoreEnv.MAIN_TRANSACTION].append( self.SchemaTransaction( parent=self, backup=backupFile, )) self.logger.info(_('Creating/refreshing Engine database schema')) args = [ oenginecons.FileLocations.OVIRT_ENGINE_DB_SCHMA_TOOL, '-s', self.environment[oenginecons.EngineDBEnv.HOST], '-p', str(self.environment[oenginecons.EngineDBEnv.PORT]), '-u', self.environment[oenginecons.EngineDBEnv.USER], '-d', self.environment[oenginecons.EngineDBEnv.DATABASE], '-l', self.environment[otopicons.CoreEnv.LOG_FILE_NAME], '-c', 'apply', ] if self.environment[osetupcons.CoreEnv.DEVELOPER_MODE]: if not os.path.exists( oenginecons.FileLocations.OVIRT_ENGINE_DB_MD5_DIR): os.makedirs(oenginecons.FileLocations.OVIRT_ENGINE_DB_MD5_DIR) args.extend([ '-m', os.path.join( oenginecons.FileLocations.OVIRT_ENGINE_DB_MD5_DIR, '%s-%s.scripts.md5' % ( self.environment[oenginecons.EngineDBEnv.HOST], self.environment[oenginecons.EngineDBEnv.DATABASE], ), ), ]) rc, stdout, stderr = self.execute( args=args, envAppend={ 'DBFUNC_DB_PGPASSFILE': self.environment[oenginecons.EngineDBEnv.PGPASS_FILE] }, raiseOnError=False, ) if rc: self.logger.error( '%s: %s', os.path.basename( oenginecons.FileLocations.OVIRT_ENGINE_DB_SCHMA_TOOL), stderr[-1]) raise RuntimeError(_('Engine schema refresh failed'))
def _misc(self): database.OvirtUtils( plugin=self, dbenvkeys=oenginecons.Const.ENGINE_DB_ENV_KEYS, ).createPgPass()
def _setup(self): dbovirtutils = database.OvirtUtils( plugin=self, dbenvkeys=oenginecons.Const.ENGINE_DB_ENV_KEYS, ) dbovirtutils.detectCommands() config = configfile.ConfigFile([ oenginecons.FileLocations.OVIRT_ENGINE_SERVICE_CONFIG_DEFAULTS, oenginecons.FileLocations.OVIRT_ENGINE_SERVICE_CONFIG ]) if config.get('ENGINE_DB_PASSWORD'): try: dbenv = {} for e, k in ( (oenginecons.EngineDBEnv.HOST, 'ENGINE_DB_HOST'), (oenginecons.EngineDBEnv.PORT, 'ENGINE_DB_PORT'), (oenginecons.EngineDBEnv.USER, 'ENGINE_DB_USER'), (oenginecons.EngineDBEnv.PASSWORD, 'ENGINE_DB_PASSWORD'), (oenginecons.EngineDBEnv.DATABASE, 'ENGINE_DB_DATABASE'), ): dbenv[e] = config.get(k) for e, k in ((oenginecons.EngineDBEnv.SECURED, 'ENGINE_DB_SECURED'), (oenginecons.EngineDBEnv.SECURED_HOST_VALIDATION, 'ENGINE_DB_SECURED_VALIDATION')): dbenv[e] = config.getboolean(k) dbovirtutils.tryDatabaseConnect(dbenv) self.environment.update(dbenv) self.environment[oenginecons.EngineDBEnv. NEW_DATABASE] = dbovirtutils.isNewDatabase() self.environment[ oenginecons.EngineDBEnv. NEED_DBMSUPGRADE] = dbovirtutils.checkDBMSUpgrade() except RuntimeError: self.logger.debug( 'Existing credential use failed', exc_info=True, ) msg = _('Cannot connect to Engine database using existing ' 'credentials: {user}@{host}:{port}').format( host=dbenv[oenginecons.EngineDBEnv.HOST], port=dbenv[oenginecons.EngineDBEnv.PORT], database=dbenv[oenginecons.EngineDBEnv.DATABASE], user=dbenv[oenginecons.EngineDBEnv.USER], ) if self.environment[osetupcons.CoreEnv. ACTION] == osetupcons.Const.ACTION_REMOVE: self.logger.warning(msg) else: raise RuntimeError(msg) if not self.environment[oenginecons.EngineDBEnv.NEW_DATABASE]: statement = database.Statement( dbenvkeys=oenginecons.Const.ENGINE_DB_ENV_KEYS, environment=self.environment, ) try: justRestored = vdcoption.VdcOption( statement=statement, ).getVdcOption( 'DbJustRestored', ownConnection=True, ) self.environment[oenginecons.EngineDBEnv.JUST_RESTORED] = ( justRestored == '1') except RuntimeError: pass if self.environment[oenginecons.EngineDBEnv.JUST_RESTORED]: self.logger.info( _('The engine DB has been restored from a backup'))
def _setup(self): legacy = self._parse_legacy_conf(odwhcons.FileLocations.LEGACY_CONFIG) current = configfile.ConfigFile(files=[ odwhcons.FileLocations.OVIRT_ENGINE_DWHD_SERVICE_CONFIG_DEFAULTS, odwhcons.FileLocations.OVIRT_ENGINE_DWHD_SERVICE_CONFIG, ], ) # # legacy package installed file with some defaults # we need to ignore it if no password # if (not current.get('ENGINE_DB_PASSWORD') and legacy.get('ovirtEngineHistoryDbPassword')): fixups = [] for old, new in ( ('runDeleteTime', 'DWH_DELETE_JOB_HOUR'), ('runInterleave', 'DWH_SAMPLING'), ('timeBetweenErrorEvents', 'DWH_ERROR_EVENT_INTERVAL'), ('hoursToKeepSamples', 'DWH_TABLES_KEEP_SAMPLES'), ('hoursToKeepHourly', 'DWH_TABLES_KEEP_HOURLY'), ('hoursToKeepDaily', 'DWH_TABLES_KEEP_DAILY'), ): if legacy.get(old) != current.get(new): fixups.append('%s="%s"' % (new, legacy.get(old))) if fixups: uninstall_files = [] self.environment[ osetupcons.CoreEnv.REGISTER_UNINSTALL_GROUPS].addFiles( group='ovirt_dwh_files', fileList=uninstall_files, ) self.environment[otopicons.CoreEnv.MAIN_TRANSACTION].append( filetransaction.FileTransaction( name=(odwhcons.FileLocations. OVIRT_ENGINE_DWHD_SERVICE_CONFIG_LEGACY), content=fixups, modifiedList=uninstall_files, )) jdbcurl = self._RE_LEGACY_JDBC_URL.match( legacy.get('ovirtEngineHistoryDbJdbcConnection')) if (jdbcurl is None or jdbcurl.group('host') is None or jdbcurl.group('database') is None): raise RuntimeError(_('Invalid legacy DWH database config')) self.environment[odwhcons.DBEnv.HOST] = jdbcurl.group('host') self.environment[odwhcons.DBEnv.PORT] = ( jdbcurl.group('port') if jdbcurl.group('port') is not None else odwhcons.Defaults.DEFAULT_DB_PORT) self.environment[odwhcons.DBEnv.DATABASE] = jdbcurl.group( 'database') self.environment[odwhcons.DBEnv.SECURED] = jdbcurl.group( 'extra').find('ssl=true') != -1 self.environment[ odwhcons.DBEnv. SECURED_HOST_VALIDATION] = not jdbcurl.group('extra').find( 'sslfactory=org.postgresql.ssl.NonValidatingFactory') == -1 self.environment[odwhcons.DBEnv.USER] = legacy.get( 'ovirtEngineHistoryDbUser') self.environment[odwhcons.DBEnv.PASSWORD] = legacy.get( 'ovirtEngineHistoryDbPassword') database.OvirtUtils( plugin=self, dbenvkeys=odwhcons.Const.DWH_DB_ENV_KEYS, ).tryDatabaseConnect() self.environment[odwhcons.DBEnv.NEW_DATABASE] = False self.environment[odwhcons.CoreEnv.ENABLE] = True
def _setDatabaseResources(self, environment): dbstatement = database.Statement( dbenvkeys=self._dbenvkeys, environment=environment, ) hasDatabase = dbstatement.execute( statement=""" select count(*) as count from pg_database where datname = %(database)s """, args=dict( database=self.environment[ self._dbenvkeys['database'] ], ), ownConnection=True, transaction=False, )[0]['count'] != 0 hasUser = dbstatement.execute( statement=""" select count(*) as count from pg_user where usename = %(user)s """, args=dict( user=self.environment[ self._dbenvkeys['user'] ], ), ownConnection=True, transaction=False, )[0]['count'] != 0 generate = hasDatabase or hasUser existing = False if hasDatabase and hasUser: dbovirtutils = database.OvirtUtils( plugin=self, dbenvkeys=self._dbenvkeys, environment=environment, ) if dbovirtutils.isNewDatabase( database=self.environment[ self._dbenvkeys['database'] ], ): self.logger.debug('Found empty database') generate = False existing = True else: generate = True if generate: self.logger.debug('Existing resources found, generating names') suffix = '_%s' % datetime.datetime.now().strftime('%Y%m%d%H%M%S') self.environment[self._dbenvkeys['database']] += suffix self.environment[self._dbenvkeys['user']] += suffix self._renamedDBResources = True return existing
def _setup(self): dbovirtutils = database.OvirtUtils( plugin=self, dbenvkeys=oclcons.Const.CINDERLIB_DB_ENV_KEYS, ) dbovirtutils.detectCommands() config = configfile.ConfigFile([ oenginecons.FileLocations.OVIRT_ENGINE_SERVICE_CONFIG_DEFAULTS, oenginecons.FileLocations.OVIRT_ENGINE_SERVICE_CONFIG ]) if config.get('CINDERLIB_DB_PASSWORD'): try: dbenv = {} for e, k in ( (oclcons.CinderlibDBEnv.HOST, 'CINDERLIB_DB_HOST'), (oclcons.CinderlibDBEnv.PORT, 'CINDERLIB_DB_PORT'), (oclcons.CinderlibDBEnv.USER, 'CINDERLIB_DB_USER'), (oclcons.CinderlibDBEnv.PASSWORD, 'CINDERLIB_DB_PASSWORD'), (oclcons.CinderlibDBEnv.DATABASE, 'CINDERLIB_DB_DATABASE'), ): dbenv[e] = config.get(k) for e, k in ((oclcons.CinderlibDBEnv.SECURED, 'CINDERLIB_DB_SECURED'), (oclcons.CinderlibDBEnv.SECURED_HOST_VALIDATION, 'CINDERLIB_DB_SECURED_VALIDATION')): dbenv[e] = config.getboolean(k) dbovirtutils.tryDatabaseConnect(dbenv) self.environment.update(dbenv) # current cinderlib engine-setup code leaves the database # empty after creation, so we can't rely on # dbovirtutils.isNewDatabase for checking this (because it # checks if there are tables in the public schema). # Always set to False if we managed to connect. TODO think # of something more robust. Perhaps create our own dummy # table to mark that it's 'populated', or save in postinstall # something saying that it's created. self.environment[oclcons.CinderlibDBEnv.NEW_DATABASE] = False self.environment[ oclcons.CinderlibDBEnv. NEED_DBMSUPGRADE] = dbovirtutils.checkDBMSUpgrade() except RuntimeError: self.logger.debug( 'Existing credential use failed', exc_info=True, ) msg = _('Cannot connect to ovirt cinderlib ' 'database using existing ' 'credentials: {user}@{host}:{port}').format( host=dbenv[oclcons.CinderlibDBEnv.HOST], port=dbenv[oclcons.CinderlibDBEnv.PORT], database=dbenv[oclcons.CinderlibDBEnv.DATABASE], user=dbenv[oclcons.CinderlibDBEnv.USER], ) if self.environment[osetupcons.CoreEnv. ACTION] == osetupcons.Const.ACTION_REMOVE: self.logger.warning(msg) else: raise RuntimeError(msg)
def _commands(self): dbovirtutils = database.OvirtUtils( plugin=self, dbenvkeys=odwhcons.Const.DWH_DB_ENV_KEYS, ) dbovirtutils.detectCommands()
def _misc(self): backupFile = None # If we are upgrading to a newer postgresql, do not backup or rollback. # If we upgrade by copying, we can rollback by using the old # version. If we upgrade in-place, we do not support rollback, # and user should take care of backups elsewhere. if not self.environment[ oenginecons.EngineDBEnv.NEED_DBMSUPGRADE ]: if not self.environment[ oenginecons.EngineDBEnv.NEW_DATABASE ]: dbovirtutils = database.OvirtUtils( plugin=self, dbenvkeys=oenginecons.Const.ENGINE_DB_ENV_KEYS, ) backupFile = dbovirtutils.backup( dir=self.environment[ oenginecons.ConfigEnv.OVIRT_ENGINE_DB_BACKUP_DIR ], prefix=oenginecons.Const.ENGINE_DB_BACKUP_PREFIX, ) self.environment[otopicons.CoreEnv.MAIN_TRANSACTION].append( self.SchemaTransaction( parent=self, backup=backupFile, ) ) self.logger.info(_('Creating/refreshing Engine database schema')) args = [ oenginecons.FileLocations.OVIRT_ENGINE_DB_SCHMA_TOOL, '-s', self.environment[oenginecons.EngineDBEnv.HOST], '-p', str(self.environment[oenginecons.EngineDBEnv.PORT]), '-u', self.environment[oenginecons.EngineDBEnv.USER], '-d', self.environment[oenginecons.EngineDBEnv.DATABASE], '-l', self.environment[otopicons.CoreEnv.LOG_FILE_NAME], '-c', 'apply', ] if self.environment[ osetupcons.CoreEnv.DEVELOPER_MODE ]: if not os.path.exists( oenginecons.FileLocations.OVIRT_ENGINE_DB_MD5_DIR ): os.makedirs( oenginecons.FileLocations.OVIRT_ENGINE_DB_MD5_DIR ) args.extend( [ '-m', os.path.join( oenginecons.FileLocations.OVIRT_ENGINE_DB_MD5_DIR, '%s-%s.scripts.md5' % ( self.environment[ oenginecons.EngineDBEnv.HOST ], self.environment[ oenginecons.EngineDBEnv.DATABASE ], ), ), ] ) rc, stdout, stderr = self.execute( args=args, envAppend={ 'DBFUNC_DB_PGPASSFILE': self.environment[ oenginecons.EngineDBEnv.PGPASS_FILE ] }, raiseOnError=False, ) if rc: self.logger.error( '%s: %s', os.path.basename( oenginecons.FileLocations.OVIRT_ENGINE_DB_SCHMA_TOOL ), stderr[-1] if stderr else "exited with non-zero return code." ) raise RuntimeError(_('Engine schema refresh failed'))
def _setupAuth(self): self.environment[otopicons.CoreEnv.MAIN_TRANSACTION].append( filetransaction.FileTransaction( name=oenginecons.FileLocations.AAA_JDBC_CONFIG_DB, mode=0o600, owner=self.environment[osetupcons.SystemEnv.USER_ENGINE], enforcePermissions=True, content=( 'config.datasource.jdbcurl={jdbcUrl}\n' 'config.datasource.dbuser={user}\n' 'config.datasource.dbpassword={password}\n' 'config.datasource.jdbcdriver=org.postgresql.Driver\n' 'config.datasource.schemaname={schemaName}\n' ).format( jdbcUrl=database.OvirtUtils( plugin=self, dbenvkeys=oenginecons.Const.ENGINE_DB_ENV_KEYS, ).getJdbcUrl(), user=self.environment[oenginecons.EngineDBEnv.USER], password=outil.escape( self.environment[oenginecons.EngineDBEnv.PASSWORD], '"\\$', ), schemaName=self._AAA_JDBC_SCHEMA ), visibleButUnsafe=True, modifiedList=self.environment[ otopicons.CoreEnv.MODIFIED_FILES ], ) ) profile = self.environment[ oenginecons.ConfigEnv.ADMIN_USER ].rsplit('@', 1)[1] self.environment[otopicons.CoreEnv.MAIN_TRANSACTION].append( filetransaction.FileTransaction( name=( os.path.join( oenginecons.FileLocations.OVIRT_ENGINE_EXTENSIONS_DIR, '%s-authn.properties' % profile ) ), mode=0o600, owner=self.environment[osetupcons.SystemEnv.USER_ENGINE], enforcePermissions=True, content=( 'ovirt.engine.extension.name = internal-authn\n' 'ovirt.engine.extension.bindings.method = jbossmodule\n' 'ovirt.engine.extension.binding.jbossmodule.module = ' 'org.ovirt.engine.extension.aaa.jdbc\n' 'ovirt.engine.extension.binding.jbossmodule.class = ' 'org.ovirt.engine.extension.aaa.jdbc.binding.api.' 'AuthnExtension\n' 'ovirt.engine.extension.provides = ' 'org.ovirt.engine.api.extensions.aaa.Authn\n' 'ovirt.engine.aaa.authn.profile.name = {profile}\n' 'ovirt.engine.aaa.authn.authz.plugin = {authzName}\n' 'config.datasource.file = {dbConfigFile}\n' ).format( profile=profile, authzName=self.environment[ oenginecons.ConfigEnv.ADMIN_USER_AUTHZ_NAME ], dbConfigFile=oenginecons.FileLocations.AAA_JDBC_CONFIG_DB, ), modifiedList=self.environment[ otopicons.CoreEnv.MODIFIED_FILES ], ) ) self.environment[otopicons.CoreEnv.MAIN_TRANSACTION].append( filetransaction.FileTransaction( name=( os.path.join( oenginecons.FileLocations.OVIRT_ENGINE_EXTENSIONS_DIR, '%s-authz.properties' % profile ) ), mode=0o600, owner=self.environment[osetupcons.SystemEnv.USER_ENGINE], enforcePermissions=True, content=( 'ovirt.engine.extension.name = {authzName}\n' 'ovirt.engine.extension.bindings.method = jbossmodule\n' 'ovirt.engine.extension.binding.jbossmodule.module = ' 'org.ovirt.engine.extension.aaa.jdbc\n' 'ovirt.engine.extension.binding.jbossmodule.class = ' 'org.ovirt.engine.extension.aaa.jdbc.binding.api.' 'AuthzExtension\n' 'ovirt.engine.extension.provides = ' 'org.ovirt.engine.api.extensions.aaa.Authz\n' 'config.datasource.file = {dbConfigFile}\n' ).format( profile=profile, authzName=self.environment[ oenginecons.ConfigEnv.ADMIN_USER_AUTHZ_NAME ], dbConfigFile=oenginecons.FileLocations.AAA_JDBC_CONFIG_DB, ), modifiedList=self.environment[ otopicons.CoreEnv.MODIFIED_FILES ], ) )
def _local_domains_in_use(self): res = False dbovirtutils = database.OvirtUtils( plugin=self, dbenvkeys=oenginecons.Const.ENGINE_DB_ENV_KEYS, ) dbovirtutils.tryDatabaseConnect() dbstatement = database.Statement( dbenvkeys=oenginecons.Const.ENGINE_DB_ENV_KEYS, environment=self.environment, ) self._my_domains = [] rows = dbstatement.execute( statement=""" select s.id, s.status, s.storage, storage_name, connection, storage_domain_type from storage_domains s, storage_server_connections c where s.storage = c.id and s.storage_type=%(storage_type)s """, args=dict(storage_type=domains.StorageType.NFS, ), ownConnection=True, ) for row in rows: host, path = row['connection'].split(':', 1) if host == self._current_fqdn: self._my_domains.append(row) if self._my_domains: self.logger.info(_('Engine machine hosting Storage Domains')) vms_with_iso = [] for dom in self._my_domains: rows = dbstatement.execute( statement=""" select distinct vm_name from storage_domains s, vms, cluster c, storage_pool sp, storage_domains sd where sd.storage_pool_id = sp.id and sp.id = c.storage_pool_id and c.cluster_id = vms.cluster_id and sd.id = %(sd_id)s and vms.current_cd != '' and vms.status > 0 """, args=dict(sd_id=dom['id'], ), ownConnection=True, ) vms_with_iso.extend([r['vm_name'] for r in rows]) if vms_with_iso: res = True self.dialog.note(text=_( 'The following Virtual Machines have attached ISO images ' 'from one or more of the below Storage Domains:\n' '\n' '{vms_with_iso}\n' '\n' 'Needed action: They should be shut down, and/or ' 'have the ISO images disconnected (e.g. by ejecting them).' '\n\n').format(vms_with_iso='\n'.join(sorted( set(vms_with_iso))), ), ) vms_with_disks = [] for dom in self._my_domains: rows = dbstatement.execute( statement=""" select distinct vm_name from all_disks_for_vms adfv, vms where storage_id = %(sd_id)s and adfv.vm_id = vms.vm_guid and vms.status > 0 """, args=dict(sd_id=dom['id'], ), ownConnection=True, ) vms_with_disks.extend([r['vm_name'] for r in rows]) if vms_with_disks: res = True self.dialog.note(text=_( 'The following Virtual Machines have attached disk ' 'images from one or more of the below Storage Domains:\n' '\n' '{vms_with_disks}\n' '\n' 'Needed action: They should be shut down.' '\n\n').format(vms_with_disks='\n'.join( sorted(set(vms_with_disks))), ), ) active_domains = [ r for r in self._my_domains if r['status'] == domains.StorageDomainStatus.ACTIVE ] if active_domains: res = True self.dialog.note(text=_( 'The following Storage Domains use the engine ' 'machine as an NFS server, and are active:\n' '\n' '{domains}\n' '\n' 'Needed action: They should be moved to Maintenance.' '\n\n').format(domains='\n'.join( sorted([d['storage_name'] for d in active_domains]))), ) if not res and self._my_domains: # Lastly inform the user if we are going to rename # local storage domains (which are not in use) self.dialog.note(text=_( 'The following Storage Domains use the engine ' 'machine as an NFS server:\n' '\n' '{domains}\n' '\n' 'They will be modified to use the new name.\n' '\n').format(domains='\n'.join( sorted([d['storage_name'] for d in self._my_domains]))), ) return res
def _misc(self): self._backup = None if not self.environment[ odwhcons.DBEnv.NEED_DBMSUPGRADE ]: if not self.environment[ odwhcons.DBEnv.NEW_DATABASE ] and self.environment[ odwhcons.DBEnv.PERFORM_BACKUP ]: dbovirtutils = database.OvirtUtils( plugin=self, dbenvkeys=odwhcons.Const.DWH_DB_ENV_KEYS, ) self._backup = dbovirtutils.backup( dir=self.environment[ odwhcons.ConfigEnv.OVIRT_ENGINE_DWH_DB_BACKUP_DIR ], prefix=odwhcons.Const.OVIRT_ENGINE_DWH_DB_BACKUP_PREFIX, ) self.environment[otopicons.CoreEnv.MAIN_TRANSACTION].append( self.SchemaTransaction( parent=self, ) ) self.logger.info(_('Creating/refreshing DWH database schema')) args = [ odwhcons.FileLocations.OVIRT_ENGINE_DWH_DB_SCHMA_TOOL, '-s', self.environment[odwhcons.DBEnv.HOST], '-p', str(self.environment[odwhcons.DBEnv.PORT]), '-u', self.environment[odwhcons.DBEnv.USER], '-d', self.environment[odwhcons.DBEnv.DATABASE], '-l', self.environment[otopicons.CoreEnv.LOG_FILE_NAME], '-c', 'apply', ] if self.environment[ osetupcons.CoreEnv.DEVELOPER_MODE ]: if not os.path.exists( odwhcons.FileLocations.OVIRT_ENGINE_DB_MD5_DIR ): os.makedirs( odwhcons.FileLocations.OVIRT_ENGINE_DB_MD5_DIR ) args.extend( [ '-m', os.path.join( odwhcons.FileLocations.OVIRT_ENGINE_DB_MD5_DIR, '%s-%s.scripts.md5' % ( self.environment[odwhcons.DBEnv.HOST], self.environment[odwhcons.DBEnv.DATABASE], ), ), ] ) self.execute( args=args, envAppend={ 'DBFUNC_DB_PGPASSFILE': self.environment[ odwhcons.DBEnv.PGPASS_FILE ] }, )
def _misc(self): database.OvirtUtils( plugin=self, dbenvkeys=odwhcons.Const.DWH_DB_ENV_KEYS, ).createPgPass()
def _setup_engine_db_credentials(self): # TODO: refactor the code in this function to be usable by similar # ones config = configfile.ConfigFile([ odwhcons.FileLocations.OVIRT_ENGINE_DWHD_SERVICE_CONFIG_DEFAULTS, odwhcons.FileLocations.OVIRT_ENGINE_DWHD_SERVICE_CONFIG, ]) if config.get('ENGINE_DB_PASSWORD'): try: dbenv = {} for e, k in ( (oenginecons.EngineDBEnv.HOST, 'ENGINE_DB_HOST'), (oenginecons.EngineDBEnv.PORT, 'ENGINE_DB_PORT'), (oenginecons.EngineDBEnv.USER, 'ENGINE_DB_USER'), (oenginecons.EngineDBEnv.PASSWORD, 'ENGINE_DB_PASSWORD'), (oenginecons.EngineDBEnv.DATABASE, 'ENGINE_DB_DATABASE'), ): dbenv[e] = ( self.environment.get(e) if self.environment.get(e) is not None else config.get(k) ) for e, k in ( (oenginecons.EngineDBEnv.SECURED, 'ENGINE_DB_SECURED'), ( oenginecons.EngineDBEnv.SECURED_HOST_VALIDATION, 'ENGINE_DB_SECURED_VALIDATION' ) ): dbenv[e] = config.getboolean(k) dbovirtutils = database.OvirtUtils( plugin=self, dbenvkeys=oenginecons.Const.ENGINE_DB_ENV_KEYS, ) dbovirtutils.tryDatabaseConnect(dbenv) self.environment.update(dbenv) self.environment[ oenginecons.EngineDBEnv.NEW_DATABASE ] = dbovirtutils.isNewDatabase() self.environment[ oenginecons.EngineDBEnv.NEED_DBMSUPGRADE ] = dbovirtutils.checkDBMSUpgrade() except RuntimeError as e: self.logger.debug( 'Existing credential use failed', exc_info=True, ) msg = _( 'Cannot connect to Engine database using existing ' 'credentials: {user}@{host}:{port}' ).format( host=dbenv[oenginecons.EngineDBEnv.HOST], port=dbenv[oenginecons.EngineDBEnv.PORT], database=dbenv[oenginecons.EngineDBEnv.DATABASE], user=dbenv[oenginecons.EngineDBEnv.USER], ) if self.environment[ osetupcons.CoreEnv.ACTION ] == osetupcons.Const.ACTION_REMOVE: self.logger.warning(msg) else: raise RuntimeError(msg)
def _misc(self): database.OvirtUtils( plugin=self, dbenvkeys=oclcons.Const.CINDERLIB_DB_ENV_KEYS, ).createPgPass()
def _validation(self): # this required for dbvalidations database.OvirtUtils( plugin=self, dbenvkeys=oclcons.Const.CINDERLIB_DB_ENV_KEYS, ).createPgPass()