1 from sfa.client.sfaserverproxy import SfaServerProxy
2 from sfa.util.xml import XML
4 # GeniLight client support is optional
6 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
17 def __init__(self, hrn, addr, port, client_type='sfa'):
21 self.client_type = client_type
24 address_parts = self.addr.split('/')
25 address_parts[0] = address_parts[0] + ":" + str(self.port)
26 url = "http://%s" % "/".join(address_parts)
29 def server_proxy(self, key_file, cert_file, timeout=30):
31 if self.client_type == 'geniclientlight' and GeniClientLight:
32 # xxx url and self.api are undefined
33 server = GeniClientLight(
34 url, self.api.key_file, self.api.cert_file)
36 server = SfaServerProxy(
37 self.get_url(), key_file, cert_file, timeout)
41 # In is a dictionary of registry connections keyed on the registry
45 class Interfaces(dict):
47 Interfaces is a base class for managing information on the
48 peers we are federated with. Provides connections (xmlrpc or soap) to federated peers
51 # fields that must be specified in the config file
58 # defined by the class
61 def __init__(self, conf_file):
62 dict.__init__(self, {})
64 required_fields = set(self.default_fields.keys())
65 self.interface_info = XML(conf_file).todict()
66 for value in list(self.interface_info.values()):
67 if isinstance(value, list):
69 if isinstance(record, dict) and \
70 required_fields.issubset(list(record.keys())):
71 hrn, address, port = record[
72 '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 server_proxy(self, hrn, key_file, cert_file, timeout=30):
81 return self[hrn].server_proxy(key_file, cert_file, timeout)