- # create the client connection
- # make sure module exists before trying to instantiate it
- if client_type in ['geniclientlight'] and GeniClientLight:
- self[hrn] = GeniClientLight(url, self.api.key_file, self.api.cert_file)
- else:
- self[hrn] = xmlrpcprotocol.get_server(url, self.api.key_file, self.api.cert_file)
+ # get hrns that actually exist in the db
+ table = SfaTable()
+ records = table.find({'type': 'sa'})
+ hrns_found = [record['hrn'] for record in records]
+
+ # remove old records
+ for record in records:
+ if record['hrn'] not in hrns_expected:
+ table.remove(record)
+
+ # add new records
+ for hrn in hrns_expected:
+ if hrn not in hrns_found:
+ record = {
+ 'hrn': hrn,
+ 'type': 'sa',
+ }
+ table.insert(record)
+
+
+ def get_connections(self, registries):
+ """
+ read connection details for the trusted peer registries from file return
+ a dictionary of connections keyed on interface hrn.
+ """
+ connections = {}
+ required_fields = self.default_fields.keys()
+ if not isinstance(registries, []):
+ registries = [registries]
+ for registry in registries:
+ # make sure the required fields are present and not null
+ for key in required_fields
+ if not registry.get(key):
+ continue
+ hrn, address, port = registry['hrn'], registry['addr'], registry['port']
+ url = 'http://%(address)s:%(port)s' % locals()
+ # check which client we should use
+ # sfa.util.xmlrpcprotocol is default
+ client_type = 'xmlrpcprotocol'
+ if registry.has_key('client') and \
+ registry['client'] in ['geniclientlight'] and \
+ GeniClientLight:
+ client_type = 'geniclientlight'
+ connections[hrn] = GeniClientLight(url, self.api.key_file, self.api.cert_file)
+ else:
+ connections[hrn] = xmlrpcprotocol.get_server(url, self.api.key_file, self.api.cert_file)