1 #from sfa.util.faults import *
2 from sfa.util.storage import XmlStorage
3 import sfa.util.xmlrpcprotocol as xmlrpcprotocol
5 # GeniLight client support is optional
7 from egeni.geniLight_client import *
13 Interface to another SFA service, typically a peer, or the local aggregate
14 can retrieve a xmlrpclib.ServerProxy object for issuing calls there
16 def __init__(self, hrn, addr, port, client_type='sfa'):
20 self.client_type = client_type
23 address_parts = self.addr.split('/')
24 address_parts[0] = address_parts[0] + ":" + str(self.port)
25 url = "http://%s" % "/".join(address_parts)
28 def get_server(self, key_file, cert_file, timeout=30):
30 if self.client_type == 'geniclientlight' and GeniClientLight:
31 # xxx url and self.api are undefined
32 server = GeniClientLight(url, self.api.key_file, self.api.cert_file)
34 server = xmlrpcprotocol.get_server(self.get_url(), key_file, cert_file, timeout)
38 # In is a dictionary of registry connections keyed on the registry
41 class Interfaces(dict):
43 Interfaces is a base class for managing information on the
44 peers we are federated with. Provides connections (xmlrpc or soap) to federated peers
47 # fields that must be specified in the config file
54 # defined by the class
57 def __init__(self, conf_file):
58 dict.__init__(self, {})
60 self.interface_info = XmlStorage(conf_file, self.default_dict)
61 self.interface_info.load()
62 records = self.interface_info.values()[0]
63 if not isinstance(records, list):
66 required_fields = self.default_fields.keys()
67 for record in records:
68 if not record or not set(required_fields).issubset(record.keys()):
70 # port is appended onto the domain, before the path. Should look like:
71 # http://domain:port/path
72 hrn, address, port = record['hrn'], record['addr'], record['port']
73 # sometime this is called at a very early stage with no config loaded
74 # avoid to remember this instance in such a case
75 if not address or not port:
77 interface = Interface(hrn, address, port)
80 def get_server(self, hrn, key_file, cert_file, timeout=30):
81 return self[hrn].get_server(key_file, cert_file, timeout)