Exemple #1
0
class Interfaces(dict):
    """
    Interfaces is a base class for managing information on the
    peers we are federated with. Provides connections (xmlrpc or soap) to federated peers
    """

    # fields that must be specified in the config file
    default_fields = {
        'hrn': '',
        'addr': '', 
        'port': '', 
    }

    # defined by the class 
    default_dict = {}

    def __init__(self, conf_file):
        dict.__init__(self, {})
        # load config 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   

    def server_proxy(self, hrn, key_file, cert_file, timeout=30):
        return self[hrn].server_proxy(key_file, cert_file, timeout)