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 *
12 Interface to another SFA service, typically a peer, or the local aggregate
13 can retrieve a xmlrpclib.ServerProxy object for issuing calls there
15 def __init__(self, hrn, addr, port, client_type='sfa'):
19 self.client_type = client_type
22 address_parts = self.addr.split('/')
23 address_parts[0] = address_parts[0] + ":" + str(self.port)
24 url = "http://%s" % "/".join(address_parts)
27 def server_proxy(self, key_file, cert_file, timeout=30):
29 if self.client_type == 'geniclientlight' and GeniClientLight:
30 # xxx url and self.api are undefined
31 server = GeniClientLight(url, self.api.key_file, self.api.cert_file)
33 server = SfaServerProxy(self.get_url(), key_file, cert_file, timeout)
37 # In is a dictionary of registry connections keyed on the registry
40 class Interfaces(dict):
42 Interfaces is a base class for managing information on the
43 peers we are federated with. Provides connections (xmlrpc or soap) to federated peers
46 # fields that must be specified in the config file
53 # defined by the class
56 def __init__(self, conf_file):
57 dict.__init__(self, {})
59 required_fields = set(self.default_fields.keys())
60 self.interface_info = XML(conf_file).todict()
61 for value in self.interface_info.values():
62 if isinstance(value, list):
64 if isinstance(record, dict) and \
65 required_fields.issubset(record.keys()):
66 hrn, address, port = record['hrn'], record['addr'], record['port']
67 # sometime this is called at a very early stage with no config loaded
68 # avoid to remember this instance in such a case
69 if not address or not port:
71 interface = Interface(hrn, address, port)
74 def server_proxy(self, hrn, key_file, cert_file, timeout=30):
75 return self[hrn].server_proxy(key_file, cert_file, timeout)