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