def queue_dh_params(self, block=False): queue.start('dh_params', block=block, server_id=self.id, dh_param_bits=self.dh_param_bits, priority=HIGH) self.dh_params = None if block: self.load()
def unassign_ip_addr(self, org_id, user_id): if not self.network_lock: self.ip_pool.unassign_ip_addr(org_id, user_id) else: queue.start('unassign_ip_addr', server_id=self.id, org_id=org_id, user_id=user_id)
def queue_initialize(self, block, priority=LOW): if self.type != ORG_POOL: raise TypeError('Only pool orgs can be queued') queue.start('init_org_pooled', block=block, org_doc=self.export(), priority=priority) if block: self.load()
def generate_dh_param(self): reserved = queue.reserve('pooled_dh_params', svr=self) if not reserved: reserved = queue.reserve('queued_dh_params', svr=self) if reserved: queue.start('dh_params', dh_param_bits=self.dh_param_bits, priority=LOW) return self.queue_dh_params()
def queue_initialize(self, block, priority=LOW): if self.type in (CERT_SERVER_POOL, CERT_CLIENT_POOL): queue.start('init_user_pooled', block=block, org_doc=self.org.export(), user_doc=self.export(), priority=priority) else: retry = True if self.type == CERT_CA: retry = False queue.start('init_user', block=block, org_doc=self.org.export(), user_doc=self.export(), priority=priority, retry=retry) if block: self.load()
def commit(self, *args, **kwargs): tran = None if self.network != self._orig_network: tran = transaction.Transaction() if self.network_lock: raise ServerNetworkLocked('Server network is locked', { 'server_id': self.id, 'lock_id': self.network_lock, }) else: queue_ip_pool = queue.start( 'assign_ip_pool', transaction=tran, server_id=self.id, network=self.network, old_network=self._orig_network, ) self.network_lock = queue_ip_pool.id elif self._orgs_changed: # TODO update ip pool pass mongo.MongoObject.commit(self, transaction=tran, *args, **kwargs) if tran: messenger.publish('queue', 'queue_updated', transaction=tran) tran.commit()
def commit(self, *args, **kwargs): tran = None if 'network' in self.loaded_fields and \ self.network != self._orig_network: tran = transaction.Transaction() if self.network_lock: raise ServerNetworkLocked('Server network is locked', { 'server_id': self.id, 'lock_id': self.network_lock, }) else: queue_ip_pool = queue.start('assign_ip_pool', transaction=tran, server_id=self.id, network=self.network, old_network=self._orig_network, ) self.network_lock = queue_ip_pool.id for org_id in self._orgs_added: self.ip_pool.assign_ip_pool_org(org_id) for org_id in self._orgs_removed: self.ip_pool.unassign_ip_pool_org(org_id) mongo.MongoObject.commit(self, transaction=tran, *args, **kwargs) if tran: messenger.publish('queue', 'queue_updated', transaction=tran) tran.commit()
def commit(self, *args, **kwargs): tran = None if self.network != self._orig_network: tran = transaction.Transaction() if self.network_lock: raise ServerNetworkLocked('Server network is locked', { 'server_id': self.id, 'lock_id': self.network_lock, }) else: queue_ip_pool = queue.start('assign_ip_pool', transaction=tran, server_id=self.id, network=self.network, old_network=self._orig_network, ) self.network_lock = queue_ip_pool.id elif self._orgs_changed: # TODO update ip pool pass mongo.MongoObject.commit(self, transaction=tran, *args, **kwargs) if tran: messenger.publish('queue', 'queue_updated', transaction=tran) tran.commit()
def fill_dh_params(): collection = mongo.get_collection('dh_params') queue_collection = mongo.get_collection('queue') new_dh_params = [] dh_param_bits_pool = settings.app.dh_param_bits_pool dh_param_counts = utils.LeastCommonCounter() for dh_param_bits in dh_param_bits_pool: pool_count = collection.find({ 'dh_param_bits': dh_param_bits, }, { '_id': True }).count() dh_param_counts[dh_param_bits] = pool_count pool_count = queue_collection.find({ 'type': 'dh_params', 'dh_param_bits': dh_param_bits, }, { '_id': True }).count() dh_param_counts[dh_param_bits] += pool_count for dh_param_bits, count in dh_param_counts.least_common(): new_dh_params.append([dh_param_bits] * ( settings.app.server_pool_size - count)) for dh_param_bits in utils.roundrobin(*new_dh_params): que = queue.start('dh_params', dh_param_bits=dh_param_bits, priority=LOW)
def fill_dh_params(): collection = mongo.get_collection('dh_params') queue_collection = mongo.get_collection('queue') new_dh_params = [] dh_param_bits_pool = settings.app.dh_param_bits_pool dh_param_counts = utils.LeastCommonCounter() for dh_param_bits in dh_param_bits_pool: pool_count = collection.find({ 'dh_param_bits': dh_param_bits, }, { '_id': True }).count() dh_param_counts[dh_param_bits] = pool_count pool_count = queue_collection.find( { 'type': 'dh_params', 'dh_param_bits': dh_param_bits, }, { '_id': True }).count() dh_param_counts[dh_param_bits] += pool_count for dh_param_bits, count in dh_param_counts.least_common(): new_dh_params.append([dh_param_bits] * (settings.app.server_pool_size - count)) for dh_param_bits in utils.roundrobin(*new_dh_params): que = queue.start('dh_params', dh_param_bits=dh_param_bits, priority=LOW)
def commit(self, *args, **kwargs): tran = None if 'network' in self.loaded_fields and \ self.network != self._orig_network: tran = transaction.Transaction() if self.network_lock: raise ServerNetworkLocked('Server network is locked', { 'server_id': self.id, 'lock_id': self.network_lock, }) else: queue_ip_pool = queue.start( 'assign_ip_pool', transaction=tran, server_id=self.id, network=self.network, old_network=self._orig_network, ) self.network_lock = queue_ip_pool.id for org_id in self._orgs_added: self.ip_pool.assign_ip_pool_org(org_id) for org_id in self._orgs_removed: self.ip_pool.unassign_ip_pool_org(org_id) mongo.MongoObject.commit(self, transaction=tran, *args, **kwargs) if tran: messenger.publish('queue', 'queue_updated', transaction=tran) tran.commit()
def generate_dh_param(self): doc = queue.find({"type": "dh_params", "server_id": self.id}) if doc: if doc["dh_param_bits"] != self.dh_param_bits: queue.stop(doc["_id"]) else: return reserved = queue.reserve("pooled_dh_params", svr=self) if not reserved: reserved = queue.reserve("queued_dh_params", svr=self) if reserved: queue.start("dh_params", dh_param_bits=self.dh_param_bits, priority=LOW) return self.queue_dh_params()
def generate_dh_param(self): doc = queue.find({ 'type': 'dh_params', 'server_id': self.id, }) if doc: if doc['dh_param_bits'] != self.dh_param_bits: queue.stop(doc['_id']) else: return reserved = queue.reserve('pooled_dh_params', svr=self) if not reserved: reserved = queue.reserve('queued_dh_params', svr=self) if reserved: queue.start('dh_params', dh_param_bits=self.dh_param_bits, priority=LOW) return self.queue_dh_params()
def commit(self, *args, **kwargs): tran = None if "network" in self.loaded_fields and self.network_hash != self._orig_network_hash: tran = transaction.Transaction() if self.network_lock: raise ServerNetworkLocked( "Server network is locked", {"server_id": self.id, "lock_id": self.network_lock} ) else: queue_ip_pool = queue.start( "assign_ip_pool", transaction=tran, server_id=self.id, network=self.network, network_start=self.network_start, network_end=self.network_end, network_hash=self.network_hash, old_network=self._orig_network, old_network_start=self._orig_network_start, old_network_end=self._orig_network_end, old_network_hash=self._orig_network_hash, ) self.network_lock = queue_ip_pool.id for org_id in self._orgs_added: self.ip_pool.assign_ip_pool_org(org_id) for org_id in self._orgs_removed: self.ip_pool.unassign_ip_pool_org(org_id) mongo.MongoObject.commit(self, transaction=tran, *args, **kwargs) if tran: messenger.publish("queue", "queue_updated", transaction=tran) tran.commit()
def fill_dh_params(): collection = mongo.get_collection('dh_params') queue_collection = mongo.get_collection('queue') dh_param_bits_pool = settings.app.dh_param_bits_pool if len(dh_param_bits_pool) > 1: dh_param_counts = utils.LeastCommonCounter( {x: 0 for x in dh_param_bits_pool}) pools = collection.aggregate([ {'$match': { 'dh_param_bits': {'$in': dh_param_bits_pool}, }}, {'$project': { 'dh_param_bits': True, }}, {'$group': { '_id': '$dh_param_bits', 'count': {'$sum': 1}, }}, ])['result'] for pool in pools: dh_param_counts[pool['_id']] = pool['count'] pools = queue_collection.aggregate([ {'$match': { 'type': 'dh_params', 'dh_param_bits': {'$in': dh_param_bits_pool}, }}, {'$project': { 'dh_param_bits': True, }}, {'$group': { '_id': '$dh_param_bits', 'count': {'$sum': 1}, }}, ])['result'] for pool in pools: dh_param_counts[pool['_id']] += pool['count'] else: dh_param_counts = utils.LeastCommonCounter() pool_count = collection.find({ 'dh_param_bits': dh_param_bits_pool[0], }, { '_id': True }).count() dh_param_counts[dh_param_bits_pool[0]] = pool_count pool_count = queue_collection.find({ 'type': 'dh_params', 'dh_param_bits': dh_param_bits_pool[0], }, { '_id': True }).count() dh_param_counts[dh_param_bits_pool[0]] += pool_count new_dh_params = [] for dh_param_bits, count in dh_param_counts.least_common(): new_dh_params.append([dh_param_bits] * ( settings.app.server_pool_size - count)) for dh_param_bits in utils.roundrobin(*new_dh_params): que = queue.start('dh_params', dh_param_bits=dh_param_bits, priority=LOW) logger.debug('Queue dh params', 'server', queue_id=que.id, dh_param_bits=dh_param_bits, )