X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=sfa%2Fplc%2Fsfa-nuke-plc.py;h=84360355ccfbee68637067f3d57c26c25a2b327a;hb=3abb6d4142db83f8dc0580e9391be6cd8d45be02;hp=4bbf003ba8f64a9735856559afacb7328c1a0ea9;hpb=eababa96fb603cdd552bc03091813544b099befd;p=sfa.git diff --git a/sfa/plc/sfa-nuke-plc.py b/sfa/plc/sfa-nuke-plc.py index 4bbf003b..84360355 100755 --- a/sfa/plc/sfa-nuke-plc.py +++ b/sfa/plc/sfa-nuke-plc.py @@ -7,27 +7,39 @@ # is not purged by this tool and may be deleted by a command like 'rm'. ## -import getopt import sys +import os +from optparse import OptionParser from sfa.trust.hierarchy import * from sfa.util.record import * from sfa.util.table import SfaTable -from sfa.util.sfalogging import sfa_import_logger - -def process_options(): - - (options, args) = getopt.getopt(sys.argv[1:], '', []) - for opt in options: - name = opt[0] - val = opt[1] +from sfa.util.sfalogging import sfa_logger_goes_to_import,sfa_logger def main(): - process_options() - - sfa_import_logger.info("Purging SFA records from database") - table = SfaTable() - table.sfa_records_purge() - + usage="%prog: trash the registry DB (the 'sfa' table in the 'planetlab5' database)" + parser = OptionParser(usage=usage) + parser.add_option('-f','--file-system',dest='clean_fs',action='store_true',default=False, + help='Clean up the /var/lib/sfa/authorities area as well') + (options,args)=parser.parse_args() + if args: + parser.print_help() + sys.exit(1) + sfa_logger_goes_to_import() + sfa_logger().info("Purging SFA records from database") + table = SfaTable() + table.sfa_records_purge() + if options.clean_fs: + # just remove all files that do not match 'server.key' or 'server.cert' + preserved_files = [ 'server.key', 'server.cert'] + for (dir,_,files) in os.walk('/var/lib/sfa/authorities'): + for file in files: + if file in preserved_files: continue + path=dir+os.sep+file + os.unlink(path) + if not os.path.exists(path): + sfa_logger().info("Unlinked file %s"%path) + else: + sfa_logger().error("Could not unlink file %s"%path) if __name__ == "__main__": - main() + main()