6 from sfa.util.misc import *
7 from sfa.util.genitable import GeniTable
8 from sfa.util.geniclient import GeniClient
9 from sfa.plc.api import GeniAPI
10 from sfa.util.config import Config
11 from sfa.trust.certificate import Keypair
12 from sfa.trust.hierarchy import Hierarchy
13 from sfa.util.report import trace, error
14 from sfa.server.registry import Registries
15 from sfa.util.xmlrpcprotocol import ServerException
20 if not config.SFA_REGISTRY_ENABLED:
23 # Get the path to the sfa server key/cert files from
24 # the sfa hierarchy object
25 sfa_hierarchy = Hierarchy()
26 sfa_key_path = sfa_hierarchy.basedir
27 key_file = os.path.join(sfa_key_path, "server.key")
28 cert_file = os.path.join(sfa_key_path, "server.cert")
29 key = Keypair(filename=key_file)
31 # get a connection to our local sfa registry
32 # and a valid credential
33 authority = config.SFA_INTERFACE_HRN
34 url = 'http://%s:%s/' %(config.SFA_REGISTRY_HOST, config.SFA_REGISTRY_PORT)
35 registry = GeniClient(url, key_file, cert_file)
36 sfa_api = GeniAPI(key_file = key_file, cert_file = cert_file, interface='registry')
37 credential = sfa_api.getCredential()
40 registries = Registries(sfa_api)
43 # get local peer records
45 peer_records = table.find({'~peer_authority': None})
46 for peer_record in peer_records:
47 peer_auth = peer_record['peer_authority']
48 if peer_auth in registries:
50 peer_record_hrn = peer_record['hrn']
51 arg_list = [credential, peer_record_hrn]
52 request_hash = key.compute_hash(arg_list)
53 records = registries[peer_auth].resolve(credential, peer_record_hrn, request_hash)
54 except ServerException:
55 # an exception will be thrown if the record doenst exist
56 # if so remove the record from the local registry
57 arg_list = [credential]
58 request_hash = key.compute_hash(arg_list)
59 registries[sfa_api.hrn].remove_peer_object(credential, peer_record, request_hash)
62 if __name__ == '__main__':