8 import sfa.client.xmlrpcprotocol as xmlrpcprotocol
9 from sfa.util.table import SfaTable
10 from sfa.util.prefixTree import prefixTree
11 from sfa.util.config import Config
13 from sfa.generic import Generic
15 from sfa.trust.certificate import Keypair
16 from sfa.trust.hierarchy import Hierarchy
17 from sfa.server.registry import Registries
21 if not config.SFA_REGISTRY_ENABLED:
24 # Get the path to the sfa server key/cert files from
25 # the sfa hierarchy object
26 sfa_hierarchy = Hierarchy()
27 sfa_key_path = sfa_hierarchy.basedir
28 key_file = os.path.join(sfa_key_path, "server.key")
29 cert_file = os.path.join(sfa_key_path, "server.cert")
30 key = Keypair(filename=key_file)
32 # get a connection to our local sfa registry
33 # and a valid credential
34 authority = config.SFA_INTERFACE_HRN
35 url = 'http://%s:%s/' %(config.SFA_REGISTRY_HOST, config.SFA_REGISTRY_PORT)
36 registry = xmlrpcprotocol.server_proxy(url, key_file, cert_file)
37 sfa_api = Generic.the_flavour()
38 credential = sfa_api.getCredential()
41 registries = Registries(sfa_api)
43 tree.load(registries.keys())
45 # get local peer records
47 peer_records = table.find({'~peer_authority': None})
50 for record in peer_records:
51 registry_hrn = tree.best_match(record['hrn'])
52 if registry_hrn not in hrn_dict:
53 hrn_dict[registry_hrn] = []
54 hrn_dict[registry_hrn].append(record['hrn'])
56 # attempt to resolve the record at the authoritative interface
57 for registry_hrn in hrn_dict:
58 if registry_hrn in registries:
60 target_hrns = hrn_dict[registry_hrn]
62 records = registries[registry_hrn].Resolve(target_hrns, credential)
63 found_records.extend([record['hrn'] for record in records])
64 except ServerException:
65 # an exception will be thrown if the record doenst exist
66 # if so remove the record from the local registry
69 # this deosnt necessarily mean the records dont exist
70 # lets give them the benefit of the doubt here (for now)
71 found_records.extend(target_hrns)
74 # remove what wasnt found
75 for peer_record in peer_records:
76 if peer_record['hrn'] not in found_records:
77 registries[sfa_api.hrn].Remove(peer_record['hrn'], credential, peer_record['type'])
79 if __name__ == '__main__':