def _updatePostgresConf( self, transaction, ): with open(self.environment[ oengcommcons.ProvisioningEnv.POSTGRES_CONF]) as f: content = f.read().splitlines() dbovirtutils = database.OvirtUtils( plugin=self._plugin, dbenvkeys=self._dbenvkeys, ) needUpdate, content = dbovirtutils.getUpdatedPGConf(content) if needUpdate: transaction.append( filetransaction.FileTransaction( name=self.environment[ oengcommcons.ProvisioningEnv.POSTGRES_CONF], content=content, modifiedList=self.environment[ otopicons.CoreEnv.MODIFIED_FILES], ), ) self.environment[ osetupcons.CoreEnv.UNINSTALL_UNREMOVABLE_FILES].append( self.environment[ oengcommcons.ProvisioningEnv.POSTGRES_CONF])
def _setPgHbaLocalPeer( self, transaction, ): content = [] with open( self.environment[ osetupcons.ProvisioningEnv.POSTGRES_PG_HBA ] ) as f: for line in f.read().splitlines(): matcher = self._RE_POSTGRES_PGHBA_LOCAL.match(line) if matcher is not None: line = line.replace( matcher.group('param'), 'ident', # we cannot use peer <psql-9 ) content.append(line) transaction.append( filetransaction.FileTransaction( name=self.environment[ osetupcons.ProvisioningEnv.POSTGRES_PG_HBA ], content=content, visibleButUnsafe=True, ) )
def _setPgHbaLocalPeer( self, transaction, ): content = [] with open( self.environment[ oengcommcons.ProvisioningEnv.POSTGRES_PG_HBA ] ) as f: for line in f.read().splitlines(): matcher = self._RE_POSTGRES_PGHBA_LOCAL.match(line) if matcher is not None: line = line.replace( matcher.group('param'), 'ident', # we cannot use peer <psql-9 ) content.append(line) transaction.append( filetransaction.FileTransaction( name=self.environment[ oengcommcons.ProvisioningEnv.POSTGRES_PG_HBA ], content=content, visibleButUnsafe=True, ) )
def _updatePostgresConf( self, transaction, maxconn, listenaddr, ): with open( self.environment[ oengcommcons.ProvisioningEnv.POSTGRES_CONF ] ) as f: content = f.read().splitlines() needUpdate = True maxConnOK = False listenAddrOK = False for l in content: m = self._RE_KEY_VALUE.match(l) if m is not None: if m.group('key') == 'max_connections': if int(m.group('value')) >= int(maxconn): maxConnOK = True else: break elif m.group('key') == 'listen_addresses': if m.group('value') == listenaddr: listenAddrOK = True else: break if (maxConnOK and listenAddrOK): needUpdate = False break if needUpdate: content = osetuputil.editConfigContent( content=content, params={ 'max_connections': maxconn, 'listen_addresses': listenaddr }, ) transaction.append( filetransaction.FileTransaction( name=self.environment[ oengcommcons.ProvisioningEnv.POSTGRES_CONF ], content=content, modifiedList=self.environment[ otopicons.CoreEnv.MODIFIED_FILES ], ), ) self.environment[ osetupcons.CoreEnv.UNINSTALL_UNREMOVABLE_FILES ].append( self.environment[ oengcommcons.ProvisioningEnv.POSTGRES_CONF ] )
def _updateMaxConnections( self, transaction, filename, maxconn, ): with open(filename, 'r') as f: content = osetuputil.editConfigContent( content=f.read().splitlines(), params={ 'max_connections': maxconn, }, ) transaction.append( filetransaction.FileTransaction( name=filename, content=content, modifiedList=self.environment[ otopicons.CoreEnv.MODIFIED_FILES ], ), ) self.environment[ osetupcons.CoreEnv.UNINSTALL_UNREMOVABLE_FILES ].append(filename)
def _addPgHbaDatabaseAccess(self, transaction): lines = [ # we cannot use all for address <psql-9 ("{host:7} " "{database:15} " "{user:15} " "{address:23} " "{auth}").format( host="host", user=_ind_env(self, DEK.USER), database=_ind_env(self, DEK.DATABASE), address=address, auth="md5", ) for address in ("0.0.0.0/0", "::0/0") ] content = [] with open(self.environment[oengcommcons.ProvisioningEnv.POSTGRES_PG_HBA]) as f: for line in f.read().splitlines(): if line not in lines: content.append(line) # order is important, add after local # so we be first if line.lstrip().startswith("local"): content.extend(lines) transaction.append( filetransaction.FileTransaction( name=self.environment[oengcommcons.ProvisioningEnv.POSTGRES_PG_HBA], content=content, modifiedList=self.environment[otopicons.CoreEnv.MODIFIED_FILES], ) ) self.environment[osetupcons.CoreEnv.UNINSTALL_UNREMOVABLE_FILES].append( self.environment[oengcommcons.ProvisioningEnv.POSTGRES_PG_HBA] )
def _addPgHbaDatabaseAccess( self, transaction, ): lines = [ # we cannot use all for address <psql-9 ( '{host:7} ' '{user:15} ' '{database:15} ' '{address:23} ' '{auth}' ).format( host='host', user=self.environment[ self._dbenvkeys['user'] ], database=self.environment[ self._dbenvkeys['database'] ], address=address, auth='md5', ) for address in ('0.0.0.0/0', '::0/0') ] content = [] with open( self.environment[ osetupcons.ProvisioningEnv.POSTGRES_PG_HBA ] ) as f: for line in f.read().splitlines(): if line not in lines: content.append(line) # order is important, add after local # so we be first if line.lstrip().startswith('local'): content.extend(lines) transaction.append( filetransaction.FileTransaction( name=self.environment[ osetupcons.ProvisioningEnv.POSTGRES_PG_HBA ], content=content, modifiedList=self.environment[ otopicons.CoreEnv.MODIFIED_FILES ], ) ) self.environment[ osetupcons.CoreEnv.UNINSTALL_UNREMOVABLE_FILES ].append( self.environment[ osetupcons.ProvisioningEnv.POSTGRES_PG_HBA ] )
def _addPgHbaDatabaseAccess( self, transaction, ): lines = [ # we cannot use all for address <psql-9 ( '{host:7} ' '{database:15} ' '{user:15} ' '{address:23} ' '{auth}' ).format( host='host', user=self.environment[ self._dbenvkeys['user'] ], database=self.environment[ self._dbenvkeys['database'] ], address=address, auth='md5', ) for address in ('0.0.0.0/0', '::0/0') ] content = [] with open( self.environment[ oengcommcons.ProvisioningEnv.POSTGRES_PG_HBA ] ) as f: for line in f.read().splitlines(): if line not in lines: content.append(line) # order is important, add after local # so we be first if line.lstrip().startswith('local'): content.extend(lines) transaction.append( filetransaction.FileTransaction( name=self.environment[ oengcommcons.ProvisioningEnv.POSTGRES_PG_HBA ], content=content, modifiedList=self.environment[ otopicons.CoreEnv.MODIFIED_FILES ], ) ) self.environment[ osetupcons.CoreEnv.UNINSTALL_UNREMOVABLE_FILES ].append( self.environment[ oengcommcons.ProvisioningEnv.POSTGRES_PG_HBA ] )
def _updateMaxConnections( self, transaction, maxconn, ): with open( self.environment[ osetupcons.ProvisioningEnv.POSTGRES_CONF ] ) as f: content = f.read().splitlines() needUpdate = True for l in content: m = self._RE_KEY_VALUE.match(l) if ( m is not None and m.group('key') == 'max_connections' and int(m.group('value')) >= int(maxconn) ): needUpdate = False break if needUpdate: content = osetuputil.editConfigContent( content=content, params={ 'max_connections': maxconn, }, ) transaction.append( filetransaction.FileTransaction( name=self.environment[ osetupcons.ProvisioningEnv.POSTGRES_CONF ], content=content, modifiedList=self.environment[ otopicons.CoreEnv.MODIFIED_FILES ], ), ) self.environment[ osetupcons.CoreEnv.UNINSTALL_UNREMOVABLE_FILES ].append( self.environment[ osetupcons.ProvisioningEnv.POSTGRES_CONF ] )
def _updatePostgresConf(self, transaction, maxconn, listenaddr): with open(self.environment[oengcommcons.ProvisioningEnv.POSTGRES_CONF]) as f: content = f.read().splitlines() dbovirtutils = database.OvirtUtils(plugin=self._plugin, dbenvkeys=self._dbenvkeys) needUpdate, content = dbovirtutils.getUpdatedPGConf(content) if needUpdate: transaction.append( filetransaction.FileTransaction( name=self.environment[oengcommcons.ProvisioningEnv.POSTGRES_CONF], content=content, modifiedList=self.environment[otopicons.CoreEnv.MODIFIED_FILES], ) ) self.environment[osetupcons.CoreEnv.UNINSTALL_UNREMOVABLE_FILES].append( self.environment[oengcommcons.ProvisioningEnv.POSTGRES_CONF] )
def _updateMaxConnections( self, transaction, filename, maxconn, ): with open(filename, 'r') as f: content = osetuputil.editConfigContent( content=f.read().splitlines(), params={ 'max_connections': maxconn, }, ) transaction.append( filetransaction.FileTransaction( name=filename, content=content, modifiedList=self.environment[ otopicons.CoreEnv.MODIFIED_FILES], ), ) self.environment[ osetupcons.CoreEnv.UNINSTALL_UNREMOVABLE_FILES].append(filename)