3 # Delete all the database records for SFA. This tool is used to clean out SFA
4 # records during testing.
6 # Authority info (maintained by the hierarchy module in a subdirectory tree)
7 # is not purged by this tool and may be deleted by a command like 'rm'.
12 from optparse import OptionParser
14 from sfa.util.table import SfaTable
15 from sfa.util.sfalogging import logger
18 usage="%prog: trash the registry DB (the 'sfa' table in the 'planetlab5' database)"
19 parser = OptionParser(usage=usage)
20 parser.add_option('-f','--file-system',dest='clean_fs',action='store_true',default=False,
21 help='Clean up the /var/lib/sfa/authorities area as well')
22 parser.add_option('-c','--certs',dest='clean_certs',action='store_true',default=False,
23 help='Remove all cached certs/gids found in /var/lib/sfa/authorities area as well')
24 (options,args)=parser.parse_args()
28 logger.info("Purging SFA records from database")
30 table.sfa_records_purge()
32 if options.clean_certs:
33 # remove the server certificate and all gids found in /var/lib/sfa/authorities
34 logger.info("Purging cached certificates")
35 for (dir, _, files) in os.walk('/var/lib/sfa/authorities'):
37 if file.endswith('.gid') or file == 'server.cert':
40 if not os.path.exists(path):
41 logger.info("Unlinked file %s"%path)
43 logger.error("Could not unlink file %s"%path)
46 # just remove all files that do not match 'server.key' or 'server.cert'
47 logger.info("Purging registry filesystem cache")
48 preserved_files = [ 'server.key', 'server.cert']
49 for (dir,_,files) in os.walk('/var/lib/sfa/authorities'):
51 if file in preserved_files: continue
54 if not os.path.exists(path):
55 logger.info("Unlinked file %s"%path)
57 logger.error("Could not unlink file %s"%path)
58 if __name__ == "__main__":