X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=sfa%2Fserver%2Fsfa-clean-peer-records.py;h=795c747ff8c6bd933d847447177dafc256de69a6;hb=d710b76d4d0c64f1cd16f5eb8857f8fbac1a9077;hp=f821f4ce04696adeff0e1ba5a75bf1f689e5d5dc;hpb=3109c266ca3a5df2364e52502479adcc2f995d68;p=sfa.git diff --git a/sfa/server/sfa-clean-peer-records.py b/sfa/server/sfa-clean-peer-records.py index f821f4ce..795c747f 100644 --- a/sfa/server/sfa-clean-peer-records.py +++ b/sfa/server/sfa-clean-peer-records.py @@ -3,15 +3,21 @@ import sys import os import traceback -from sfa.util.table import SfaTable +import socket + 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.server.registry import Registries -import sfa.util.xmlrpcprotocol as xmlrpcprotocol -import socket + +from sfa.storage.alchemy import dbsession +from sfa.storage.model import RegRecord + +from sfa.client.sfaserverproxy import SfaServerProxy + +from sfa.generic import Generic def main(): config = Config() @@ -21,17 +27,17 @@ def main(): # Get the path to the sfa server key/cert files from # the sfa hierarchy object sfa_hierarchy = Hierarchy() - 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") + auth_info = sfa_hierarchy.get_interface_auth_info() + key_file = auth_info.get_privkey_filename() + cert_file = auth_info.get_gid_filename() 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 = xmlrpcprotocol.get_server(url, key_file, cert_file) - sfa_api = SfaAPI(key_file = key_file, cert_file = cert_file, interface='registry') + registry = SfaServerProxy(url, key_file, cert_file) + sfa_api = Generic.the_flavour() credential = sfa_api.getCredential() # get peer registries @@ -40,15 +46,14 @@ def main(): tree.load(registries.keys()) # get local peer records - table = SfaTable() - peer_records = table.find({'~peer_authority': None}) + peer_records=dbsession.query(RegRecord).filter (RegRecord.peer_authority != None).all() found_records = [] hrn_dict = {} for record in peer_records: - registry_hrn = tree.best_match(record['hrn']) + 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']) + hrn_dict[registry_hrn].append(record.hrn) # attempt to resolve the record at the authoritative interface for registry_hrn in hrn_dict: @@ -70,8 +75,8 @@ def main(): # remove what wasnt found for peer_record in peer_records: - if peer_record['hrn'] not in found_records: - registries[sfa_api.hrn].Remove(peer_record['hrn'], credential, peer_record['type']) + if peer_record.hrn not in found_records: + registries[sfa_api.hrn].Remove(peer_record.hrn, credential, peer_record.type) if __name__ == '__main__': main()