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.sfalogging import logger
16 from sfa.storage.table import SfaTable
19 usage="%prog: trash the registry DB (the 'sfa' table in the 'planetlab5' database)"
20 parser = OptionParser(usage=usage)
21 parser.add_option('-f','--file-system',dest='clean_fs',action='store_true',default=False,
22 help='Clean up the /var/lib/sfa/authorities area as well')
23 parser.add_option('-c','--certs',dest='clean_certs',action='store_true',default=False,
24 help='Remove all cached certs/gids found in /var/lib/sfa/authorities area as well')
25 (options,args)=parser.parse_args()
29 logger.info("Purging SFA records from database")
33 if options.clean_certs:
34 # remove the server certificate and all gids found in /var/lib/sfa/authorities
35 logger.info("Purging cached certificates")
36 for (dir, _, files) in os.walk('/var/lib/sfa/authorities'):
38 if file.endswith('.gid') or file == 'server.cert':
41 if not os.path.exists(path):
42 logger.info("Unlinked file %s"%path)
44 logger.error("Could not unlink file %s"%path)
47 # just remove all files that do not match 'server.key' or 'server.cert'
48 logger.info("Purging registry filesystem cache")
49 preserved_files = [ 'server.key', 'server.cert']
50 for (dir,_,files) in os.walk('/var/lib/sfa/authorities'):
52 if file in preserved_files: continue
55 if not os.path.exists(path):
56 logger.info("Unlinked file %s"%path)
58 logger.error("Could not unlink file %s"%path)
59 if __name__ == "__main__":