def _validate_ssl(self): with open( self.environment[ oengcommcons.ApacheEnv.HTTPD_CONF_SSL ], 'r' ) as f: self._sslData = f.read() missingParams = [] osetuputil.editConfigContent( content=self._sslData.splitlines(), params=self._params, separator_re='\s+', new_line_tpl='{spaces}{param} {value}', added_params=missingParams, ) if missingParams: self.logger.warning( _( 'Expected parameter(s) {missingParams} were not ' 'found in {file}. Automatic ' 'configuration of this file will not be ' 'performed.' ).format( missingParams=missingParams, file=self.environment[ oengcommcons.ApacheEnv.HTTPD_CONF_SSL ] ) ) self._enabled = False
def _misc(self): self.environment[oengcommcons.ApacheEnv.NEED_RESTART] = True changed_lines = [] self.environment[otopicons.CoreEnv.MAIN_TRANSACTION].append( filetransaction.FileTransaction( name=self.environment[ oengcommcons.ApacheEnv.HTTPD_CONF_SSL ], content=osetuputil.editConfigContent( content=self._sslData.splitlines(), params=self._params, changed_lines=changed_lines, separator_re='\s+', new_line_tpl='{spaces}{param} {value}', ), ) ) self.environment[ osetupcons.CoreEnv.REGISTER_UNINSTALL_GROUPS ].createGroup( group='ssl', description='Apache SSL configuration', optional=True ).addChanges( 'ssl', self.environment[oengcommcons.ApacheEnv.HTTPD_CONF_SSL], changed_lines, ) self.environment[ osetupcons.CoreEnv.UNINSTALL_UNREMOVABLE_FILES ].append( self.environment[ oengcommcons.ApacheEnv.HTTPD_CONF_SSL ] )
def getUpdatedPGConf(self, content): needUpdate = True confs_ok = {} edit_params = {} for item in self._pg_conf_info(): key = item['key'] confs_ok[key] = False if item['needed_on_create']: edit_params[key] = item['expected'] for l in content: m = self._RE_KEY_VALUE.match(l) if m is not None: for item in [ i for i in self._pg_conf_info() if i['needed_on_create'] and m.group('key') == i['key'] ]: if item['ok'](key=key, current=m.group('value'), expected=item['expected']): confs_ok[item['key']] = True else: break if False not in confs_ok.values(): needUpdate = False break if needUpdate: content = osetuputil.editConfigContent( content=content, params=edit_params, ) return needUpdate, content
def getUpdatedPGConf(self, content): edit_params = {} for item in self._pg_conf_info(): key = item['key'] if item['needed_on_create']: edit_params[key] = item['expected'] for l in content: m = RE_KEY_VALUE.match(l) if m is not None: for item in [ i for i in self._pg_conf_info() if i['needed_on_create'] and m.group('key') == i['key'] ]: if item['ok'](key=key, current=m.group('value'), expected=item['expected']): del (edit_params[item['key']]) needUpdate = len(edit_params) > 0 if needUpdate: content = osetuputil.editConfigContent( content=content, params=edit_params, ) return needUpdate, content
def _misc(self): changed_lines = [] content = [] if os.path.exists(osetupcons.FileLocations.NFS_RHEL_CONFIG): with open(osetupcons.FileLocations.NFS_RHEL_CONFIG, 'r') as f: content = f.read().splitlines() self.environment[otopicons.CoreEnv.MAIN_TRANSACTION].append( filetransaction.FileTransaction( name=osetupcons.FileLocations.NFS_RHEL_CONFIG, content=osetuputil.editConfigContent( content=content, params=self.SYSCONFIG_NFS_PARAMS, changed_lines=changed_lines, new_line_tpl='{spaces}{param}={value}', ) ) ) self.environment[ osetupcons.CoreEnv.REGISTER_UNINSTALL_GROUPS ].createGroup( group='nfs_config', description='NFS Configuration', optional=True ).addChanges( 'nfs_config', osetupcons.FileLocations.NFS_RHEL_CONFIG, changed_lines, ) self.environment[ osetupcons.CoreEnv.UNINSTALL_UNREMOVABLE_FILES ].append(osetupcons.FileLocations.NFS_RHEL_CONFIG)
def _misc(self): changed_lines = [] with open(YUM_VERSIONLOCK_CONF, 'r') as f: content = f.read().splitlines() self.environment[otopicons.CoreEnv.MAIN_TRANSACTION].append( filetransaction.FileTransaction( name=YUM_VERSIONLOCK_CONF, content=osetuputil.editConfigContent( content=content, params={ 'follow_obsoletes': '1', }, changed_lines=changed_lines, new_line_tpl='{spaces}{param}={value}', ), )) self.environment[ osetupcons.CoreEnv.REGISTER_UNINSTALL_GROUPS].createGroup( group='versionlock_conf', description='Versionlock Plugin Configuration', optional=True).addChanges( 'versionlock_conf', YUM_VERSIONLOCK_CONF, changed_lines, ) self.environment[ osetupcons.CoreEnv.UNINSTALL_UNREMOVABLE_FILES].append( YUM_VERSIONLOCK_CONF)
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 getUpdatedPGConf(self, content): needUpdate = True confs_ok = {} edit_params = {} for item in self._pg_conf_info(): key = item['key'] confs_ok[key] = False if item['needed_on_create']: edit_params[key] = item['expected'] for l in content: m = self._RE_KEY_VALUE.match(l) if m is not None: for item in [ i for i in self._pg_conf_info() if i['needed_on_create'] and m.group('key') == i['key'] ]: if item['ok']( key=key, current=m.group('value'), expected=item['expected'] ): confs_ok[item['key']] = True else: break if False not in confs_ok.values(): needUpdate = False break if needUpdate: content = osetuputil.editConfigContent( content=content, params=edit_params, ) return needUpdate, content
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 _update_provider_config_with_pki(self): content = [] modified_parameters = { 'cert-file': oenginecons.OvnFileLocations.OVIRT_PROVIDER_OVN_HTTPS_CERT, 'key-file': oenginecons.OvnFileLocations.OVIRT_PROVIDER_OVN_HTTPS_KEY, 'cacert-file': oenginecons.FileLocations.OVIRT_ENGINE_PKI_ENGINE_CA_CERT, 'ssl_enabled': 'true', 'ovn-remote': '%s:127.0.0.1:%s' % ( self.OVN_NORTH_DB_CONFIG.protocol, self.OVN_NORTH_DB_CONFIG.port, ), } if os.path.exists( oenginecons.OvnFileLocations.OVIRT_PROVIDER_CONFIG_FILE): with open(oenginecons.OvnFileLocations.OVIRT_PROVIDER_CONFIG_FILE, 'r') as f: content = f.read().splitlines() modified_content = osetuputil.editConfigContent( content=content, params=modified_parameters, param_re='[\w-]+', ) self.environment[otopicons.CoreEnv.MAIN_TRANSACTION].append( filetransaction.FileTransaction( name=oenginecons.OvnFileLocations.OVIRT_PROVIDER_CONFIG_FILE, content=modified_content, visibleButUnsafe=True, ))
def _misc(self): self.environment[oengcommcons.ApacheEnv.NEED_RESTART] = True changed_lines = [] self.environment[otopicons.CoreEnv.MAIN_TRANSACTION].append( filetransaction.FileTransaction( name=self.environment[oengcommcons.ApacheEnv.HTTPD_CONF_SSL], content=osetuputil.editConfigContent( content=_apply_logging(self._sslData.splitlines()), params=self._params, changed_lines=changed_lines, separator_re='\s+', new_line_tpl='{spaces}{param} {value}', ), )) self.environment[ osetupcons.CoreEnv.REGISTER_UNINSTALL_GROUPS].createGroup( group='ssl', description='Apache SSL configuration', optional=True).addChanges( 'ssl', self.environment[oengcommcons.ApacheEnv.HTTPD_CONF_SSL], changed_lines, ) self.environment[ osetupcons.CoreEnv.UNINSTALL_UNREMOVABLE_FILES].append( self.environment[oengcommcons.ApacheEnv.HTTPD_CONF_SSL])
def _misc(self): changed_lines = [] content = [] if os.path.exists(oenginecons.FileLocations.NFS_RHEL_CONFIG): with open(oenginecons.FileLocations.NFS_RHEL_CONFIG, 'r') as f: content = f.read().splitlines() self.environment[otopicons.CoreEnv.MAIN_TRANSACTION].append( filetransaction.FileTransaction( name=oenginecons.FileLocations.NFS_RHEL_CONFIG, content=osetuputil.editConfigContent( content=content, params=self.SYSCONFIG_NFS_PARAMS, changed_lines=changed_lines, new_line_tpl='{spaces}{param}={value}', ))) self.environment[ osetupcons.CoreEnv.REGISTER_UNINSTALL_GROUPS].createGroup( group='nfs_config', description='NFS Configuration', optional=True).addChanges( 'nfs_config', oenginecons.FileLocations.NFS_RHEL_CONFIG, changed_lines, ) self.environment[ osetupcons.CoreEnv.UNINSTALL_UNREMOVABLE_FILES].append( oenginecons.FileLocations.NFS_RHEL_CONFIG)
def _read_and_process_file(self): with open(self.environment[oengcommcons.ApacheEnv.HTTPD_CONF_SSL], 'r') as f: self._current_content = f.read() self._missing_params = [] self._new_content = osetuputil.editConfigContent( content=_apply_logging(self._current_content.splitlines()), params=self._params, changed_lines=self._changed_lines, separator_re='\s+', new_line_tpl='{spaces}{param} {value}', added_params=self._missing_params, )
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 _update_provider_config_with_pki(self, modified_parameters): content = [] if os.path.exists( oenginecons.OvnFileLocations.OVIRT_PROVIDER_CONFIG_FILE): with open(oenginecons.OvnFileLocations.OVIRT_PROVIDER_CONFIG_FILE, 'r') as f: content = f.read().splitlines() modified_content = osetuputil.editConfigContent( content=content, params=modified_parameters, param_re='[\w-]+', ) self.environment[otopicons.CoreEnv.MAIN_TRANSACTION].append( filetransaction.FileTransaction( name=oenginecons.OvnFileLocations.OVIRT_PROVIDER_CONFIG_FILE, content=modified_content, visibleButUnsafe=True, ))
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 _import(self): self.logger.info(_('Importing data into Jasper')) if self._quartzprops: with open( oreportscons.FileLocations.OVIRT_ENGINE_REPORTS_JASPER_QUARTZ, 'w' ) as f: f.write( '\n'.join( osetuputil.editConfigContent( content=self._quartzprops, params=self.QUARTZ_NEEDED_PROPS, keep_existing=True, param_re='(\w|\.)+', new_line_tpl='{spaces}{param}={value}', ) ) ) os.chmod( oreportscons.FileLocations.OVIRT_ENGINE_REPORTS_JASPER_QUARTZ, 0o644, ) if self._users: self._oreportsutil.jsimport(self._users) if self._savedReports: self._oreportsutil.jsimport(self._savedReports) self._oreportsutil.jsimport(self._prepareOvirtReports()) # # We import users twice because we need permissions to be # preserved as well as users passwords reset after importing # reports in previous step. # if self._users: self._oreportsutil.jsimport(self._users) if self._jobs: self._oreportsutil.jsimport(self._jobs) self.logger.info(_('Configuring Jasper Java resources')) for f in glob.glob( os.path.join( oreportscons.FileLocations.PKG_JAVA_DIR, '*.jar', ) ): shutil.copy2( f, os.path.join( oreportscons.FileLocations.OVIRT_ENGINE_REPORTS_JASPER_WAR, 'WEB-INF', 'lib', ) ) self.logger.info(_('Configuring Jasper Database resources')) with oreportsutil.XMLDoc( os.path.join( oreportscons.FileLocations.OVIRT_ENGINE_REPORTS_JASPER_WAR, 'WEB-INF', 'js-jboss7-ds.xml', ) ) as xml: for node in xml.xpath.xpathEval( '/datasources/datasource/driver' ): if 'postgresql' in node.content: node.setContent('postgresql') self.logger.info(_('Customizing Jasper')) base = oreportscons.FileLocations.OVIRT_ENGINE_JASPER_CUSTOMIZATION for directory, dirs, files in os.walk(base): for f in files: shutil.copy2( os.path.join( directory, f, ), os.path.join( oreportscons.FileLocations. OVIRT_ENGINE_REPORTS_JASPER_WAR, os.path.relpath( directory, base, ), ) ) for p in sorted( ( glob.glob( os.path.join( oreportscons.FileLocations.OVIRT_ENGINE_WAR_PATCHES, self.environment[ oreportscons.JasperEnv.JASPER_NAME ], '*.patch', ) ) + glob.glob( os.path.join( oreportscons.FileLocations.OVIRT_ENGINE_WAR_PATCHES, 'common', '*.patch', ) ) ), key=lambda x: os.path.basename(x), ): rc, stdout, stderr = self.execute( args=( self.command.get('patch'), '-p1', '-B', os.path.join(self._temproot, 'patches-backup'), '-d', ( oreportscons.FileLocations. OVIRT_ENGINE_REPORTS_JASPER_WAR ), '-i', p, '--reject-file', '-', '--batch', '--silent', ), ) self.logger.info(_('Customizing Jasper metadata')) everything = self._oreportsutil.jsexport( what='everything-post', args=( '--everything', ), ) if self.environment[ oreportscons.DBEnv.NEW_DATABASE ]: for f in ( 'users/anonymousUser.xml', 'users/jasperadmin.xml', 'users/organization_1/jasperadmin.xml', ): f = os.path.join(everything, f) if os.path.exists(f): with oreportsutil.XMLDoc(f) as xml: xml.setNodesContent( '/user/enabled', 'false', ) for f in ( 'organizations/organizations.xml', 'organizations/organization_1.xml', ): f = os.path.join(everything, f) if os.path.exists(f): with oreportsutil.XMLDoc(f) as xml: xml.setNodesContent( '/organization/theme', self.environment[ oreportscons.JasperEnv.THEME ], ) if ( self.environment[oreportscons.JasperEnv.JASPER_NAME] == 'pro' ): self.logger.info(_('Customizing Jasper Pro Parts')) if self.environment[ oreportscons.ConfigEnv.ADMIN_PASSWORD ] is not None: with oreportsutil.XMLDoc( os.path.join( everything, 'users', 'superuser.xml', ) ) as xml: xml.setNodesContent( '/user/password', self.environment[ oreportscons.ConfigEnv.ADMIN_PASSWORD ], ) if os.path.exists( os.path.join( everything, 'resources', 'themes', self.environment[ oreportscons.JasperEnv.THEME ].replace( '-', '-002d' ), ), ): shutil.rmtree( os.path.join( everything, 'resources', 'themes', self.environment[ oreportscons.JasperEnv.THEME ].replace( '-', '-002d' ), ), ) shutil.copytree( os.path.join( self.environment[oreportscons.JasperEnv.REPORTS_EXPORT], 'resources', 'themes', self.environment[ oreportscons.JasperEnv.THEME ].replace( '-', '-002d' ), ), os.path.join( everything, 'resources', 'themes', self.environment[ oreportscons.JasperEnv.THEME ].replace( '-', '-002d' ), ), ) with oreportsutil.XMLDoc( os.path.join( everything, 'resources', 'themes', '.folder.xml', ) ) as xml: addNode = True for node in xml.xpath.xpathEval( '/folder' ): if self.environment[ oreportscons.JasperEnv.THEME ] in node.content: addNode = False if addNode: addition = None try: addition = libxml2.parseDoc( ''' <folder>%s</folder> ''' % self.environment[ oreportscons.JasperEnv.THEME ] ) xml.xpath.xpathEval('/folder')[0].addChild( addition.getRootElement() ) finally: # do not free, cause segmentation fault # addition.freeDoc() pass self._oreportsutil.jsimport(everything)