4 from sfa.util.faults import *
5 from sfa.util.storage import XmlStorage
6 from sfa.util.xrn import get_authority, hrn_to_urn
7 from sfa.util.record import SfaRecord
8 import sfa.util.xmlrpcprotocol as xmlrpcprotocol
9 import sfa.util.soapprotocol as soapprotocol
10 from sfa.trust.gid import GID
12 # GeniLight client support is optional
14 from egeni.geniLight_client import *
16 GeniClientLight = None
22 def __init__(self, hrn, addr, port, client_type='sfa'):
26 self.client_type = client_type
29 address_parts = self.addr.split('/')
30 address_parts[0] = address_parts[0] + ":" + str(self.port)
31 url = "http://%s" % "/".join(address_parts)
34 def get_server(self, key_file, cert_file, timeout=30):
36 if self.client_type == 'geniclientlight' and GeniClientLight:
37 server = GeniClientLight(url, self.api.key_file, self.api.cert_file)
39 server = xmlrpcprotocol.get_server(self.get_url(), key_file, cert_file, timeout)
43 # In is a dictionary of registry connections keyed on the registry
46 class Interfaces(dict):
48 Interfaces is a base class for managing information on the
49 peers we are federated with. Provides connections (xmlrpc or soap) to federated peers
52 # fields that must be specified in the config file
59 # defined by the class
62 def __init__(self, conf_file):
63 dict.__init__(self, {})
65 self.interface_info = XmlStorage(conf_file, self.default_dict)
66 self.interface_info.load()
67 records = self.interface_info.values()[0]
68 if not isinstance(records, list):
71 required_fields = self.default_fields.keys()
72 for record in records:
73 if not record or not set(required_fields).issubset(record.keys()):
75 # port is appended onto the domain, before the path. Should look like:
76 # http://domain:port/path
77 hrn, address, port = record['hrn'], record['addr'], record['port']
78 interface = Interface(hrn, address, port)
81 def get_server(self, hrn, key_file, cert_file, timeout=30):
82 return self[hrn].get_server(key_file, cert_file, timeout)