def periodic_callback(self): # save statistics values for topo in self.topologies.values(): stats = topo.get_stats() if not stats.save_if_changed() and stats.get_idle_time_sec() > MAX_INACTIVE_TOPOLOGY_LIFE_SEC: self.stop_topology(topo, 'topology exceeded maximum idle time (%dsec)' % MAX_INACTIVE_TOPOLOGY_LIFE_SEC) elif stats.get_num_sec_connected() > MAX_TOPOLOGY_LIFE_SEC: self.stop_topology(topo, 'topology exceeded maximum lifetime (%dsec)' % MAX_TOPOLOGY_LIFE_SEC) # see if there is any admin message to be sent to all clients try: bts = db.SystemInfo.objects.get(name='banner_to_send') msg_for_clients = bts.value bts.delete() logging.info('sending message to clients: %s' % msg_for_clients) for conn in self.clients.keys(): for m in VNSBanner.get_banners(msg_for_clients): conn.send(m) except db.SystemInfo.DoesNotExist: pass # note in the db that the reactor thread is still running try: latest = db.SystemInfo.objects.get(name='last_alive_time') except db.SystemInfo.DoesNotExist: latest = db.SystemInfo() latest.name = 'last_alive_time' latest.value = str(int(time())) latest.save() reactor.callLater(30, self.periodic_callback)
def send_motd_to_client(self, conn): """Sends a message to a newly connected client, if such a a message is set.""" # see if there is any admin message to be sent to a client upon connecting try: msg_for_client = DBService.run_and_wait(lambda: db.SystemInfo.objects.get(name='motd')).value logging.info('sending message to clients: %s' % msg_for_client) for m in VNSBanner.get_banners(msg_for_client): conn.send(m) except db.SystemInfo.DoesNotExist: pass
def send_motd_to_client(self, conn): """Sends a message to a newly connected client, if such a a message is set.""" # see if there is any admin message to be sent to a client upon connecting try: msg_for_client = db.SystemInfo.objects.get(name='motd').value logging.info('sending message to clients: %s' % msg_for_client) for m in VNSBanner.get_banners(msg_for_client): conn.send(m) except db.SystemInfo.DoesNotExist: pass
def periodic_callback(self): # save statistics values for topo in self.topologies.values(): stats = topo.get_stats() stats_deferred = DBService.run_in_db_thread(stats.save_if_changed) stats_deferred.addCallback(lambda c: self.__stop_topo_if_necessary(topo, c)) # see if there is any admin message to be sent to all clients try: bts = DBService.run_and_wait(db.SystemInfo.objects.get(name='banner_to_send')) msg_for_clients = bts.value bts.delete() logging.info('sending message to clients: %s' % msg_for_clients) for conn in self.clients.keys(): for m in VNSBanner.get_banners(msg_for_clients): conn.send(m) except db.SystemInfo.DoesNotExist: pass # note in the db that the reactor thread is still running def __update_reactor_alive_time(): try: latest = db.SystemInfo.objects.get(name='last_alive_time') except db.SystemInfo.DoesNotExist: latest = db.SystemInfo() latest.name = 'last_alive_time' latest.value = str(int(time())) latest.save() DBService.run_in_db_thread(__update_reactor_alive_time) # see if there are any topologies to be deleted jtd = DBService.run_and_wait(db.JournalTopologyDelete.objects.all) for je in jtd: try: topo = self.topologies[je.topology.id] except KeyError: # this topology is not in use, we can just delete it from # the db - this also deletes the journal entry DBService.run_in_db_thread(je.topology.delete) else: # the topology is in use; stop it and then delete it self.stop_topology(topo, "topology has been deleted") DBService.run_in_db_thread(je.topology.delete) reactor.callLater(30, self.periodic_callback)