import sfa.util.xmlrpcprotocol as xmlrpcprotocol
import sfa.util.soapprotocol as soapprotocol
-
+
# GeniLight client support is optional
try:
from egeni.geniLight_client import *
# defined by the class
default_dict = {}
- # allowed types
- types = ['sa', 'ma']
+ types = ['authority']
- def __init__(self, api, conf_file, type):
+ def __init__(self, api, conf_file, type='authority'):
if type not in self.types:
raise SfaInfaildArgument('Invalid type %s: must be in %s' % (type, self.types))
dict.__init__(self, {})
if not isinstance(interfaces, list):
interfaces = [self.interfaces]
self.interfaces = {}
+ required_fields = self.default_fields.keys()
for interface in interfaces:
- self.interfaces[interface['hrn']] = interface
+ valid = True
+ # skp any interface definition that has a null hrn,
+ # address or port
+ for field in required_fields:
+ if field not in interface or not interface[field]:
+ valid = False
+ break
+ if valid:
+ self.interfaces[interface['hrn']] = interface
- # get connections
- self.update(self.get_connections(self.interfaces))
def sync_interfaces(self):
"""
return peer_gids
trusted_certs_dir = self.api.config.get_trustedroots_dir()
for new_hrn in new_hrns:
+ if not new_hrn:
+ continue
# the gid for this interface should already be installed
if new_hrn == self.api.config.SFA_INTERFACE_HRN:
continue
try:
# get gid from the registry
interface_info = self.interfaces[new_hrn]
- interface = self.get_connections(self.interfaces[new_hrn])[new_hrn]
+ interface = self[new_hrn]
trusted_gids = interface.get_trusted_certs()
- # default message
- message = "interface: %s\tunable to install trusted gid for %s" % \
- (self.api.interface, new_hrn)
if trusted_gids:
# the gid we want shoudl be the first one in the list,
# but lets make sure
for trusted_gid in trusted_gids:
+ # default message
+ message = "interface: %s\t" % (self.api.interface)
+ message += "unable to install trusted gid for %s" % \
+ (new_hrn)
gid = GID(string=trusted_gids[0])
peer_gids.append(gid)
if gid.get_hrn() == new_hrn:
gid.save_to_file(gid_filename, save_parents=True)
message = "interface: %s\tinstalled trusted gid for %s" % \
(self.api.interface, new_hrn)
- # log the message
- self.api.logger.info(message)
+ # log the message
+ self.api.logger.info(message)
except:
message = "interface: %s\tunable to install trusted gid for %s" % \
(self.api.interface, new_hrn)
# get hrns that actually exist in the db
table = SfaTable()
- records = table.find({'type': type})
+ records = table.find({'type': type, 'pointer': -1})
hrns_found = [record['hrn'] for record in records]
-
+
# remove old records
for record in records:
if record['hrn'] not in hrns_expected:
record = SfaRecord(dict=record)
table.insert(record)
- def get_connections(self, interfaces):
+ def get_connections(self):
"""
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(interfaces, list):
- interfaces = [interfaces]
- for interface in interfaces:
+ for interface in self.interfaces.values():
# make sure the required fields are present and not null
if not all([interface.get(key) for key in required_fields]):
continue
-
+
hrn, address, port = interface['hrn'], interface['addr'], interface['port']
url = 'http://%(address)s:%(port)s' % locals()
+
# check which client we should use
# sfa.util.xmlrpcprotocol is default
client_type = 'xmlrpcprotocol'