Example #1
0
 def __init__(self, ip, port, key_file, cert_file):
     SfaServer.__init__(self, ip, port, key_file, cert_file, 'registry')
     sfa_config = Config()
     if Config().SFA_REGISTRY_ENABLED:
         from sfa.storage.alchemy import engine
         from sfa.storage.dbschema import DBSchema
         DBSchema().init_or_upgrade()
Example #2
0
    def nuke(self, all=False, certs=False, reinit=True):
        """Cleanup local registry DB, plus various additional filesystem cleanups optionally"""
        from sfa.storage.dbschema import DBSchema
        from sfa.util.sfalogging import _SfaLogger
        logger = _SfaLogger(logfile='/var/log/sfa_import.log',
                            loggername='importlog')
        logger.setLevelFromOptVerbose(self.api.config.SFA_API_LOGLEVEL)
        logger.info("Purging SFA records from database")
        dbschema = DBSchema()
        dbschema.nuke()

        # for convenience we re-create the schema here, so there's no need for an explicit
        # service sfa restart
        # however in some (upgrade) scenarios this might be wrong
        if reinit:
            logger.info("re-creating empty schema")
            dbschema.init_or_upgrade()

        # remove the server certificate and all gids found in /var/lib/sfa/authorities
        if certs:
            logger.info("Purging cached certificates")
            for (dir, _, files) in os.walk('/var/lib/sfa/authorities'):
                for file in files:
                    if file.endswith('.gid') or file == 'server.cert':
                        path = dir + os.sep + file
                        os.unlink(path)

        # just remove all files that do not match 'server.key' or 'server.cert'
        if all:
            logger.info("Purging registry filesystem cache")
            preserved_files = ['server.key', 'server.cert']
            for (dir, _, files) in os.walk(Hierarchy().basedir):
                for file in files:
                    if file in preserved_files: continue
                    path = dir + os.sep + file
                    os.unlink(path)
Example #3
0
 def sync_db(self):
     """Initialize or upgrade the db"""
     from sfa.storage.dbschema import DBSchema
     dbschema = DBSchema()
     dbschema.init_or_upgrade()