- self.interface_info = XmlStorage(conf_file, self.default_dict)
- self.interface_info.load()
- interfaces = self.interface_info.values()[0].values()[0]
- if not isinstance(interfaces, list):
- interfaces = [self.interfaces]
- # set the url and urn
- for interface in interfaces:
- # port is appended onto the domain, before the path. Should look like:
- # http://domain:port/path
- hrn, address, port = interface['hrn'], interface['addr'], interface['port']
- address_parts = address.split('/')
- address_parts[0] = address_parts[0] + ":" + str(port)
- url = "http://%s" % "/".join(address_parts)
- interface['url'] = url
- interface['urn'] = hrn_to_urn(hrn, 'authority')
-
- self.interfaces = {}
- required_fields = self.default_fields.keys()
- for interface in interfaces:
- 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
-
-
- 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()
- for interface in self.interfaces.values():
- url = interface['url']
-# sfa_logger().debug("Interfaces.get_connections - looping on neighbour %s"%url)
- # check which client we should use
- # sfa.util.xmlrpcprotocol is default
- client_type = 'xmlrpcprotocol'
- if interface.has_key('client') and \
- interface['client'] in ['geniclientlight'] and \
- GeniClientLight:
- client_type = 'geniclientlight'
- connections[hrn] = GeniClientLight(url, self.api.key_file, self.api.cert_file)
- else:
- connections[interface['hrn']] = xmlrpcprotocol.get_server(url, self.api.key_file, self.api.cert_file)
+ required_fields = set(self.default_fields.keys())
+ self.interface_info = XML(conf_file).todict()
+ for value in self.interface_info.values():
+ if isinstance(value, list):
+ for record in value:
+ if isinstance(record, dict) and \
+ required_fields.issubset(record.keys()):
+ hrn, address, port = record[
+ 'hrn'], record['addr'], record['port']
+ # sometime this is called at a very early stage with no config loaded
+ # avoid to remember this instance in such a case
+ if not address or not port:
+ continue
+ interface = Interface(hrn, address, port)
+ self[hrn] = interface