Пример #1
0
    def handle_event(self, event):
        # print "Received event: %s" % event
        networks = self.networks
        role_map = ThorEntitiesRoleMap(event.message)  ## mapping between role names and lists of nodes with that role
        for role in ["msrprelay_server"]:
            try:
                network = networks[role]  ## avoid setdefault here because it always evaluates the 2nd argument
            except KeyError:
                from thor import network as thor_network

                network = thor_network.new(Config.multiply)
                networks[role] = network
            new_nodes = set([node.ip for node in role_map.get(role, [])])
            old_nodes = set(network.nodes)
            added_nodes = new_nodes - old_nodes
            removed_nodes = old_nodes - new_nodes
            if removed_nodes:
                for node in removed_nodes:
                    network.remove_node(node)
                plural = len(removed_nodes) != 1 and "s" or ""
                log.msg("removed %s node%s: %s" % (role, plural, ", ".join(removed_nodes)))
            if added_nodes:
                for node in added_nodes:
                    network.add_node(node)
                plural = len(added_nodes) != 1 and "s" or ""
                log.msg("added %s node%s: %s" % (role, plural, ", ".join(added_nodes)))
Пример #2
0
 def handle_event(self, event):
     #print "Received event: %s" % event
     networks = self.networks
     role_map = ThorEntitiesRoleMap(event.message) # mapping between role names and lists of nodes with that role
     updated = False
     for role in self.node.roles + ('sip_proxy',):
         try:
             network = networks[role]
         except KeyError:
             from thor import network as thor_network
             network = thor_network.new(ThorNodeConfig.multiply)
             networks[role] = network
         new_nodes = set([node.ip for node in role_map.get(role, [])])
         old_nodes = set(network.nodes)
         added_nodes = new_nodes - old_nodes
         removed_nodes = old_nodes - new_nodes
         if removed_nodes:
             for node in removed_nodes:
                 network.remove_node(node)
             plural = len(removed_nodes) != 1 and 's' or ''
             log.msg("removed %s node%s: %s" % (role, plural, ', '.join(removed_nodes)))
             updated = True
         if added_nodes:
             for node in added_nodes:
                 network.add_node(node)
             plural = len(added_nodes) != 1 and 's' or ''
             log.msg("added %s node%s: %s" % (role, plural, ', '.join(added_nodes)))
             updated = True
     if updated:
         NotificationCenter().post_notification('ThorNetworkGotUpdate', sender=self, data=NotificationData(networks=self.networks))
Пример #3
0
 def handle_event(self, event):
     # print "Received event: %s" % event
     networks = self.networks
     role_map = ThorEntitiesRoleMap(event.message) ## mapping between role names and lists of nodes with that role
     thor_databases = role_map.get('thor_database', [])
     if thor_databases:
         thor_databases.sort(lambda x, y: cmp(x.priority, y.priority) or cmp(x.ip, y.ip))
         dburi = thor_databases[0].dburi
     else:
         dburi = None
     self._database.update_dburi(dburi)
     all_roles = role_map.keys() + networks.keys()
     for role in all_roles:
         try:
             network = networks[role] ## avoid setdefault here because it always evaluates the 2nd argument
         except KeyError:
             from thor import network as thor_network
             if role in ["thor_manager", "thor_monitor", "provisioning_server", "media_relay", "thor_database"]:
                 continue
             else:
                 network = thor_network.new(ThorNodeConfig.multiply)
             networks[role] = network
         new_nodes = set([ThorEntityAddress(node.ip, getattr(node, 'control_port', None), getattr(node, 'version', 'unknown')) for node in role_map.get(role, [])])
         old_nodes = set(network.nodes)
         ## compute set differences
         added_nodes = new_nodes - old_nodes
         removed_nodes = old_nodes - new_nodes
         if removed_nodes:
             for node in removed_nodes:
                 network.remove_node(node)
                 self.control.discard_link((node.ip, node.control_port))
             plural = len(removed_nodes) != 1 and 's' or ''
             log.msg("removed %s node%s: %s" % (role, plural, ', '.join(removed_nodes)))
         if added_nodes:
             for node in added_nodes:
                 network.add_node(node)
             plural = len(added_nodes) != 1 and 's' or ''
             log.msg("added %s node%s: %s" % (role, plural, ', '.join(added_nodes)))