X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=sfa%2Fserver%2Fsfa-clean-peer-records.py;h=18e13e32a1563876b42e64924452dfebd292577e;hb=676d81c2d87c50aff2674abf76b778af2dd10260;hp=05cf65c9bd9901d06ad683648a0f1a95a90e5d2e;hpb=4b9d02c5bfa21a93324895080ee4c183105a37bc;p=sfa.git diff --git a/sfa/server/sfa-clean-peer-records.py b/sfa/server/sfa-clean-peer-records.py index 05cf65c9..18e13e32 100644 --- a/sfa/server/sfa-clean-peer-records.py +++ b/sfa/server/sfa-clean-peer-records.py @@ -3,15 +3,16 @@ import sys import os import traceback -from sfa.util.misc import * -from sfa.util.genitable import GeniTable -from sfa.util.geniclient import GeniClient -from sfa.plc.api import GeniAPI +from sfa.util.namespace import * +from sfa.util.table import SfaTable +from sfa.util.prefixTree import prefixTree +from sfa.plc.api import SfaAPI from sfa.util.config import Config +from sfa.trust.certificate import Keypair from sfa.trust.hierarchy import Hierarchy from sfa.util.report import trace, error from sfa.server.registry import Registries -from sfa.util.xmlrpcprotocol import ServerException +from sfa.util.xmlrpcprotocol import * import socket def main(): @@ -25,32 +26,47 @@ def main(): sfa_key_path = sfa_hierarchy.basedir key_file = os.path.join(sfa_key_path, "server.key") cert_file = os.path.join(sfa_key_path, "server.cert") + key = Keypair(filename=key_file) # get a connection to our local sfa registry # and a valid credential authority = config.SFA_INTERFACE_HRN url = 'http://%s:%s/' %(config.SFA_REGISTRY_HOST, config.SFA_REGISTRY_PORT) - registry = GeniClient(url, key_file, cert_file) - sfa_api = GeniAPI(key_file = key_file, cert_file = cert_file, interface='registry') + registry = xmlrpcprotocol.get_server(url, key_file, cert_file) + sfa_api = SfaAPI(key_file = key_file, cert_file = cert_file, interface='registry') credential = sfa_api.getCredential() # get peer registries registries = Registries(sfa_api) - - + tree = prefixTree() + tree.load(registries.keys()) + # get local peer records - table = GeniTable() + table = SfaTable() peer_records = table.find({'~peer_authority': None}) - for peer_record in peer_records: - peer_auth = peer_record['peer_authority'] - if peer_auth in registries: + found_records = [] + hrn_dict = {} + for record in peer_records: + registry_hrn = tree.best_match(record['hrn']) + if registry_hrn not in hrn_dict: + hrn_dict[registry_hrn] = [] + hrn_dict[registry_hrn].append(record['hrn']) + + # attempt to resolve the record at the authoritative interface + for registry_hrn in hrn_dict: + if registry_hrn in registries: + records = [] + target_hrns = hrn_dict[registry_hrn] try: - records = registries[peer_auth].resolve(credential, peer_record['hrn']) - except ServerException: - # an exception will be thrown if the record doenst exist - # if so remove the record from the local registry - registries[sfa_api.hrn].remove_peer_object(credential, peer_record) + records = registries[registry_hrn].resolve(credential, target_hrns) + found_records.extend([record['hrn'] for record in records]) except: - traceback.print_exc() + traceback.print_exc() + + # remove what wasnt found + for peer_record in peer_records: + if peer_record['hrn'] not in found_records: + registries[sfa_api.hrn].remove(credential, peer_record) + if __name__ == '__main__': main()