def handle_if_instance_info(self, is_allowed): stats = self.get_argument('instance_info', None) if stats is None: return False if not is_allowed: AdminHandler.log_error("Show instance info not allowed for user") response = {'code': -1, 'data': 'You do not have permissions to view these stats'} else: try: if stats == 'load': result = {} # get cluster loads average_load = Compute.get_cluster_average_stats('Load') if average_load is not None: result['Average Load'] = average_load machine_loads = Compute.get_cluster_stats('Load') if machine_loads is not None: for n, v in machine_loads.iteritems(): result['Instance ' + n] = v elif stats == 'sessions': result = JBoxSessionProps.get_active_sessions(Compute.get_install_id()) elif stats == 'apis': result = JBoxInstanceProps.get_instance_status(Compute.get_install_id()) else: raise Exception("unknown command %s" % (stats,)) response = {'code': 0, 'data': result} except: AdminHandler.log_error("exception while getting stats") AdminHandler._get_logger().exception("exception while getting stats") response = {'code': -1, 'data': 'error getting stats'} self.write(response) return True