Example #1
0
    def update_ip_pool(self):
        cache_key = self.get_cache_key('ip_pool')
        set_cache_key = self.get_cache_key('ip_pool_set')
        cache_db.lock_acquire(cache_key)
        try:
            ip_pool = ipaddress.IPv4Network(self.network).iterhosts()
            ip_pool.next()

            users = set()
            for org in self.iter_orgs():
                for user in org.iter_users():
                    if user.type == CERT_CLIENT:
                        users.add(org.id + '-' + user.id)

            for user_id in cache_db.dict_keys(cache_key) - users:
                ip_set = cache_db.dict_get(cache_key, user_id)
                local_ip_addr, remote_ip_addr = ip_set.split('-')
                cache_db.set_remove(set_cache_key, local_ip_addr)
                cache_db.set_remove(set_cache_key, remote_ip_addr)
                cache_db.dict_remove(cache_key, user_id)

            try:
                for user_id in users - cache_db.dict_keys(cache_key):
                    while True:
                        remote_ip_addr = str(ip_pool.next())
                        ip_addr_endpoint = remote_ip_addr.split('.')[-1]
                        if ip_addr_endpoint not in VALID_IP_ENDPOINTS:
                            continue
                        local_ip_addr = str(ip_pool.next())

                        if not cache_db.set_exists(set_cache_key,
                                local_ip_addr) and not cache_db.set_exists(
                                set_cache_key, remote_ip_addr):
                            cache_db.set_add(set_cache_key, local_ip_addr)
                            cache_db.set_add(set_cache_key, remote_ip_addr)
                            break
                    cache_db.dict_set(cache_key, user_id,
                        local_ip_addr + '-' + remote_ip_addr)
            except StopIteration:
                pass
            finally:
                self._commit_ip_pool()
                for org in self.iter_orgs():
                    Event(type=USERS_UPDATED, resource_id=org.id)
        finally:
            cache_db.lock_release(cache_key)
Example #2
0
 def _fill_servers_pool_listener(self, cache_key, dh_param_path, process):
     for msg in cache_db.subscribe('pooler'):
         if msg == 'update':
             if process.poll() is not None:
                 break
             elif cache_db.set_length('openssl_tasks') and \
                     cache_db.set_exists(cache_key, dh_param_path):
                 # There is a running openssl process started by the user
                 # which takes priority over the pooler's dhparam process
                 if process.poll() is None:
                     process.terminate()
                     time.sleep(0.3)
                     if process.poll() is None:
                         process.kill()
         elif msg == 'stop':
             process.kill()
             return
Example #3
0
    def get_server(cls, id, type=None):
        from node_server import NodeServer

        if not type:
            if cache_db.set_exists('servers', id + '_' + NODE_SERVER):
                type = NODE_SERVER
            else:
                type = SERVER

        if type == NODE_SERVER:
            server = NodeServer(id=id)
        else:
            server = Server(id=id)
        try:
            server.load()
        except IOError:
            logger.exception('Failed to load server conf. %r' % {
                    'server_id': id,
                })
            return
        return server