def clear_cache(self): cache_db.set_remove('servers', '%s_%s' % (self.id, self.type)) cache_db.list_remove('servers_sorted', '%s_%s' % (self.id, self.type)) cache_db.remove(self.get_cache_key('clients')) for period in ('1m', '5m', '30m', '2h', '1d'): persist_db.remove(self.get_cache_key('bandwidth-%s' % period)) Config.clear_cache(self)
def clear_cache(self): cache_db.set_remove("orgs", self.id) cache_db.list_remove("orgs_sorted", self.id) cache_db.decrement("org_count") cache_db.remove(self.get_cache_key("users_cached")) cache_db.remove(self.get_cache_key("users")) CacheTrie(self.get_cache_key("users_trie")).clear_cache() Config.clear_cache(self)
def remove_key(self, key, value): name = self.name + '_' cur_key = self.key new_key = cur_key for char in key.lower(): new_key += char cache_db.set_remove(name + cur_key, new_key) cur_key = new_key cache_db.set_remove(name + cur_key + '_values', value)
def clear_cache(self): if self.type == CERT_CLIENT: cache_db.decrement(self.org.get_cache_key('user_count')) if self.type != CERT_CA: cache_db.set_remove(self.org.get_cache_key('users'), self.id) cache_db.list_remove(self.org.get_cache_key('users_sorted'), self.id) self._remove_cache_trie_key() Config.clear_cache(self)
def clear_cache(self, org_data=True): if org_data: if self.type == CERT_CLIENT: cache_db.decrement(self.org.get_cache_key('user_count')) if self.type != CERT_CA: cache_db.set_remove(self.org.get_cache_key('users'), self.id) cache_db.list_remove(self.org.get_cache_key('users_sorted'), self.id) if self.type != CERT_CA: self._remove_cache_trie_key() cache_db.remove(self.get_cache_key('otp')) cache_db.remove(self.get_cache_key('otp_cache')) Config.clear_cache(self)
def clear_cache(self): for user in self.iter_users(): user.clear_cache(org_data=False) self.ca_cert.clear_cache(org_data=False) cache_db.set_remove('orgs', self.id) cache_db.list_remove('orgs_sorted', self.id) cache_db.decrement('org_count') cache_db.remove(self.get_cache_key('users_cached')) cache_db.remove(self.get_cache_key('users')) cache_db.remove(self.get_cache_key('user_count')) cache_db.remove(self.get_cache_key('users_sorted')) cache_db.remove(self.get_cache_key('users_page_index')) cache_db.remove(self.get_cache_key('users_page_total')) CacheTrie(self.get_cache_key('users_trie')).clear_cache() Config.clear_cache(self)
def remove_key(self, key, value): name = self.name + '_' cur_key = self.key new_key = cur_key for char in key.lower(): new_key += char name_key = name + cur_key cache_db.set_remove(name_key, new_key) if not cache_db.set_length(name_key): cache_db.remove(name_key) cur_key = new_key name_key = name + cur_key + '_values' cache_db.set_remove(name_key, value) if not cache_db.set_length(name_key): cache_db.remove(name_key)
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)
def _gen_dh_params(self, dh_param_bits): exit_code = None cache_key = 'dh_pool_%s' % dh_param_bits dh_param_path = os.path.join(self.dh_pool_path, '%s_%s' % (dh_param_bits, uuid.uuid4().hex)) try: cache_db.dict_set('dh_pool_state', dh_param_path, PENDING) cache_db.set_add(cache_key, dh_param_path) args = [ 'openssl', 'dhparam', '-out', dh_param_path, dh_param_bits, ] process = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE) listener_thread = threading.Thread( target=self._fill_servers_pool_listener, args=(cache_key, dh_param_path, process), ) listener_thread.daemon = True listener_thread.start() exit_code = process.wait() finally: if exit_code == 0: cache_db.dict_set('dh_pool_state', dh_param_path, COMPLETE) else: cache_db.set_remove(cache_key, dh_param_path) cache_db.dict_remove('dh_pool_state', dh_param_path) try: os.remove(dh_param_path) except: pass logger.error('Openssl dhparam returned ' + \ 'error exit code %r.' % exit_code) cache_db.publish('pooler', 'update')
def _clear_list_cache(self): cache_db.set_remove('servers', '%s_%s' % (self.id, self.type)) cache_db.list_remove('servers_sorted', '%s_%s' % (self.id, self.type))